From c41a492b07ba6bdc6a89f52d4fc7213d88e6f542 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 29 Aug 2021 09:46:55 +0200 Subject: [PATCH] Rename table module to schema module --- loop/migration.py | 4 ++-- loop/{tables.py => schema.py} | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) rename loop/{tables.py => schema.py} (90%) diff --git a/loop/migration.py b/loop/migration.py index 3cc9501..3527499 100644 --- a/loop/migration.py +++ b/loop/migration.py @@ -1,10 +1,10 @@ -import loop.tables as tables +import loop.schema as schema import loop.habits as habits import loop.repetitions as rep def migrate(trackers, events): - db = tables.migrate("output.db") + db = schema.migrate("output.db") if trackers is not None: habitlist = habits.migrate(db, trackers) diff --git a/loop/tables.py b/loop/schema.py similarity index 90% rename from loop/tables.py rename to loop/schema.py index fd5788c..fc6c03c 100644 --- a/loop/tables.py +++ b/loop/schema.py @@ -55,7 +55,17 @@ def create_tables(db): ) +def create_constraints(db): + c = db.cursor() + c.execute( + """ CREATE UNIQUE INDEX IF NOT EXISTS idx_repetitions_habit_timestamp + on Repetitions( habit, timestamp); + """ + ) + + def migrate(name): db = create_database(name) create_tables(db) + create_constraints(db) return db