fix(migrator): replace payload migrate with direct psql runner
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:
parent
a26a9c05ae
commit
79b24ef3d9
1 changed files with 13 additions and 14 deletions
|
|
@ -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'"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue