003_create_recordings_table.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """Peewee migrations -- 003_create_recordings_table.py.
  2. Some examples (model - class or model name)::
  3. > Model = migrator.orm['model_name'] # Return model in current state by name
  4. > migrator.sql(sql) # Run custom SQL
  5. > migrator.python(func, *args, **kwargs) # Run python code
  6. > migrator.create_model(Model) # Create a model (could be used as decorator)
  7. > migrator.remove_model(model, cascade=True) # Remove a model
  8. > migrator.add_fields(model, **fields) # Add fields to a model
  9. > migrator.change_fields(model, **fields) # Change fields
  10. > migrator.remove_fields(model, *field_names, cascade=True)
  11. > migrator.rename_field(model, old_field_name, new_field_name)
  12. > migrator.rename_table(model, new_table_name)
  13. > migrator.add_index(model, *col_names, unique=False)
  14. > migrator.drop_index(model, *col_names)
  15. > migrator.add_not_null(model, *field_names)
  16. > migrator.drop_not_null(model, *field_names)
  17. > migrator.add_default(model, field_name, default)
  18. """
  19. import peewee as pw
  20. from frigate.models import Recordings
  21. SQL = pw.SQL
  22. def migrate(migrator, database, fake=False, **kwargs):
  23. migrator.sql(
  24. '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)'
  25. )
  26. migrator.sql(
  27. 'CREATE INDEX IF NOT EXISTS "recordings_camera" ON "recordings" ("camera")'
  28. )
  29. migrator.sql(
  30. 'CREATE UNIQUE INDEX IF NOT EXISTS "recordings_path" ON "recordings" ("path")'
  31. )
  32. migrator.sql(
  33. 'CREATE INDEX IF NOT EXISTS "recordings_start_time_end_time" ON "recordings" (start_time, end_time)'
  34. )
  35. def rollback(migrator, database, fake=False, **kwargs):
  36. pass