refactor: update environment configuration, enhance installation script, and add migration scripts for database setup
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
if [ -z "${DATABASE_URL:-}" ]; then
|
||||
echo "DATABASE_URL is required." >&2
|
||||
echo "Example:" >&2
|
||||
echo " DATABASE_URL='postgresql://postgres:password@host:5432/postgres' bash ./scripts/apply-migrations.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SQL_FILES=(
|
||||
"supabase/schema.sql"
|
||||
"supabase/migrations/0002_add_freelancer_os_core_tables.sql"
|
||||
"supabase/migrations/0003_add_project_planning_assets.sql"
|
||||
"supabase/migrations/0004_add_business_os_tables.sql"
|
||||
"supabase/migrations/0005_add_advanced_crm_tables.sql"
|
||||
"supabase/migrations/0006_add_pgvector_and_embeddings.sql"
|
||||
"supabase/migrations/0007_add_client_portal_tables.sql"
|
||||
"supabase/migrations/0008_add_project_progress_and_quota.sql"
|
||||
"supabase/migrations/0009_lock_registration_after_first_admin.sql"
|
||||
)
|
||||
|
||||
run_sql_file() {
|
||||
local file_path="$1"
|
||||
local absolute_path="$ROOT_DIR/$file_path"
|
||||
|
||||
if [ ! -f "$absolute_path" ]; then
|
||||
echo "Missing SQL file: $file_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Applying $file_path"
|
||||
|
||||
if command -v psql >/dev/null 2>&1; then
|
||||
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f "$absolute_path"
|
||||
elif command -v docker >/dev/null 2>&1; then
|
||||
docker run --rm -i postgres:16-alpine \
|
||||
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f - < "$absolute_path"
|
||||
else
|
||||
echo "Neither psql nor docker is available to run migrations." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
for sql_file in "${SQL_FILES[@]}"; do
|
||||
run_sql_file "$sql_file"
|
||||
done
|
||||
|
||||
echo "All Neta migrations were applied."
|
||||
Reference in New Issue
Block a user