diff --git a/db/db.py b/db/db.py index d9e15b4..836ad41 100644 --- a/db/db.py +++ b/db/db.py @@ -48,9 +48,25 @@ class Database: act.project_id, ) ) + except sq.IntegrityError: + cur.execute( + """UPDATE activities + SET description = ?, time_spent = ?, date_start = ?, date_end = ?, is_tracked = ?, vetro_project_id = ?, tag_id = ?, project_id = ? + WHERE id = ?""", + ( + act.description, + act.time_spent, + act.date_start, + act.date_end, + act.is_tracked, + act.vetro_project_id, + act.tag_id, + act.project_id, + act.id, + ) + ) + finally: self.con.commit() - except Exception: - pass if not is_updated: logging.info("База данных устарела. Рекомендуем обновить с помощью флага -i [--init-db]") @@ -72,7 +88,7 @@ class Database: ) ) self.con.commit() - except Exception: + except sq.IntegrityError: pass @@ -81,9 +97,15 @@ class Database: for tag in tags: try: cur.execute("INSERT INTO tags VALUES(?, ?)",(tag.id,tag.title)) + except sq.IntegrityError: + cur.execute( + """UPDATE tags + SET title = ? + WHERE id = ?""", + (tag.title, tag.id) + ) + finally: self.con.commit() - except Exception: - pass def insert_vetro_projects(self, vetro_projects: list[VetroProject]): @@ -91,15 +113,27 @@ class Database: for vetro_project in vetro_projects: try: cur.execute("INSERT INTO vetro_projects VALUES(?, ?)", (vetro_project.id, vetro_project.title)) + except sq.IntegrityError: + cur.execute(""" + UPDATE vetro_projects + SET title = ? + WHERE id = ?""", + (vetro_project.title, vetro_project.id) + ) + finally: self.con.commit() - except Exception: - pass def insert_activity_types(self, activity_types: list[ActivityType]): cur = self.con.cursor() for activity_type in activity_types: try: cur.execute("INSERT INTO activity_types VALUES(?, ?)", (activity_type.id, activity_type.title)) + except sq.IntegrityError: + cur.execute(""" + UPDATE activity_types + SET title = ? + WHERE id = ?""", + (activity_type.title, activity_type.id) + ) + finally: self.con.commit() - except Exception: - pass