ci: dump prod DB before each migration with size check
Some checks failed
CI / Lint, Test & Build (push) Failing after 5m40s
Deploy to Production / Build and Deploy (push) Has been cancelled

This commit is contained in:
Antigravity
2026-05-16 22:26:43 +00:00
parent 9e8afa4adf
commit d0b8713148

View File

@@ -142,6 +142,17 @@ jobs:
echo "=== Create vector extension ==="
docker compose exec -T postgres psql -U "${POSTGRES_USER:-memento}" -d "${POSTGRES_DB:-memento}" -c "CREATE EXTENSION IF NOT EXISTS vector;"
echo "=== Dump database before migration ==="
DUMP_FILE="/opt/memento/backups/pre-migrate-$(date +%Y%m%d-%H%M%S).sql.gz"
mkdir -p /opt/memento/backups
docker compose exec -T postgres pg_dump -U "${POSTGRES_USER:-memento}" -d "${POSTGRES_DB:-memento}" --clean --if-exists | gzip > "$DUMP_FILE"
DUMP_SIZE=$(stat -c%s "$DUMP_FILE")
if [ "$DUMP_SIZE" -lt 1048576 ]; then
echo "ERROR: Dump is only $DUMP_SIZE bytes (< 1MB). Aborting deploy!"
exit 1
fi
echo "Backup saved: $DUMP_FILE ($(( DUMP_SIZE / 1024 ))KB)"
echo "=== Resolve failed prisma migrations ==="
docker compose exec -T postgres psql -U "${POSTGRES_USER:-memento}" -d "${POSTGRES_DB:-memento}" -c "UPDATE \"_prisma_migrations\" SET \"finished_at\"=NOW(), \"rolled_back_at\"=NULL WHERE \"finished_at\" IS NULL AND \"rolled_back_at\" IS NULL;" || true
@@ -203,4 +214,8 @@ jobs:
- name: Cleanup
if: always()
run: ssh root@192.168.1.190 "docker image prune -f" || true
run: |
ssh root@192.168.1.190 << 'ENDSSH'
docker image prune -f
cd /opt/memento/backups 2>/dev/null && ls -t pre-migrate-*.sql.gz | tail -n +11 | xargs -r rm -f && echo "Old backups cleaned" || true
ENDSSH