Skip to content

Commit

Permalink
allow db path to be customized
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Jan 27, 2021
1 parent f20b1d7 commit dd102ff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion frigate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def init_queues(self):
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)
Expand Down
22 changes: 22 additions & 0 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def ensure_zones_and_cameras_have_different_names(cameras):

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
Expand All @@ -214,6 +217,19 @@ def ensure_zones_and_cameras_have_different_names(cameras):
}
)

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']
Expand Down Expand Up @@ -781,6 +797,7 @@ def __init__(self, config_file=None, config=None):

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'])
Expand Down Expand Up @@ -813,6 +830,7 @@ def _load_file(self, config_file):

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(),
Expand All @@ -821,6 +839,10 @@ def to_dict(self):
'logger': self.logger.to_dict()
}

@property
def database(self):
return self._database

@property
def model(self):
return self._model
Expand Down

0 comments on commit dd102ff

Please sign in to comment.