- Replace pdf2pic/GraphicsMagick with pdfjs-dist + @napi-rs/canvas for Vercel-compatible PDF rasterization - Replace MinIO with Supabase Storage (S3-compatible); rename minio.ts to storage.ts and update all imports - Replace in-memory job queue with Upstash QStash; upload route now persists files to storage before enqueuing, /api/jobs/process handles the QStash callback - Convert email watcher from persistent IMAP connection to stateless scanInbox() polled by Vercel Cron every 2 minutes - Add FTP watcher (basic-ftp) with cron polling for scanner integration via Dreamhost FTP drop directory - Add FTP config fields to AppSettings schema - Remove folder watcher (chokidar), standalone output, Docker-only code - Update next.config.ts, middleware, instrumentation for serverless - Add vercel.json with cron schedules for email and FTP polling - Add migration scripts for database (pg_dump/restore) and storage (S3-to-S3 copy) with verification Made-with: Cursor
76 lines
2.9 KiB
Bash
Executable file
76 lines
2.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ─── Database Migration: Homelab PostgreSQL → Supabase ────────
|
|
#
|
|
# Prerequisites:
|
|
# - pg_dump and pg_restore installed locally
|
|
# - Network access to both the homelab PG and Supabase PG
|
|
# - Supabase project created with direct connection string
|
|
#
|
|
# Usage:
|
|
# HOMELAB_DB_URL="postgresql://echos_ocr:PASSWORD@192.168.68.102:5432/echos_ocr" \
|
|
# SUPABASE_DB_URL="postgresql://postgres.REF:PASSWORD@db.REF.supabase.co:5432/postgres" \
|
|
# bash scripts/migrate-database.sh
|
|
|
|
if [ -z "${HOMELAB_DB_URL:-}" ]; then
|
|
echo "Error: HOMELAB_DB_URL is not set"
|
|
echo "Example: postgresql://echos_ocr:PASSWORD@192.168.68.102:5432/echos_ocr"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${SUPABASE_DB_URL:-}" ]; then
|
|
echo "Error: SUPABASE_DB_URL is not set (use the DIRECT connection, port 5432, not pooled)"
|
|
echo "Example: postgresql://postgres.REF:PASSWORD@db.REF.supabase.co:5432/postgres"
|
|
exit 1
|
|
fi
|
|
|
|
DUMP_FILE="echos_ocr_backup_$(date +%Y%m%d_%H%M%S).dump"
|
|
|
|
echo "=== Step 1: Dumping homelab database ==="
|
|
pg_dump "${HOMELAB_DB_URL}" -Fc -f "${DUMP_FILE}"
|
|
echo "Dump created: ${DUMP_FILE} ($(du -h "${DUMP_FILE}" | cut -f1))"
|
|
|
|
echo ""
|
|
echo "=== Step 2: Restoring to Supabase ==="
|
|
pg_restore "${SUPABASE_DB_URL}" --no-owner --no-privileges --clean --if-exists "${DUMP_FILE}" 2>&1 || true
|
|
echo "Restore complete (some warnings about existing objects are normal)"
|
|
|
|
echo ""
|
|
echo "=== Step 3: Pushing schema with Prisma ==="
|
|
echo "Running 'npx prisma db push' to ensure schema alignment..."
|
|
DATABASE_URL="${SUPABASE_DB_URL}" npx prisma db push --skip-generate 2>&1
|
|
echo "Schema push complete"
|
|
|
|
echo ""
|
|
echo "=== Step 4: Verifying row counts ==="
|
|
psql "${SUPABASE_DB_URL}" -c "
|
|
SELECT 'User' as table_name, count(*) FROM \"User\"
|
|
UNION ALL SELECT 'Organization', count(*) FROM \"Organization\"
|
|
UNION ALL SELECT 'OrgMember', count(*) FROM \"OrgMember\"
|
|
UNION ALL SELECT 'ResponseCard', count(*) FROM \"ResponseCard\"
|
|
UNION ALL SELECT 'ProcessingJob', count(*) FROM \"ProcessingJob\"
|
|
UNION ALL SELECT 'ActivityLog', count(*) FROM \"ActivityLog\"
|
|
UNION ALL SELECT 'Notification', count(*) FROM \"Notification\"
|
|
UNION ALL SELECT 'Integration', count(*) FROM \"Integration\"
|
|
ORDER BY table_name;
|
|
"
|
|
|
|
echo ""
|
|
echo "=== Compare with homelab counts ==="
|
|
psql "${HOMELAB_DB_URL}" -c "
|
|
SELECT 'User' as table_name, count(*) FROM \"User\"
|
|
UNION ALL SELECT 'Organization', count(*) FROM \"Organization\"
|
|
UNION ALL SELECT 'OrgMember', count(*) FROM \"OrgMember\"
|
|
UNION ALL SELECT 'ResponseCard', count(*) FROM \"ResponseCard\"
|
|
UNION ALL SELECT 'ProcessingJob', count(*) FROM \"ProcessingJob\"
|
|
UNION ALL SELECT 'ActivityLog', count(*) FROM \"ActivityLog\"
|
|
UNION ALL SELECT 'Notification', count(*) FROM \"Notification\"
|
|
UNION ALL SELECT 'Integration', count(*) FROM \"Integration\"
|
|
ORDER BY table_name;
|
|
"
|
|
|
|
echo ""
|
|
echo "=== Migration complete ==="
|
|
echo "Backup file retained at: ${DUMP_FILE}"
|
|
echo "Verify the counts above match between homelab and Supabase."
|