Skip to content

mongrator.migration

mongrator.migration

MigrationRecord

Bases: TypedDict

Document stored in the tracking collection for each applied migration.

Source code in src/mongrator/migration.py
12
13
14
15
16
17
18
19
class MigrationRecord(TypedDict):
    """Document stored in the tracking collection for each applied migration."""

    _id: MigrationId
    applied_at: datetime
    checksum: Checksum
    direction: Literal["up", "down"]
    duration_ms: int

MigrationFile dataclass

Represents a discovered migration file on disk.

Source code in src/mongrator/migration.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@dataclass
class MigrationFile:
    """Represents a discovered migration file on disk."""

    id: MigrationId
    path: Path
    checksum: Checksum
    module: types.ModuleType | None = field(default=None, repr=False)

    @property
    def up(self) -> Callable[..., Any] | None:
        if self.module is None:
            return None
        return getattr(self.module, "up", None)

    @property
    def down(self) -> Callable[..., Any] | None:
        if self.module is None:
            return None
        return getattr(self.module, "down", None)

    def has_up(self) -> bool:
        return self.up is not None

    def has_down(self) -> bool:
        return self.down is not None

MigrationStatus dataclass

Status of a single migration as reported by runner.status().

Source code in src/mongrator/migration.py
50
51
52
53
54
55
56
57
58
@dataclass
class MigrationStatus:
    """Status of a single migration as reported by runner.status()."""

    id: MigrationId
    applied: bool
    applied_at: datetime | None = None
    checksum_ok: bool = True
    orphaned: bool = False