diff --git a/frigate/config.py b/frigate/config.py index 05ca61f4d..5cf8b2da4 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -1355,6 +1355,7 @@ class FrigateConfig(FrigateBaseModel): default_factory=TimestampStyleConfig, title="Global timestamp style configuration.", ) + version: Optional[float] = Field(default=None, title="Current config version.") def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig: """Merge camera config with globals.""" diff --git a/frigate/util/config.py b/frigate/util/config.py index f395ee125..d8518eac9 100644 --- a/frigate/util/config.py +++ b/frigate/util/config.py @@ -17,16 +17,13 @@ CURRENT_CONFIG_VERSION = 0.14 def migrate_frigate_config(config_file: str): """handle migrating the frigate config.""" logger.info("Checking if frigate config needs migration...") - version_file = os.path.join(CONFIG_DIR, ".version") - if not os.path.isfile(version_file): - previous_version = 0.13 - else: - with open(version_file) as f: - try: - previous_version = float(f.readline()) - except Exception: - previous_version = 0.13 + yaml = YAML() + yaml.indent(mapping=2, sequence=4, offset=2) + with open(config_file, "r") as f: + config: dict[str, dict[str, any]] = yaml.load(f) + + previous_version = config.get("version", 0.13) if previous_version == CURRENT_CONFIG_VERSION: logger.info("frigate config does not need migration...") @@ -35,11 +32,6 @@ def migrate_frigate_config(config_file: str): logger.info("copying config as backup...") shutil.copy(config_file, os.path.join(CONFIG_DIR, "backup_config.yaml")) - yaml = YAML() - yaml.indent(mapping=2, sequence=4, offset=2) - with open(config_file, "r") as f: - config: dict[str, dict[str, any]] = yaml.load(f) - if previous_version < 0.14: logger.info(f"Migrating frigate config from {previous_version} to 0.14...") new_config = migrate_014(config) @@ -57,9 +49,6 @@ def migrate_frigate_config(config_file: str): os.path.join(EXPORT_DIR, file), os.path.join(EXPORT_DIR, new_name) ) - with open(version_file, "w") as f: - f.write(str(CURRENT_CONFIG_VERSION)) - logger.info("Finished frigate config migration...") @@ -141,6 +130,7 @@ def migrate_014(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]: new_config["cameras"][name] = camera_config + new_config["version"] = 0.14 return new_config