#Migrating Postgres schema changes

10 messages · Page 1 of 1 (latest)

chrome perch
#

Hi, I am trying to migrate schema changes to my production Payload instance running inside a docker container.

My CMD in docker looks like this: CMD npm run payload:production migrate && node dist/server.js

The npm script for payload looks like this: "payload:production": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts NODE_ENV=production payload"

I thought this would disable the message where payload asks about changes, but I still see this:
? It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.

Therefore my payload instance doesnt start up.

How can I just tell it to push the changes?

I have created the migration files locally using npm run payload migrate:create

fluid lakeBOT
chrome perch
#

I might be approaching this in the wrong way, so any tips would be greatly appriciated

#

I aslo failed to mention that the reason why I am running the npm run payload:production migrate in the Dockerfile is that the database exists as a service and payload and db run together from a docker compose. So I cant run the migration locally to the production database since it is not exposed

#

Is it possible to maybe run the migrations not by running a npm script, but inside the server js code? Something like payload.drizzle.migrate() when the server first starts up?

chrome perch
# tropic briar DId you ever solve this?

Not fully, but we are switching to a database that is exposed outside the server, so we will be running our migrations from our local machines when needed. I will try to post the script to do this here later, when we finish it.

tropic briar
chrome perch
#

Yeah, that’s also a solution, but you have to be careful, since a migration can delete your data if the table needs to be truncated

tropic briar
#

Right, the issue is with my CI/CD pipeline. I need to set NODE_ENV to development to install dev deps for the build, but then the migrations won't run.

BUT

I think I'm going to turn off the local synchronization during development and just run proper migrations moving forward. I'd rather run migrations in development and just read them before I run them.