fix(migrator): replace payload migrate with direct psql runner
Some checks failed
CI / Type Check (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
Deploy / Build & Push Image (push) Has been cancelled
Deploy / Deploy to VPS (push) Has been cancelled

tsx@4.21.0 + Node.js v22 has two unfixable interop bugs:
- --import tsx/esm hook: importSyncForRequire fails on @/ path aliases
- tsx runner: @next/env has __esModule:true but no .default export → TypeError

Solution: run SQL migrations directly via psql (alpine + postgresql-client).
All migration files use IF NOT EXISTS guards so they're idempotent on re-run.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-13 20:12:02 +01:00
parent a26a9c05ae
commit 79b24ef3d9

View file

@ -1,16 +1,15 @@
# syntax=docker/dockerfile:1
# Migrator image — runs `payload migrate` / `payload migrate:create`
# tsx is used as the RUNNER (not as a hook) to avoid the Node.js v22
# importSyncForRequire bug that breaks --import tsx/esm hook mode.
# Migrator — runs SQL migration files via psql.
# Bypasses tsx/Node.js v22 importSyncForRequire + @next/env interop bugs.
# All migrations must be idempotent SQL (use IF NOT EXISTS / ADD COLUMN IF NOT EXISTS).
FROM node:22-alpine AS base
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
ENTRYPOINT ["pnpm", "exec", "tsx"]
CMD ["node_modules/payload/bin.js", "migrate"]
FROM alpine:3
RUN apk add --no-cache postgresql-client
WORKDIR /migrations
COPY migrations/ .
CMD ["sh", "-c", "\
for f in $(ls -v *.sql 2>/dev/null); do \
echo \"→ $f\"; \
psql \"$DATABASE_URL\" -v ON_ERROR_STOP=0 -f \"$f\" && echo \"✓ $f\" || echo \"⚠ $f (errors ignored — likely already applied)\"; \
done; \
echo '✓ migrations done'"]