-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for storing the relationship between recordings and event…
…s in the `RecordingsToEvents` table
- Loading branch information
1 parent
3921a7f
commit 7adea8f
Showing
6 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# migrations/019_recordings_to_events.py | ||
from peewee import CharField, CompositeKey, Model | ||
|
||
from frigate.models import Recordings, Event | ||
|
||
|
||
def migrate(migrator, database, fake=False, **kwargs): | ||
"""Write your migrations here.""" | ||
|
||
@migrator.create_model | ||
class RecordingsToEvents(Model): # type: ignore[misc] | ||
event_id = CharField(null=False, index=True, max_length=30) | ||
recording_id = CharField(null=False, index=True, max_length=30) | ||
|
||
class Meta: | ||
db_table = "recordingstoevents" | ||
primary_key = CompositeKey("event_id", "recording_id") | ||
|
||
sql = """ | ||
INSERT INTO recordingstoevents (recording_id, event_id) | ||
SELECT | ||
r.id AS recording, | ||
e.id AS event | ||
FROM | ||
event e | ||
JOIN | ||
recordings r ON e.camera = r.camera | ||
WHERE | ||
r.start_time <= e.end_time | ||
AND r.end_time >= e.start_time; | ||
""" | ||
migrator.sql(sql) | ||
|
||
|
||
def rollback(migrator, database, fake=False, **kwargs): | ||
"""This function is used to undo the migration, i.e., to drop the RecordingToEvent table.""" | ||
migrator.drop_table("recordingstoevents") |