migrate legacy conf files that were incorrectly relative to root

This commit is contained in:
Lincoln Stein 2024-03-29 10:21:53 -04:00 committed by Kent Keirsey
parent b0ffe36d21
commit c308654442
2 changed files with 22 additions and 14 deletions

View File

@ -38,6 +38,7 @@ def init_db(config: InvokeAIAppConfig, logger: Logger, image_files: ImageFileSto
migrator.register_migration(build_migration_5()) migrator.register_migration(build_migration_5())
migrator.register_migration(build_migration_6()) migrator.register_migration(build_migration_6())
migrator.register_migration(build_migration_7()) migrator.register_migration(build_migration_7())
print("DEBUG: HERE I AM")
migrator.register_migration(build_migration_8(app_config=config)) migrator.register_migration(build_migration_8(app_config=config))
migrator.run_migrations() migrator.run_migrations()

View File

@ -27,8 +27,9 @@ class Migration8Callback:
change was reverted. To smooth over the revert for our tests, we can migrate the paths back to relative. change was reverted. To smooth over the revert for our tests, we can migrate the paths back to relative.
""" """
models_dir = self._app_config.models_path models_path = self._app_config.models_path
legacy_conf_dir = self._app_config.legacy_conf_path legacy_conf_path = self._app_config.legacy_conf_path
legacy_conf_dir = self._app_config.legacy_conf_dir
stmt = """---sql stmt = """---sql
SELECT SELECT
@ -42,8 +43,8 @@ class Migration8Callback:
for model_id, model_path, model_config_path in all_models: for model_id, model_path, model_config_path in all_models:
# If the model path is inside the models directory, update it to be relative to the models directory. # If the model path is inside the models directory, update it to be relative to the models directory.
if model_path.startswith(str(models_dir)): if model_path.startswith(str(models_path)):
new_path = Path(model_path).relative_to(models_dir) new_path = Path(model_path).relative_to(models_path)
cursor.execute( cursor.execute(
"""--sql """--sql
UPDATE models UPDATE models
@ -54,16 +55,22 @@ class Migration8Callback:
) )
# If the model has a legacy config path and it is inside the legacy conf directory, update it to be # If the model has a legacy config path and it is inside the legacy conf directory, update it to be
# relative to the legacy conf directory. # relative to the legacy conf directory.
if model_config_path and model_config_path.startswith(str(legacy_conf_dir)): if model_config_path:
new_config_path = Path(model_config_path).relative_to(legacy_conf_dir) if model_config_path.startswith(str(legacy_conf_path)): # for absolute version
cursor.execute( new_config_path = Path(model_config_path).relative_to(legacy_conf_path)
"""--sql elif model_config_path.startswith(str(legacy_conf_dir)): # for incorrect root-relative version
UPDATE models new_config_path = Path(*Path(model_config_path).parts[1:])
SET config = json_set(config, '$.config_path', ?) else:
WHERE id = ?; new_config_path = None
""", if new_config_path:
(str(new_config_path), model_id), cursor.execute(
) """--sql
UPDATE models
SET config = json_set(config, '$.config_path', ?)
WHERE id = ?;
""",
(str(new_config_path), model_id),
)
def build_migration_8(app_config: InvokeAIAppConfig) -> Migration: def build_migration_8(app_config: InvokeAIAppConfig) -> Migration: