mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(db): require migration versions to be consecutive
This commit is contained in:
parent
ef8284f009
commit
55acc16b2d
@ -40,8 +40,8 @@ class Migration(BaseModel):
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_to_version(self) -> "Migration":
|
||||
if self.to_version <= self.from_version:
|
||||
raise ValueError("to_version must be greater than from_version")
|
||||
if self.to_version != self.from_version + 1:
|
||||
raise ValueError("to_version must be one greater than from_version")
|
||||
return self
|
||||
|
||||
def __hash__(self) -> int:
|
||||
|
@ -81,9 +81,11 @@ def create_migrate(i: int) -> MigrateCallback:
|
||||
return migrate
|
||||
|
||||
|
||||
def test_migration_to_version_gt_from_version(no_op_migrate_callback: MigrateCallback) -> None:
|
||||
with pytest.raises(ValidationError, match="greater_than_equal"):
|
||||
Migration(from_version=1, to_version=0, migrate=no_op_migrate_callback)
|
||||
def test_migration_to_version_is_one_gt_from_version(no_op_migrate_callback: MigrateCallback) -> None:
|
||||
with pytest.raises(ValidationError, match="to_version must be one greater than from_version"):
|
||||
Migration(from_version=0, to_version=2, migrate=no_op_migrate_callback)
|
||||
# not raising is sufficient
|
||||
Migration(from_version=1, to_version=2, migrate=no_op_migrate_callback)
|
||||
|
||||
|
||||
def test_migration_hash(no_op_migrate_callback: MigrateCallback) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user