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