home · contact · privacy
Improve consistency of DB column names.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 19 Apr 2024 03:45:12 +0000 (05:45 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 19 Apr 2024 03:45:12 +0000 (05:45 +0200)
plomtask/conditions.py
plomtask/misc.py
plomtask/processes.py
scripts/init.sql

index 80fc13e4f0a68a9784cc1ec510311f76c0e44320..98a0b99e667adfe11f9f4f0ef3439df03a6cc67f 100644 (file)
@@ -26,11 +26,11 @@ class Condition(BaseModel):
         condition = super().from_table_row(db_conn, row)
         assert isinstance(condition, Condition)
         for title_row in db_conn.exec('SELECT * FROM condition_titles '
-                                      'WHERE parent_id = ?', (row[0],)):
+                                      'WHERE parent = ?', (row[0],)):
             condition.title.history[title_row[1]]\
                     = title_row[2]  # pylint: disable=no-member
         for desc_row in db_conn.exec('SELECT * FROM condition_descriptions '
-                                     'WHERE parent_id = ?', (row[0],)):
+                                     'WHERE parent = ?', (row[0],)):
             condition.description.history[desc_row[1]]\
                     = desc_row[2]  # pylint: disable=no-member
         return condition
index bf071885278471e421a346791bb9db59989097d5..dcaad175874c3d21041bd77fe0240f9060324cdd 100644 (file)
@@ -46,7 +46,7 @@ class VersionedAttribute:
 
     def save(self, db_conn: DatabaseConnection) -> None:
         """Save as self.history entries, but first wipe old ones."""
-        db_conn.exec(f'DELETE FROM {self.table_name} WHERE parent_id = ?',
+        db_conn.exec(f'DELETE FROM {self.table_name} WHERE parent = ?',
                      (self.parent.id_,))
         for timestamp, value in self.history.items():
             db_conn.exec(f'INSERT INTO {self.table_name} VALUES (?, ?, ?)',
index 7872c335eebd702e327db08481a83a77827fbc5f..9c5c824376ccad12b73892023d924a04e95b7ce8 100644 (file)
@@ -48,16 +48,16 @@ class Process(BaseModel):
                 raise NotFoundException(f'Process not found of id: {id_}')
             process = Process(id_)
         for row in db_conn.exec('SELECT * FROM process_titles '
-                                'WHERE parent_id = ?', (process.id_,)):
+                                'WHERE parent = ?', (process.id_,)):
             process.title.history[row[1]] = row[2]
         for row in db_conn.exec('SELECT * FROM process_descriptions '
-                                'WHERE parent_id = ?', (process.id_,)):
+                                'WHERE parent = ?', (process.id_,)):
             process.description.history[row[1]] = row[2]
         for row in db_conn.exec('SELECT * FROM process_efforts '
-                                'WHERE parent_id = ?', (process.id_,)):
+                                'WHERE parent = ?', (process.id_,)):
             process.effort.history[row[1]] = row[2]
         for row in db_conn.exec('SELECT * FROM process_steps '
-                                'WHERE owner_id = ?', (process.id_,)):
+                                'WHERE owner = ?', (process.id_,)):
             process.explicit_steps += [ProcessStep.from_table_row(db_conn,
                                                                   row)]
         for row in db_conn.exec('SELECT condition FROM process_conditions '
@@ -75,8 +75,8 @@ class Process(BaseModel):
     def used_as_step_by(self, db_conn: DatabaseConnection) -> list[Process]:
         """Return Processes using self for a ProcessStep."""
         owner_ids = set()
-        for owner_id in db_conn.exec('SELECT owner_id FROM process_steps WHERE'
-                                     ' step_process_id = ?', (self.id_,)):
+        for owner_id in db_conn.exec('SELECT owner FROM process_steps WHERE'
+                                     ' step_process = ?', (self.id_,)):
             owner_ids.add(owner_id[0])
         return [self.__class__.by_id(db_conn, id_) for id_ in owner_ids]
 
@@ -174,7 +174,7 @@ class Process(BaseModel):
             assert isinstance(step.id_, int)
             del db_conn.cached_process_steps[step.id_]
         self.explicit_steps = []
-        db_conn.exec('DELETE FROM process_steps WHERE owner_id = ?',
+        db_conn.exec('DELETE FROM process_steps WHERE owner = ?',
                      (self.id_,))
         for step_tuple in steps:
             self._add_step(db_conn, step_tuple[0],
@@ -202,7 +202,7 @@ class Process(BaseModel):
             db_conn.exec('INSERT INTO process_undoes VALUES (?,?)',
                          (self.id_, condition.id_))
         assert isinstance(self.id_, int)
-        db_conn.exec('DELETE FROM process_steps WHERE owner_id = ?',
+        db_conn.exec('DELETE FROM process_steps WHERE owner = ?',
                      (self.id_,))
         for step in self.explicit_steps:
             step.save(db_conn)
index 870e845c31827bd7400faea3e7ea877458493715..5fdd77905bb8c5fbc2557843be015ae54f3a289f 100644 (file)
@@ -1,16 +1,16 @@
 CREATE TABLE condition_descriptions (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     description TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES conditions(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES conditions(id)
 );
 CREATE TABLE condition_titles (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     title TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES conditions(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES conditions(id)
 );
 CREATE TABLE conditions (
     id INTEGER PRIMARY KEY,
@@ -28,18 +28,18 @@ CREATE TABLE process_conditions (
     FOREIGN KEY (condition) REFERENCES conditions(id)
 );
 CREATE TABLE process_descriptions (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     description TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES processes(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES processes(id)
 );
 CREATE TABLE process_efforts (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     effort REAL NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES processes(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES processes(id)
 );
 CREATE TABLE process_fulfills (
     process INTEGER NOT NULL,
@@ -50,19 +50,19 @@ CREATE TABLE process_fulfills (
 );
 CREATE TABLE process_steps (
     id INTEGER PRIMARY KEY,
-    owner_id INTEGER NOT NULL,
-    step_process_id INTEGER NOT NULL,
-    parent_step_id INTEGER,
-    FOREIGN KEY (owner_id) REFERENCES processes(id),
-    FOREIGN KEY (step_process_id) REFERENCES processes(id),
-    FOREIGN KEY (parent_step_id) REFERENCES process_steps(step_id)
+    owner INTEGER NOT NULL,
+    step_process INTEGER NOT NULL,
+    parent_step INTEGER,
+    FOREIGN KEY (owner) REFERENCES processes(id),
+    FOREIGN KEY (step_process) REFERENCES processes(id),
+    FOREIGN KEY (parent_step) REFERENCES process_steps(step_id)
 );
 CREATE TABLE process_titles (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     title TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES processes(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES processes(id)
 );
 CREATE TABLE process_undoes (
     process INTEGER NOT NULL,
@@ -104,9 +104,9 @@ CREATE TABLE todo_undoes (
 );
 CREATE TABLE todos (
     id INTEGER PRIMARY KEY,
-    process_id INTEGER NOT NULL,
+    process INTEGER NOT NULL,
     is_done BOOLEAN NOT NULL,
     day TEXT NOT NULL,
-    FOREIGN KEY (process_id) REFERENCES processes(id),
+    FOREIGN KEY (process) REFERENCES processes(id),
     FOREIGN KEY (day) REFERENCES days(id)
 );