fix: add identifier column migration and fix entrypoint resolve logic
- Add explicit migration for CatalogItem.identifier column - Fix entrypoint script: resolve only migrations on 'Failed' lines (not all) - Remove auto-diff generation (use committed migration files instead) - Remove 2>/dev/null that swallowed migration errors
This commit is contained in:
@@ -3,42 +3,21 @@ set -e
|
|||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# 1. Resolve any previously failed migrations so deploy can proceed.
|
# 1. Resolve any previously failed migrations so deploy can proceed.
|
||||||
# Prisma marks failed migrations in _prisma_migrations; we roll them back
|
# Only migrations explicitly marked as "Failed" in the status output are
|
||||||
# so the current run can re-apply them cleanly.
|
# resolved. We grep for lines containing "Failed" and extract the name.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
echo "[migrate] Checking for failed migrations..."
|
echo "[migrate] Checking for failed migrations..."
|
||||||
FAILED=$(bunx prisma migrate status 2>&1 || true)
|
STATUS_OUTPUT=$(bunx prisma migrate status 2>&1 || true)
|
||||||
|
echo "$STATUS_OUTPUT"
|
||||||
|
|
||||||
# Extract failed migration names and mark them as rolled back
|
# Only resolve migrations whose status line explicitly says "Failed"
|
||||||
echo "$FAILED" | grep -oE '[0-9]{14}_[a-z_]+' | while read -r MIGRATION; do
|
echo "$STATUS_OUTPUT" | grep -i "failed" | grep -oE '[0-9]{14}_[a-zA-Z_]+' | while read -r MIGRATION; do
|
||||||
# Only resolve if the status output says it failed
|
echo "[migrate] Resolving failed migration: $MIGRATION"
|
||||||
if echo "$FAILED" | grep -q "failed"; then
|
bunx prisma migrate resolve --rolled-back "$MIGRATION" || true
|
||||||
echo "[migrate] Resolving failed migration: $MIGRATION"
|
|
||||||
bunx prisma migrate resolve --rolled-back "$MIGRATION" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# 2. Generate diff SQL between current migrations and the Prisma schema.
|
# 2. Deploy all pending migrations from the migrations directory.
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
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
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 3. Deploy all pending migrations.
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
echo "[migrate] Running prisma migrate deploy..."
|
echo "[migrate] Running prisma migrate deploy..."
|
||||||
bunx prisma migrate deploy
|
bunx prisma migrate deploy
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "CatalogItem" ADD COLUMN "identifier" TEXT;
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "CatalogItem_identifier_key" ON "CatalogItem"("identifier");
|
||||||
Reference in New Issue
Block a user