fix: crash loop recovery, auto-migrations, CI test pipeline
- Wrap startup syncs in safeStartup() to prevent crash on external service failure - Add migrate-entrypoint.sh for auto-generating migrations from schema diff - Update Dockerfile migration stage to use entrypoint script - Add test job to build-and-publish workflow (runs before build) - Add tests.yaml workflow to run tests on every push - Fix test setup to use real RSA key pair instead of plain strings - Add test script to package.json
This commit is contained in:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Generate diff SQL between current migrations and the Prisma schema
|
||||
DIFF_SQL=$(bunx prisma migrate diff \
|
||||
--from-migrations prisma/migrations \
|
||||
--to-schema-datamodel prisma/schema.prisma \
|
||||
--script 2>/dev/null || true)
|
||||
|
||||
# If there's a meaningful diff (not just empty/comments), create a migration
|
||||
if [ -n "$DIFF_SQL" ] && echo "$DIFF_SQL" | grep -qvE '^\s*$|^--'; then
|
||||
TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")
|
||||
MIGRATION_DIR="prisma/migrations/${TIMESTAMP}_auto_generated"
|
||||
mkdir -p "$MIGRATION_DIR"
|
||||
echo "$DIFF_SQL" > "$MIGRATION_DIR/migration.sql"
|
||||
echo "[migrate] Created migration: $MIGRATION_DIR"
|
||||
else
|
||||
echo "[migrate] Schema and migrations are in sync — no migration needed."
|
||||
fi
|
||||
|
||||
# Deploy all pending migrations
|
||||
echo "[migrate] Running prisma migrate deploy..."
|
||||
bunx prisma migrate deploy
|
||||
Reference in New Issue
Block a user