Files
appfactory-tools/scripts/migrate-deployment-locks-db.sh
T
2026-05-29 10:43:53 +02:00

45 lines
884 B
Bash
Executable File

#!/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 deployment_locks (
target_type TEXT NOT NULL,
target_id TEXT NOT NULL,
job_id INTEGER NOT NULL,
worker_id TEXT NOT NULL,
acquired_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at TEXT,
PRIMARY KEY (target_type, target_id)
)
""")
con.execute("""
CREATE INDEX IF NOT EXISTS idx_deployment_locks_job_id
ON deployment_locks(job_id)
""")
con.execute("""
CREATE INDEX IF NOT EXISTS idx_deployment_locks_expires_at
ON deployment_locks(expires_at)
""")
con.commit()
con.close()
print("Deployment locks migration completed.")
PY