fix: copy and move
This commit is contained in:
Binary file not shown.
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -35,5 +36,8 @@ def _load_root_aliases() -> dict[str, str]:
|
||||
|
||||
|
||||
def get_settings() -> Settings:
|
||||
task_db_path = os.getenv("WEBMANAGER_TASK_DB_PATH", "webui/backend/data/tasks.db").strip()
|
||||
default_task_db_path = str(Path(__file__).resolve().parents[1] / "data" / "tasks.db")
|
||||
task_db_path = os.getenv("WEBMANAGER_TASK_DB_PATH", default_task_db_path).strip()
|
||||
if not task_db_path:
|
||||
task_db_path = default_task_db_path
|
||||
return Settings(root_aliases=_load_root_aliases(), task_db_path=task_db_path)
|
||||
|
||||
Binary file not shown.
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user