`prisma db push` is how both containers reconcile the database at start, and it stops the moment a change could destroy data — a dropped column, a dropped table, a unique index over rows it has not seen. It stops for the whole push, so the reaction table and the `upvotes` column left a deployment restart- looping on "Use the --accept-data-loss flag", with the identity columns and the download token stuck behind them. `prisma/pre-push.sql` is every one of those changes written out in full and applied first, so the push that follows only ever sees work it considers safe. It is idempotent, a no-op on a fresh database, and it carries the whole series since local IPA storage, so a deployment that skipped four releases catches up in one boot. Both containers run it; an advisory lock makes the second one wait rather than race the first. Not `--accept-data-loss`: that flag would wave through the next drop nobody meant to make. A destructive change stays something somebody wrote down.
37 lines
1.3 KiB
Docker
37 lines
1.3 KiB
Docker
FROM node:20-slim
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libssl3 \
|
|
zlib1g \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci --ignore-scripts
|
|
COPY prisma ./prisma/
|
|
RUN npx prisma generate
|
|
|
|
COPY . .
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
# /app/storage holds the IPA files and tweak icons and is shared with the app.
|
|
# NOTE: a bind mount there shadows this directory, so the host path must already
|
|
# be owned by uid/gid 1001 — the build-time chown does not reach it.
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nextjs && \
|
|
mkdir -p /app/tdlib-data/db /app/tdlib-data/files \
|
|
/app/storage/ipa /app/storage/icons /app/storage/tmp \
|
|
/tmp/ftstore && \
|
|
chown -R nextjs:nodejs /app /tmp/ftstore
|
|
|
|
USER nextjs
|
|
|
|
# Same two steps the app boots with, in the same order: `pre-push.sql` applies
|
|
# what `db push` refuses to do to a database that already has rows, then the
|
|
# push. Whichever container gets there first does the work; the script takes an
|
|
# advisory lock so the other one waits rather than racing it.
|
|
CMD ["sh", "-c", "npx prisma db execute --schema prisma/schema.prisma --file prisma/pre-push.sql && npx prisma db push --skip-generate && npx tsx worker/index.ts"]
|