mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-13 22:55:26 +03:00
Handle migration automatically
This commit is contained in:
parent
079d167d37
commit
0a3988ba73
@ -1437,7 +1437,7 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
default_factory=TimestampStyleConfig,
|
default_factory=TimestampStyleConfig,
|
||||||
title="Global timestamp style configuration.",
|
title="Global timestamp style configuration.",
|
||||||
)
|
)
|
||||||
version: Optional[float] = Field(default=None, title="Current config version.")
|
version: Optional[str] = Field(default=None, title="Current config version.")
|
||||||
|
|
||||||
def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
|
def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
|
||||||
"""Merge camera config with globals."""
|
"""Merge camera config with globals."""
|
||||||
|
|||||||
@ -128,16 +128,13 @@ class EventProcessor(threading.Thread):
|
|||||||
if should_update_db(self.events_in_process[event_data["id"]], event_data):
|
if should_update_db(self.events_in_process[event_data["id"]], event_data):
|
||||||
updated_db = True
|
updated_db = True
|
||||||
camera_config = self.config.cameras[camera]
|
camera_config = self.config.cameras[camera]
|
||||||
event_config: EventsConfig = camera_config.record.events
|
|
||||||
width = camera_config.detect.width
|
width = camera_config.detect.width
|
||||||
height = camera_config.detect.height
|
height = camera_config.detect.height
|
||||||
first_detector = list(self.config.detectors.values())[0]
|
first_detector = list(self.config.detectors.values())[0]
|
||||||
|
|
||||||
start_time = event_data["start_time"] - event_config.pre_capture
|
start_time = event_data["start_time"]
|
||||||
end_time = (
|
end_time = (
|
||||||
None
|
None if event_data["end_time"] is None else event_data["end_time"]
|
||||||
if event_data["end_time"] is None
|
|
||||||
else event_data["end_time"] + event_config.post_capture
|
|
||||||
)
|
)
|
||||||
# score of the snapshot
|
# score of the snapshot
|
||||||
score = (
|
score = (
|
||||||
|
|||||||
@ -268,7 +268,10 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
# if it doesn't overlap with an event, go ahead and drop the segment
|
# if it doesn't overlap with an event, go ahead and drop the segment
|
||||||
# if it ends more than the configured pre_capture for the camera
|
# if it ends more than the configured pre_capture for the camera
|
||||||
else:
|
else:
|
||||||
pre_capture = max(record_config.alerts.pre_capture, record_config.detections.pre_capture)
|
pre_capture = max(
|
||||||
|
record_config.alerts.pre_capture,
|
||||||
|
record_config.detections.pre_capture,
|
||||||
|
)
|
||||||
camera_info = self.object_recordings_info[camera]
|
camera_info = self.object_recordings_info[camera]
|
||||||
most_recently_processed_frame_time = (
|
most_recently_processed_frame_time = (
|
||||||
camera_info[-1][0] if len(camera_info) > 0 else 0
|
camera_info[-1][0] if len(camera_info) > 0 else 0
|
||||||
|
|||||||
@ -555,9 +555,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
def test_inherit_clips_retention(self):
|
def test_inherit_clips_retention(self):
|
||||||
config = {
|
config = {
|
||||||
"mqtt": {"host": "mqtt"},
|
"mqtt": {"host": "mqtt"},
|
||||||
"record": {
|
"record": {"alerts": {"retain": {"days": 20}}},
|
||||||
"alerts": {"retain": {"days": 20 }}
|
|
||||||
},
|
|
||||||
"cameras": {
|
"cameras": {
|
||||||
"back": {
|
"back": {
|
||||||
"ffmpeg": {
|
"ffmpeg": {
|
||||||
@ -577,9 +575,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert config == frigate_config.model_dump(exclude_unset=True)
|
assert config == frigate_config.model_dump(exclude_unset=True)
|
||||||
|
|
||||||
runtime_config = frigate_config.runtime_config()
|
runtime_config = frigate_config.runtime_config()
|
||||||
assert (
|
assert runtime_config.cameras["back"].record.alerts.retain.days == 20
|
||||||
runtime_config.cameras["back"].record.alerts.retain.days == 20
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_roles_listed_twice_throws_error(self):
|
def test_roles_listed_twice_throws_error(self):
|
||||||
config = {
|
config = {
|
||||||
|
|||||||
@ -56,7 +56,11 @@ def migrate_frigate_config(config_file: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if previous_version < "0.14.1-0":
|
if previous_version < "0.14.1-0":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.14...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.14.1-0...")
|
||||||
|
new_config = migrate_0141_0(config)
|
||||||
|
with open(config_file, "w") as f:
|
||||||
|
yaml.dump(new_config, f)
|
||||||
|
previous_version = "0.14.1-0"
|
||||||
|
|
||||||
logger.info("Finished frigate config migration...")
|
logger.info("Finished frigate config migration...")
|
||||||
|
|
||||||
@ -144,7 +148,99 @@ def migrate_014(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]:
|
|||||||
|
|
||||||
new_config["cameras"][name] = camera_config
|
new_config["cameras"][name] = camera_config
|
||||||
|
|
||||||
new_config["version"] = 0.14
|
new_config["version"] = "0.14"
|
||||||
|
return new_config
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_0141_0(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]:
|
||||||
|
"""Handle migrating frigate config to 0.14.1-0"""
|
||||||
|
new_config = config.copy()
|
||||||
|
|
||||||
|
# migrate record.events to record.alerts and record.detections
|
||||||
|
global_record_events = config.get("record", {}).get("events")
|
||||||
|
if global_record_events:
|
||||||
|
alerts_retention = {"retain": {}}
|
||||||
|
detections_retention = {"retain": {}}
|
||||||
|
|
||||||
|
if global_record_events["pre_capture"]:
|
||||||
|
alerts_retention["pre_capture"] = global_record_events["pre_capture"]
|
||||||
|
|
||||||
|
if global_record_events["post_capture"]:
|
||||||
|
alerts_retention["post_capture"] = global_record_events["post_capture"]
|
||||||
|
|
||||||
|
if global_record_events["retain"]["default"]:
|
||||||
|
alerts_retention["retain"]["days"] = global_record_events["retain"][
|
||||||
|
"default"
|
||||||
|
]
|
||||||
|
|
||||||
|
# decide logical detections retention based on current detections config
|
||||||
|
if not config.get("review", {}).get("alerts", {}).get(
|
||||||
|
"required_zones"
|
||||||
|
) or config.get("review", {}).get("detections"):
|
||||||
|
if global_record_events["pre_capture"]:
|
||||||
|
detections_retention["pre_capture"] = global_record_events[
|
||||||
|
"pre_capture"
|
||||||
|
]
|
||||||
|
|
||||||
|
if global_record_events["post_capture"]:
|
||||||
|
detections_retention["post_capture"] = global_record_events[
|
||||||
|
"post_capture"
|
||||||
|
]
|
||||||
|
|
||||||
|
if global_record_events["retain"]["default"]:
|
||||||
|
detections_retention["retain"]["days"] = global_record_events["retain"][
|
||||||
|
"default"
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
detections_retention["retain"]["days"] = 0
|
||||||
|
|
||||||
|
new_config["record"]["alerts"] = alerts_retention
|
||||||
|
new_config["record"]["detections"] = detections_retention
|
||||||
|
|
||||||
|
del new_config["record"]["events"]
|
||||||
|
|
||||||
|
for name, camera in config.get("cameras", {}).items():
|
||||||
|
camera_config: dict[str, dict[str, any]] = camera.copy()
|
||||||
|
|
||||||
|
record_events = camera_config.get("record", {}).get("events")
|
||||||
|
if record_events:
|
||||||
|
alerts_retention = {"retain": {}}
|
||||||
|
detections_retention = {"retain": {}}
|
||||||
|
|
||||||
|
if record_events["pre_capture"]:
|
||||||
|
alerts_retention["pre_capture"] = record_events["pre_capture"]
|
||||||
|
|
||||||
|
if record_events["post_capture"]:
|
||||||
|
alerts_retention["post_capture"] = record_events["post_capture"]
|
||||||
|
|
||||||
|
if record_events["retain"]["default"]:
|
||||||
|
alerts_retention["retain"]["days"] = record_events["retain"]["default"]
|
||||||
|
|
||||||
|
# decide logical detections retention based on current detections config
|
||||||
|
if not camera_config.get("review", {}).get("alerts", {}).get(
|
||||||
|
"required_zones"
|
||||||
|
) or camera_config.get("review", {}).get("detections"):
|
||||||
|
if record_events["pre_capture"]:
|
||||||
|
detections_retention["pre_capture"] = record_events["pre_capture"]
|
||||||
|
|
||||||
|
if record_events["post_capture"]:
|
||||||
|
detections_retention["post_capture"] = record_events["post_capture"]
|
||||||
|
|
||||||
|
if record_events["retain"]["default"]:
|
||||||
|
detections_retention["retain"]["days"] = record_events["retain"][
|
||||||
|
"default"
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
detections_retention["retain"]["days"] = 0
|
||||||
|
|
||||||
|
new_config["record"]["alerts"] = alerts_retention
|
||||||
|
new_config["record"]["detections"] = detections_retention
|
||||||
|
|
||||||
|
del new_config["record"]["events"]
|
||||||
|
|
||||||
|
new_config["cameras"][name] = camera_config
|
||||||
|
|
||||||
|
new_config["version"] = "0.14.1-0"
|
||||||
return new_config
|
return new_config
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user