Add bootstrap v2, preflight readiness and migration tooling
This commit is contained in:
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DB_FILE="/opt/appfactory/data/appfactory/appfactory.db"
|
||||
|
||||
if [ ! -f "$DB_FILE" ]; then
|
||||
echo "Missing database: $DB_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python3 - "$DB_FILE" <<'PY'
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
db_file = sys.argv[1]
|
||||
con = sqlite3.connect(db_file)
|
||||
|
||||
con.execute("""
|
||||
CREATE TABLE IF NOT EXISTS jobs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type TEXT NOT NULL,
|
||||
target_type TEXT NOT NULL,
|
||||
target_id TEXT NOT NULL,
|
||||
payload_json TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'queued',
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
started_at TEXT,
|
||||
finished_at TEXT,
|
||||
created_by_user_id INTEGER,
|
||||
created_by_username TEXT,
|
||||
created_by_display_name TEXT,
|
||||
source TEXT NOT NULL DEFAULT 'system',
|
||||
worker_id TEXT,
|
||||
result_json TEXT,
|
||||
error_text TEXT
|
||||
)
|
||||
""")
|
||||
|
||||
con.execute("""
|
||||
CREATE TABLE IF NOT EXISTS job_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
job_id INTEGER NOT NULL,
|
||||
stream TEXT NOT NULL DEFAULT 'system',
|
||||
message TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
|
||||
con.execute("""
|
||||
CREATE INDEX IF NOT EXISTS idx_jobs_status
|
||||
ON jobs(status)
|
||||
""")
|
||||
|
||||
con.execute("""
|
||||
CREATE INDEX IF NOT EXISTS idx_jobs_target
|
||||
ON jobs(target_type, target_id)
|
||||
""")
|
||||
|
||||
con.execute("""
|
||||
CREATE INDEX IF NOT EXISTS idx_jobs_created_at
|
||||
ON jobs(created_at)
|
||||
""")
|
||||
|
||||
con.execute("""
|
||||
CREATE INDEX IF NOT EXISTS idx_job_logs_job_id
|
||||
ON job_logs(job_id)
|
||||
""")
|
||||
|
||||
columns = [row[1] for row in con.execute("PRAGMA table_info(deployments)").fetchall()]
|
||||
if "job_id" not in columns:
|
||||
con.execute("ALTER TABLE deployments ADD COLUMN job_id INTEGER")
|
||||
|
||||
con.commit()
|
||||
|
||||
print("Jobs migration completed.")
|
||||
print("")
|
||||
for row in con.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"):
|
||||
print(f"- {row[0]}")
|
||||
|
||||
con.close()
|
||||
PY
|
||||
Reference in New Issue
Block a user