Rename task_* tables to quest_* with legacy-dev migration path (D-007)
Per design/IMPLEMENTATION-ORDER.md 1.1 and decision D-007: the domain model takes the quest vocabulary pre-release. SCHEMA_V1 now creates quest_definitions/quest_instances directly; DAO classes, records and error messages follow (QuestDefinitionsDao, QuestInstancesDao). The migration runner gains migration 2, an async-callable step that detects surviving task_* tables on dev machines and ALTER TABLE RENAMES them inside the migration transaction, with FK clauses rewritten by SQLite. Migration 1's content rewrite is legal because nothing was ever shipped; dev databases stamped version 1 ride migration 2 up to 2.
This commit is contained in:
@@ -18,6 +18,7 @@ from custom_components.nestquest import (
|
||||
)
|
||||
from custom_components.nestquest.db import NestQuestDatabase
|
||||
from custom_components.nestquest.migrations import (
|
||||
MIGRATIONS,
|
||||
VERSION_TABLE,
|
||||
apply_migrations,
|
||||
)
|
||||
@@ -114,12 +115,13 @@ def test_missing_file_opens_fresh(tmp_path) -> None:
|
||||
assert not db_path.exists()
|
||||
database = _run(_async_open_database(_make_hass_mock(), db_path))
|
||||
try:
|
||||
# The file was created fresh and migrations stamped version 1.
|
||||
# The file was created fresh and migrations stamped the
|
||||
# latest schema version.
|
||||
assert db_path.exists()
|
||||
row = _run(
|
||||
database.fetch_one(f"SELECT version FROM {VERSION_TABLE}")
|
||||
)
|
||||
assert row == (1,)
|
||||
assert row == (len(MIGRATIONS),)
|
||||
finally:
|
||||
_run(database.close())
|
||||
|
||||
@@ -151,7 +153,7 @@ def test_valid_file_opens_and_migrations_noop(tmp_path) -> None:
|
||||
row = _run(
|
||||
database.fetch_one(f"SELECT version FROM {VERSION_TABLE}")
|
||||
)
|
||||
assert row == (1,)
|
||||
assert row == (len(MIGRATIONS),)
|
||||
finally:
|
||||
_run(database.close())
|
||||
# Opening a valid file must not rewrite it (the no-op path).
|
||||
@@ -401,7 +403,7 @@ async def test_setup_with_missing_file_creates_and_loads(
|
||||
row = await database.fetch_one(
|
||||
f"SELECT version FROM {VERSION_TABLE}"
|
||||
)
|
||||
assert row == (1,)
|
||||
assert row == (len(MIGRATIONS),)
|
||||
finally:
|
||||
await database.close()
|
||||
assert await async_unload_entry(hass, entry) is True
|
||||
|
||||
Reference in New Issue
Block a user