From: Christian Heller Date: Fri, 19 Apr 2024 03:45:12 +0000 (+0200) Subject: Improve consistency of DB column names. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/feed.xml?a=commitdiff_plain;h=33cff8c5f6427c4e7e617c459ee024b5b6c2d32e;p=plomtask Improve consistency of DB column names. --- diff --git a/plomtask/conditions.py b/plomtask/conditions.py index 80fc13e..98a0b99 100644 --- a/plomtask/conditions.py +++ b/plomtask/conditions.py @@ -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 diff --git a/plomtask/misc.py b/plomtask/misc.py index bf07188..dcaad17 100644 --- a/plomtask/misc.py +++ b/plomtask/misc.py @@ -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 (?, ?, ?)', diff --git a/plomtask/processes.py b/plomtask/processes.py index 7872c33..9c5c824 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -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) diff --git a/scripts/init.sql b/scripts/init.sql index 870e845..5fdd779 100644 --- a/scripts/init.sql +++ b/scripts/init.sql @@ -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) );