Files
OnEverDrive/backend/migrate_runs_and_dest.py
T

48 lines
1.7 KiB
Python

import sqlite3
import os
DB_PATH = os.path.join(os.path.dirname(__file__), "onever_drive.db")
def migrate():
print(f"Connecting to database at {DB_PATH}...")
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# 1. Add local_destination_path column to backup_jobs table
try:
cursor.execute("ALTER TABLE backup_jobs ADD COLUMN local_destination_path VARCHAR(1024) NULL")
print("Column 'local_destination_path' added successfully to backup_jobs.")
except sqlite3.OperationalError as e:
print(f"Column 'local_destination_path' could not be added (maybe it already exists?): {e}")
# 2. Create job_runs table
try:
cursor.execute("""
CREATE TABLE IF NOT EXISTS job_runs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
job_id INTEGER NOT NULL,
client_id INTEGER NOT NULL,
started_at DATETIME NOT NULL,
completed_at DATETIME NULL,
status VARCHAR(50) NOT NULL DEFAULT 'RUNNING',
files_scanned INTEGER NOT NULL DEFAULT 0,
files_copied INTEGER NOT NULL DEFAULT 0,
files_skipped INTEGER NOT NULL DEFAULT 0,
errors_count INTEGER NOT NULL DEFAULT 0,
bytes_transferred BIGINT NOT NULL DEFAULT 0,
error_summary TEXT NULL,
FOREIGN KEY(job_id) REFERENCES backup_jobs(id) ON DELETE CASCADE,
FOREIGN KEY(client_id) REFERENCES clients(id) ON DELETE CASCADE
)
""")
print("Table 'job_runs' created successfully.")
except sqlite3.OperationalError as e:
print(f"Table 'job_runs' could not be created: {e}")
conn.commit()
conn.close()
print("Migration finished.")
if __name__ == "__main__":
migrate()