Recover task metadata store schema on startup
This commit is contained in:
@@ -133,4 +133,24 @@ class TaskMetadataStore:
|
|||||||
def _connect(self) -> sqlite3.Connection:
|
def _connect(self) -> sqlite3.Connection:
|
||||||
connection = sqlite3.connect(self.db_path)
|
connection = sqlite3.connect(self.db_path)
|
||||||
connection.row_factory = sqlite3.Row
|
connection.row_factory = sqlite3.Row
|
||||||
|
# A previous interrupted startup can leave a zero-byte SQLite file
|
||||||
|
# behind before ``__init__`` reaches ``_ensure_schema``. Ensure the
|
||||||
|
# table exists on every connection so the console can recover without
|
||||||
|
# manual deletion or database repair.
|
||||||
|
connection.execute(
|
||||||
|
"""
|
||||||
|
create table if not exists tasks (
|
||||||
|
id text primary key,
|
||||||
|
goal text not null,
|
||||||
|
device_id text not null,
|
||||||
|
status text not null,
|
||||||
|
created_at text not null,
|
||||||
|
updated_at text not null,
|
||||||
|
completed_at text,
|
||||||
|
failure_reason text,
|
||||||
|
source_task_id text,
|
||||||
|
source_attempt integer
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
return connection
|
return connection
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
from storage.task_metadata import TaskMetadataStore
|
||||||
|
|
||||||
|
|
||||||
|
def test_store_recovers_from_preexisting_empty_database(tmp_path) -> None:
|
||||||
|
path = tmp_path / "task_progress.sqlite3"
|
||||||
|
path.touch()
|
||||||
|
|
||||||
|
store = TaskMetadataStore(path)
|
||||||
|
|
||||||
|
assert store.list_tasks() == []
|
||||||
Reference in New Issue
Block a user