feat(errors): migrate error-reporting stack from PostgreSQL to MariaDB (BIT-255)
Replace Postgres with MariaDB 11 in docker-compose; convert all database/error_reporting and db/migrations SQL to InnoDB-friendly syntax (DATETIME(6), AUTO_INCREMENT, ON DUPLICATE KEY). Run admin portal DDL in the same migrate one-shot as error_reporting. Switch ingest-api, collector-worker, and api from pg to mysql2 (pools, parameterized queries, transactions). Align ingest writes with er_incident_occurrences and include project_id on idempotency inserts. Add scripts/run-mysql-migrations.sh for host-side applies; update LXC run-migrate/verify, deployment docs, and .env.example (mysql://, ER_MYSQL_*). Verified: npm run build + npm test in ingest-api and collector-worker; npm run build in api. Full docker compose not run here (no local daemon). Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
b0b733d5e1
commit
4604606033
44 files changed
+1547
-993
No files matched your search
+23
-14
@@ -1,23 +1,32 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
#!/usr/bin/env bash
|
||||
# Apply error_reporting + admin SQL migrations and error_reporting seeds (Compose one-shot).
|
||||
set -euo pipefail
|
||||
|
||||
: "${PGHOST:=postgres}"
|
||||
: "${PGUSER:=postgres}"
|
||||
: "${PGDATABASE:=error_reporting}"
|
||||
: "${MARIADB_HOST:=mariadb}"
|
||||
: "${MARIADB_USER:?MARIADB_USER required}"
|
||||
: "${MARIADB_PASSWORD:?MARIADB_PASSWORD required}"
|
||||
: "${MARIADB_DATABASE:?MARIADB_DATABASE required}"
|
||||
|
||||
until pg_isready -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE"; do
|
||||
echo "docker-migrate: waiting for ${MARIADB_HOST}..."
|
||||
until mariadb-admin ping -h "${MARIADB_HOST}" -u "${MARIADB_USER}" -p"${MARIADB_PASSWORD}" --silent; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
_run_sql() {
|
||||
psql -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE" -v ON_ERROR_STOP=1 -f "$1"
|
||||
_run_sql_file() {
|
||||
_path="$1"
|
||||
echo "docker-migrate: applying ${_path}"
|
||||
mariadb -h "${MARIADB_HOST}" -u "${MARIADB_USER}" -p"${MARIADB_PASSWORD}" "${MARIADB_DATABASE}" < "${_path}"
|
||||
}
|
||||
|
||||
_run_sql "/migrations/20260322043000_create_error_reporting_core.up.sql"
|
||||
_run_sql "/migrations/20260322044000_create_error_occurrences_and_states.up.sql"
|
||||
_run_sql "/migrations/20260322044500_add_ingest_idempotency.up.sql"
|
||||
_run_sql "/migrations/20260322045000_create_collectors_retention_and_audit.up.sql"
|
||||
_run_sql "/seed/dev_two_projects.sql"
|
||||
_run_sql "/seed/dev_collector_http_fixture.sql"
|
||||
_run_sql_file "/migrations/error_reporting/20260322043000_create_error_reporting_core.up.sql"
|
||||
_run_sql_file "/migrations/error_reporting/20260322044000_create_error_occurrences_and_states.up.sql"
|
||||
_run_sql_file "/migrations/error_reporting/20260322044500_add_ingest_idempotency.up.sql"
|
||||
_run_sql_file "/migrations/error_reporting/20260322045000_create_collectors_retention_and_audit.up.sql"
|
||||
_run_sql_file "/migrations/admin/001_admin_users.sql"
|
||||
_run_sql_file "/migrations/admin/002_admin_refresh_tokens.sql"
|
||||
_run_sql_file "/migrations/admin/003_audit_logs.sql"
|
||||
_run_sql_file "/migrations/admin/004_seed_superadmin.sql"
|
||||
_run_sql_file "/seed/error_reporting/dev_two_projects.sql"
|
||||
_run_sql_file "/seed/error_reporting/dev_collector_http_fixture.sql"
|
||||
|
||||
echo "docker-migrate: complete"
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run SQL migrations from repo root (same files as docker-migrate.sh). Requires mariadb client.
|
||||
# Usage from errors.bitreport.pt root:
|
||||
# ER_MYSQL_HOST=127.0.0.1 ER_MYSQL_USER=... ER_MYSQL_PASSWORD=... ER_MYSQL_DATABASE=... ./scripts/run-mysql-migrations.sh
|
||||
# Or set DATABASE_URL=mysql://user:pass@host:port/db
|
||||
set -euo pipefail
|
||||
|
||||
_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "${_ROOT}"
|
||||
|
||||
if [[ -n "${DATABASE_URL:-}" ]] && [[ "${DATABASE_URL}" == mysql://* || "${DATABASE_URL}" == mariadb://* ]]; then
|
||||
_PARSED="$(python3 -c "
|
||||
import os
|
||||
from urllib.parse import urlparse, unquote
|
||||
u = urlparse(os.environ['DATABASE_URL'])
|
||||
if u.scheme not in ('mysql', 'mariadb', 'mysqli'):
|
||||
raise SystemExit('DATABASE_URL must be mysql:// or mariadb://')
|
||||
host = u.hostname or '127.0.0.1'
|
||||
port = u.port or 3306
|
||||
user = unquote(u.username or '')
|
||||
password = unquote(u.password or '')
|
||||
db = (u.path or '/').lstrip('/').split('?')[0]
|
||||
print(host, port, user, password, db)
|
||||
")"
|
||||
read -r ER_MYSQL_HOST ER_MYSQL_PORT ER_MYSQL_USER ER_MYSQL_PASSWORD ER_MYSQL_DATABASE <<< "${_PARSED}"
|
||||
fi
|
||||
|
||||
: "${ER_MYSQL_HOST:?ER_MYSQL_HOST or mysql DATABASE_URL required}"
|
||||
: "${ER_MYSQL_USER:?ER_MYSQL_USER required}"
|
||||
: "${ER_MYSQL_PASSWORD:?ER_MYSQL_PASSWORD required}"
|
||||
: "${ER_MYSQL_DATABASE:?ER_MYSQL_DATABASE required}"
|
||||
: "${ER_MYSQL_PORT:=3306}"
|
||||
|
||||
_run() {
|
||||
echo "run-mysql-migrations: $1"
|
||||
mariadb -h "${ER_MYSQL_HOST}" -P "${ER_MYSQL_PORT}" -u "${ER_MYSQL_USER}" -p"${ER_MYSQL_PASSWORD}" "${ER_MYSQL_DATABASE}" < "$1"
|
||||
}
|
||||
|
||||
_run "${_ROOT}/database/error_reporting/migrations/20260322043000_create_error_reporting_core.up.sql"
|
||||
_run "${_ROOT}/database/error_reporting/migrations/20260322044000_create_error_occurrences_and_states.up.sql"
|
||||
_run "${_ROOT}/database/error_reporting/migrations/20260322044500_add_ingest_idempotency.up.sql"
|
||||
_run "${_ROOT}/database/error_reporting/migrations/20260322045000_create_collectors_retention_and_audit.up.sql"
|
||||
_run "${_ROOT}/db/migrations/001_admin_users.sql"
|
||||
_run "${_ROOT}/db/migrations/002_admin_refresh_tokens.sql"
|
||||
_run "${_ROOT}/db/migrations/003_audit_logs.sql"
|
||||
_run "${_ROOT}/db/migrations/004_seed_superadmin.sql"
|
||||
_run "${_ROOT}/database/error_reporting/seed/dev_two_projects.sql"
|
||||
_run "${_ROOT}/database/error_reporting/seed/dev_collector_http_fixture.sql"
|
||||
|
||||
echo "run-mysql-migrations: complete"
|
||||
Reference in new issue
Block a user