#!/usr/bin/env bash # Initialise the XAMXAM SQLite database from schema.sql. # Safe to run on existing databases — schema uses IF NOT EXISTS / INSERT OR IGNORE. # Usage: # scripts/migrate.sh # xamxam.db (default) set -euo pipefail REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}" # Detect layout: local dev has app/ subdir, server has files at repo root if [ -d "$REPO_ROOT/app/storage" ]; then SCHEMA="$REPO_ROOT/app/storage/schema.sql" PROD_DB="$REPO_ROOT/app/storage/xamxam.db" elif [ -f "$REPO_ROOT/storage/schema.sql" ]; then SCHEMA="$REPO_ROOT/storage/schema.sql" PROD_DB="$REPO_ROOT/storage/xamxam.db" else echo "ERROR: cannot find storage/schema.sql" >&2 exit 1 fi init_db() { local db="$1" local label="$2" echo " [$label] applying schema…" sqlite3 "$db" < "$SCHEMA" echo " [$label] done" } init_db "$PROD_DB" "xamxam.db"