From 1e9eae8d9a6703125eff29fc4988dac8da406197 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 13 Dec 2020 10:04:55 -0600 Subject: [PATCH] allow db path to be customized --- README.md | 6 ++++++ frigate/app.py | 2 +- frigate/config.py | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a1a4f34e..18007d4e8 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,12 @@ logger: logs: frigate.mqtt: error +# Optional: database configuration +database: + # Optional: database path + # This may need to be in a custom location if network storage is used for clips + path: /media/frigate/clips/frigate.db + # Optional: detectors configuration # USB Coral devices will be auto detected with CPU fallback detectors: diff --git a/frigate/app.py b/frigate/app.py index 17a099903..8e4cb4d63 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -103,7 +103,7 @@ class FrigateApp(): self.detected_frames_queue = mp.Queue(maxsize=len(self.config.cameras.keys())*2) def init_database(self): - self.db = SqliteExtDatabase(f"/{os.path.join(CLIPS_DIR, 'frigate.db')}") + self.db = SqliteExtDatabase(self.config.database.path) models = [Event] self.db.bind(models) self.db.create_tables(models, safe=True) diff --git a/frigate/config.py b/frigate/config.py index 03d8ac3ea..dc20851f1 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -193,6 +193,9 @@ CAMERAS_SCHEMA = vol.Schema(vol.All( FRIGATE_CONFIG_SCHEMA = vol.Schema( { + vol.Optional('database', default={}): { + vol.Optional('path', default=os.path.join(CLIPS_DIR, 'frigate.db')): str + }, vol.Optional('model', default={'width': 320, 'height': 320}): { vol.Required('width'): int, vol.Required('height'): int @@ -214,6 +217,19 @@ FRIGATE_CONFIG_SCHEMA = vol.Schema( } ) +class DatabaseConfig(): + def __init__(self, config): + self._path = config['path'] + + @property + def path(self): + return self._path + + def to_dict(self): + return { + 'path': self.path + } + class ModelConfig(): def __init__(self, config): self._width = config['width'] @@ -781,6 +797,7 @@ class FrigateConfig(): config = self._sub_env_vars(config) + self._database = DatabaseConfig(config['database']) self._model = ModelConfig(config['model']) self._detectors = { name: DetectorConfig(d) for name, d in config['detectors'].items() } self._mqtt = MqttConfig(config['mqtt']) @@ -813,6 +830,7 @@ class FrigateConfig(): def to_dict(self): return { + 'database': self.database.to_dict(), 'model': self.model.to_dict(), 'detectors': {k: d.to_dict() for k, d in self.detectors.items()}, 'mqtt': self.mqtt.to_dict(), @@ -821,6 +839,10 @@ class FrigateConfig(): 'logger': self.logger.to_dict() } + @property + def database(self): + return self._database + @property def model(self): return self._model