From 79b24ef3d95cafe226d37f31b270a0cf2fc679ea Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Wed, 13 May 2026 20:12:02 +0100 Subject: [PATCH] fix(migrator): replace payload migrate with direct psql runner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Dockerfile.migrator | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Dockerfile.migrator b/Dockerfile.migrator index 4c3690f..a195278 100644 --- a/Dockerfile.migrator +++ b/Dockerfile.migrator @@ -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'"]