Files
errors.bitreport.pt/deploy/lxc/run-migrate.sh
T
1sonhadorandPaperclip b0b733d5e1 feat(BIT-247): consolidate error reporting repo from OTT
Merge ingest-api, collector-worker, admin-ui, database/error_reporting, deploy/lxc,
docker-compose, and deployment docs into the dedicated repository. Paths updated
for repo root (ER_REPO_ROOT, systemd WorkingDirectory). Root README documents layout.

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 18:20:27 +00:00

38 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Apply error_reporting SQL migrations and seeds (same order as docker-migrate.sh).
# Prerequisites: psql (postgresql-client), empty or already-migrated DB, DATABASE_URL + ER_REPO_ROOT (or legacy OTT_ROOT).
set -euo pipefail
_ENV_FILE="/etc/error-reporting/env"
if [[ -f "${_ENV_FILE}" ]]; then
set -a
# shellcheck disable=SC1090
source "${_ENV_FILE}"
set +a
fi
_REPO_ROOT="${ER_REPO_ROOT:-${OTT_ROOT:-}}"
: "${_REPO_ROOT:?Set ER_REPO_ROOT to this repository root (contains database/error_reporting/). Legacy OTT_ROOT is accepted.}"
: "${DATABASE_URL:?Set DATABASE_URL (postgres://...) for psql}"
_MIG="${_REPO_ROOT}/database/error_reporting/migrations"
_SEED="${_REPO_ROOT}/database/error_reporting/seed"
if [[ ! -d "${_MIG}" ]]; then
echo "run-migrate: migrations directory not found: ${_MIG}" >&2
exit 1
fi
_run_sql() {
psql "${DATABASE_URL}" -v ON_ERROR_STOP=1 -f "$1"
}
_run_sql "${_MIG}/20260322043000_create_error_reporting_core.up.sql"
_run_sql "${_MIG}/20260322044000_create_error_occurrences_and_states.up.sql"
_run_sql "${_MIG}/20260322044500_add_ingest_idempotency.up.sql"
_run_sql "${_MIG}/20260322045000_create_collectors_retention_and_audit.up.sql"
_run_sql "${_SEED}/dev_two_projects.sql"
_run_sql "${_SEED}/dev_collector_http_fixture.sql"
echo "run-migrate: complete"