allow db path to be customized

This commit is contained in:
Blake Blackshear 2020-12-13 10:04:55 -06:00
parent f20b1d75e6
commit dd102ff01d
3 changed files with 29 additions and 1 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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