good forst commit

This commit is contained in:
2026-06-09 02:02:40 +05:30
parent 801c1d7121
commit 249d759e6a
215 changed files with 15425 additions and 1240 deletions
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -euo pipefail
# Phase 2B pre-migration backup
# pg_dump data tables (Account, Group, Message, Approval, SyncRoute, ConsentRecord)
# to ./backups/phase2b-pre-<timestamp>.sql
# Tenant, Admin, AuditEvent are NOT dumped (preserved by migration).
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
BACKUP_DIR="$ROOT_DIR/backups"
TIMESTAMP="$(date -u +%Y%m%dT%H%M%SZ)"
OUT_FILE="$BACKUP_DIR/phase2b-pre-$TIMESTAMP.sql"
mkdir -p "$BACKUP_DIR"
if [ -z "${DATABASE_URL:-}" ]; then
if [ -f "$ROOT_DIR/.env" ]; then
set -a
# shellcheck disable=SC1091
. "$ROOT_DIR/.env"
set +a
fi
fi
if [ -z "${DATABASE_URL:-}" ]; then
echo "ERROR: DATABASE_URL is not set and no .env file was found" >&2
exit 1
fi
TABLES=(
"Account"
"Group"
"Message"
"Approval"
"SyncRoute"
"ConsentRecord"
)
ARGS=()
for t in "${TABLES[@]}"; do
# pg_dump -t needs extra quoting to preserve PascalCase identifiers
ARGS+=("-t" "\"$t\"")
done
echo "Dumping data-only backup of ${TABLES[*]} to $OUT_FILE"
pg_dump "$DATABASE_URL" \
--data-only \
--no-owner \
--no-privileges \
--inserts \
"${ARGS[@]}" \
-f "$OUT_FILE"
echo "Done. Size: $(wc -c < "$OUT_FILE") bytes"
echo "To restore (NOT recommended after Phase 2B has run):"
echo " psql \"\$DATABASE_URL\" -f $OUT_FILE"