class Migration:
__slots__: typing.Sequence[str] = (
"_name",
"_version",
"_checksum",
"_is_applied",
"_description",
"_upgrade_process",
"_downgrade_process",
)
def __init__(
self,
*,
name: str,
version: int,
checksum: str,
is_applied: bool,
description: str,
upgrade_process: MigrationProcess,
downgrade_process: MigrationProcess,
) -> None:
self._name = name
self._version = version
self._checksum = checksum
self._is_applied = is_applied
self._description = description
self._upgrade_process = upgrade_process
self._downgrade_process = downgrade_process
@property
def name(self) -> str:
return self._name
@property
def version(self) -> int:
return self._version
@property
def checksum(self) -> str:
return self._checksum
@property
def description(self) -> str:
return self._description
@property
def is_applied(self) -> bool:
return self._is_applied
@property
def upgrade_process(self) -> MigrationProcess:
return self._upgrade_process
@property
def downgrade_process(self) -> MigrationProcess:
return self._downgrade_process
def set_is_applied(self, value: bool, /) -> None:
self._is_applied = value
def to_dict(self, *, unique: bool = False) -> typing.Dict[str, typing.Any]:
mapping = {
"name": self.name,
"version": self.version,
"checksum": self.checksum,
"is_applied": self.is_applied,
"description": self.description,
}
if unique:
mapping["_id"] = self.version
return mapping