Files
chat/tests/test_migrate.py
2026-04-26 11:32:32 -04:00

23 lines
694 B
Python

from chat.db.connection import open_db
from chat.db.migrate import apply_migrations
def test_apply_migrations_creates_meta_table(tmp_path):
db = tmp_path / "test.db"
apply_migrations(db)
with open_db(db) as conn:
row = conn.execute(
"SELECT value FROM meta WHERE key = 'schema_version'"
).fetchone()
assert row is not None
assert int(row[0]) >= 1
def test_apply_migrations_idempotent(tmp_path):
db = tmp_path / "test.db"
apply_migrations(db)
apply_migrations(db) # second call must be a no-op
with open_db(db) as conn:
count = conn.execute("SELECT COUNT(*) FROM meta").fetchone()[0]
assert count == 1