mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
check that right no. of migration steps run
This commit is contained in:
parent
a48abfacf4
commit
2dd42d0917
@ -72,20 +72,25 @@ i like turtles
|
|||||||
|
|
||||||
|
|
||||||
class GoodMigrations(MigrationsBase):
|
class GoodMigrations(MigrationsBase):
|
||||||
|
methods_run: int = 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, migrator: ConfigMigrator) -> None:
|
def load(cls, migrator: ConfigMigrator) -> None:
|
||||||
"""Define migrations to perform."""
|
"""Define migrations to perform."""
|
||||||
|
|
||||||
@migrator.register(from_version="3.0.0", to_version="10.0.0")
|
@migrator.register(from_version="3.0.0", to_version="10.0.0")
|
||||||
def migration_1(config_dict: dict[str, Any]) -> dict[str, Any]:
|
def migration_1(config_dict: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
cls.methods_run += 1
|
||||||
return config_dict
|
return config_dict
|
||||||
|
|
||||||
@migrator.register(from_version="10.0.0", to_version="10.0.1")
|
@migrator.register(from_version="10.0.0", to_version="10.0.1")
|
||||||
def migration_2(config_dict: dict[str, Any]) -> dict[str, Any]:
|
def migration_2(config_dict: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
cls.methods_run += 1
|
||||||
return config_dict
|
return config_dict
|
||||||
|
|
||||||
@migrator.register(from_version="10.0.1", to_version="10.0.2")
|
@migrator.register(from_version="10.0.1", to_version="10.0.2")
|
||||||
def migration_3(config_dict: dict[str, Any]) -> dict[str, Any]:
|
def migration_3(config_dict: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
cls.methods_run += 1
|
||||||
return config_dict
|
return config_dict
|
||||||
|
|
||||||
|
|
||||||
@ -359,9 +364,17 @@ def test_migration_check() -> None:
|
|||||||
assert new_config["schema_version"] == CONFIG_SCHEMA_VERSION
|
assert new_config["schema_version"] == CONFIG_SCHEMA_VERSION
|
||||||
|
|
||||||
# Test a custom set of migrations
|
# Test a custom set of migrations
|
||||||
|
GoodMigrations.methods_run = 0
|
||||||
migrator = ConfigMigrator(GoodMigrations)
|
migrator = ConfigMigrator(GoodMigrations)
|
||||||
new_config = migrator.run_migrations({"schema_version": "10.0.0"})
|
new_config = migrator.run_migrations({"schema_version": "10.0.0"})
|
||||||
assert new_config["schema_version"] == "10.0.2"
|
assert new_config["schema_version"] == "10.0.2"
|
||||||
|
assert GoodMigrations.methods_run == 2
|
||||||
|
|
||||||
|
GoodMigrations.methods_run = 0
|
||||||
|
migrator = ConfigMigrator(GoodMigrations)
|
||||||
|
new_config = migrator.run_migrations({"schema_version": "3.0.0"})
|
||||||
|
assert new_config["schema_version"] == "10.0.2"
|
||||||
|
assert GoodMigrations.methods_run == 3
|
||||||
|
|
||||||
# Test a migration that should fail validation
|
# Test a migration that should fail validation
|
||||||
migrator = ConfigMigrator(BadMigrations1)
|
migrator = ConfigMigrator(BadMigrations1)
|
||||||
|
Loading…
Reference in New Issue
Block a user