Demo: use the script itself as the migrations module

This commit is contained in:
Leo Vasanko
2026-08-07 00:08:50 +00:00
parent 72944c9410
commit ec08c185aa
+3 -6
View File
@@ -10,9 +10,9 @@ lives in this file.
import asyncio
import logging
import sys
from datetime import UTC, datetime, timedelta
from pathlib import Path
from types import ModuleType
import msgspec
@@ -44,13 +44,10 @@ def migrate_v1(d: dict) -> None:
d["settings"] = {"theme": "dark"}
migrations = ModuleType("demo_migrations")
migrations.migrate_v1 = migrate_v1
# Phase 1 instance: default logging, original schema.
kanta_v0 = Kanta(DB, DataV1())
# Phase 2 instance: migrations and a custom log header.
kanta_v1 = Kanta(DB, Data(), migrations=migrations)
# Phase 2 instance: migrations (scanned from this script) and a custom header.
kanta_v1 = Kanta(DB, Data(), migrations=sys.modules[__name__])
_now = datetime(2026, 8, 6, tzinfo=UTC)