Correct applied_at type annotation to str

_AppliedMigration.applied_at was annotated datetime.datetime but
the value is the TEXT timestamp read straight from the
_sqlite_migrations table - always a string, matching the format
written by both this module and the older sqlite-migrate package.
Added a test pinning the runtime type.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
This commit is contained in:
Claude 2026-07-04 18:47:08 +00:00
commit c76aad50ae
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View file

@ -19,7 +19,9 @@ class Migrations:
@dataclass
class _AppliedMigration:
name: str
applied_at: datetime.datetime
# A string timestamp such as "2026-07-04 12:00:00.000000+00:00" -
# stored as TEXT in the _sqlite_migrations table
applied_at: str
def __init__(self, name: str):
"""

View file

@ -80,6 +80,18 @@ def test_order_does_not_matter(migrations, migrations_not_ordered_alphabetically
assert db1.schema == db2.schema
def test_applied_at_is_a_string(migrations):
db = sqlite_utils.Database(memory=True)
migrations.apply(db)
applied = migrations.applied(db)
assert len(applied) == 2
for migration in applied:
# applied_at is the TEXT timestamp straight from the
# _sqlite_migrations table, e.g. "2026-07-04 12:00:00.000000+00:00"
assert isinstance(migration.applied_at, str)
assert migration.applied_at.endswith("+00:00")
def test_failing_migration_rolls_back(migrations):
@migrations()
def m003(db):