fix: copy and move

This commit is contained in:
kodi
2026-03-11 11:45:06 +01:00
parent 05816751b1
commit 523395b92a
14 changed files with 239 additions and 15 deletions
+26
View File
@@ -8,6 +8,23 @@ from pathlib import Path
VALID_STATUSES = {"queued", "running", "completed", "failed"}
VALID_OPERATIONS = {"copy", "move"}
TASK_MIGRATION_COLUMNS: dict[str, str] = {
"operation": "TEXT NOT NULL DEFAULT 'copy'",
"status": "TEXT NOT NULL DEFAULT 'queued'",
"source": "TEXT NOT NULL DEFAULT ''",
"destination": "TEXT NOT NULL DEFAULT ''",
"done_bytes": "INTEGER NULL",
"total_bytes": "INTEGER NULL",
"done_items": "INTEGER NULL",
"total_items": "INTEGER NULL",
"current_item": "TEXT NULL",
"failed_item": "TEXT NULL",
"error_code": "TEXT NULL",
"error_message": "TEXT NULL",
"created_at": "TEXT NOT NULL",
"started_at": "TEXT NULL",
"finished_at": "TEXT NULL",
}
class TaskRepository:
@@ -197,6 +214,15 @@ class TaskRepository:
ON tasks(created_at DESC)
"""
)
self._migrate_tasks_columns(conn)
def _migrate_tasks_columns(self, conn: sqlite3.Connection) -> None:
rows = conn.execute("PRAGMA table_info(tasks)").fetchall()
existing_columns = {row["name"] for row in rows}
for column, ddl in TASK_MIGRATION_COLUMNS.items():
if column in existing_columns:
continue
conn.execute(f"ALTER TABLE tasks ADD COLUMN {column} {ddl}")
def _connect(self) -> sqlite3.Connection:
conn = sqlite3.connect(self._db_path)