From 7c74bf25668139fc09f3c88f72187f9e6cf161c1 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Mon, 13 Dec 2021 06:50:06 -0600 Subject: [PATCH] fix migrations --- migrations/003_create_recordings_table.py | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/migrations/003_create_recordings_table.py b/migrations/003_create_recordings_table.py index d61c9c06f..e13ae657e 100644 --- a/migrations/003_create_recordings_table.py +++ b/migrations/003_create_recordings_table.py @@ -28,17 +28,19 @@ SQL = pw.SQL def migrate(migrator, database, fake=False, **kwargs): - migrator.create_model(Recordings) - - def add_index(): - # First add the index here, because there is a bug in peewee_migrate - # when trying to create an multi-column index in the same migration - # as the table: https://github.com/klen/peewee_migrate/issues/19 - Recordings.add_index("start_time", "end_time") - Recordings.create_table() - - migrator.python(add_index) + migrator.sql( + 'CREATE TABLE IF NOT EXISTS "recordings" ("id" VARCHAR(30) NOT NULL PRIMARY KEY, "camera" VARCHAR(20) NOT NULL, "path" VARCHAR(255) NOT NULL, "start_time" DATETIME NOT NULL, "end_time" DATETIME NOT NULL, "duration" REAL NOT NULL)' + ) + migrator.sql( + 'CREATE INDEX IF NOT EXISTS "recordings_camera" ON "recordings" ("camera")' + ) + migrator.sql( + 'CREATE UNIQUE INDEX IF NOT EXISTS "recordings_path" ON "recordings" ("path")' + ) + migrator.sql( + 'CREATE INDEX IF NOT EXISTS "recordings_start_time_end_time" ON "recordings" (start_time, end_time)' + ) def rollback(migrator, database, fake=False, **kwargs): - migrator.remove_model(Recordings) + pass