|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 6 | +# shellcheck source=scripts/utils |
| 7 | +source "${REPO_ROOT}/scripts/utils" |
| 8 | + |
| 9 | +: "${DB_HOST:?DB_HOST is required}" |
| 10 | +: "${DB_PORT:?DB_PORT is required}" |
| 11 | +: "${DB_USER:?DB_USER is required}" |
| 12 | +: "${DB_PASSWORD:?DB_PASSWORD is required}" |
| 13 | + |
| 14 | +say "Applying Sequin bootstrap SQL..." |
| 15 | +docker run --rm --network host \ |
| 16 | + -v "${REPO_ROOT}/scripts/scaffold/sequin/postgres-docker-entrypoint-initdb.d/create-sequin-database.sql:/bootstrap.sql:ro" \ |
| 17 | + -e "PGPASSWORD=${DB_PASSWORD}" \ |
| 18 | + postgres:14-alpine \ |
| 19 | + psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -v ON_ERROR_STOP=1 -f /bootstrap.sql |
| 20 | + |
| 21 | +say "Recreating test_template..." |
| 22 | +docker run --rm --network host \ |
| 23 | + -e "PGPASSWORD=${DB_PASSWORD}" \ |
| 24 | + postgres:14-alpine \ |
| 25 | + psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -v ON_ERROR_STOP=1 \ |
| 26 | + -c "DROP DATABASE IF EXISTS test_template;" \ |
| 27 | + -c "CREATE DATABASE test_template;" |
| 28 | + |
| 29 | +if [[ "${SKIP_FLYWAY_BUILD:-0}" == "1" ]]; then |
| 30 | + say "Using pre-built crowd_flyway image." |
| 31 | +else |
| 32 | + say "Building flyway image..." |
| 33 | + docker build -t crowd_flyway -f "${REPO_ROOT}/backend/src/database/Dockerfile.flyway" "${REPO_ROOT}/backend/src/database" |
| 34 | +fi |
| 35 | + |
| 36 | +say "Migrating test_template..." |
| 37 | +docker run --rm --network host \ |
| 38 | + -e "PGHOST=${DB_HOST}" \ |
| 39 | + -e "PGPORT=${DB_PORT}" \ |
| 40 | + -e "PGUSER=${DB_USER}" \ |
| 41 | + -e "PGPASSWORD=${DB_PASSWORD}" \ |
| 42 | + -e PGDATABASE=test_template \ |
| 43 | + crowd_flyway |
| 44 | + |
| 45 | +say "Test template database ready." |
0 commit comments