You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
553 B

#!/bin/bash
# Applies database migrations in order.
# Usage: ./migrate.sh [up|down]
set -euo pipefail
DB_URL="${DATABASE_URL:-postgresql://brain:brain@localhost:5432/second_brain}"
MIGRATIONS_DIR="$(dirname "$0")/migrations"
ACTION="${1:-up}"
if [ "$ACTION" = "up" ]; then
echo "Applying schema..."
psql "$DB_URL" -f "$(dirname "$0")/schema.sql"
echo "Schema applied."
elif [ "$ACTION" = "down" ]; then
echo "Dropping schema..."
psql "$DB_URL" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
echo "Schema dropped."
fi

Powered by TurnKey Linux.