Hey. I'm running into an error while trying to run
pnpm run payloadwhich is a script that runs a script :
"payload": "cross-env PAYLOAD_CONFIG_PATH=payload.config.ts payload"What I'm trying to o is a get a migration because I removed a column from a Block. I use MongoDB database. Let me know if you need any other information.
I'm getting an error:
> @ payload /nnn/app
> cross-env PAYLOAD_CONFIG_PATH=payload.config.ts payload
/nnn/app/node_modules/.pnpm/payload@2.9.0_@swc+helpers@0.5.3_@types+react@18.2.51_esbuild@0.19.12_typescript@5.3.3_webpack@5.90.1/node_modules/payload/dist/bin/index.js:55
if (script.startsWith('migrate')) {
^
TypeError: Cannot read properties of undefined (reading 'startsWith')
at Object.<anonymous> (/nnn/app/node_modules/.pnpm/payload@2.9.0_@swc+helpers@0.5.3_@types+react@18.2.51_esbuild@0.19.12_typescript@5.3.3_webpack@5.90.1/node_modules/payload/dist/bin/index.js:55:12)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at Object.<anonymous> (/Users/maciekkolodziejczyk/Dev/bifor-final/node_modules/.pnpm/payload@2.9.0_@swc+helpers@0.5.3_@types+react@18.2.51_esbuild@0.19.12_typescript@5.3.3_webpack@5.90.1/node_modules/payload/bin.js:2:1)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
Node.js v18.18.0
ELIFECYCLE Command failed with exit code 1. Anyone had a similar problem while trying to run payload script?
You need to pass another param as a command
buildor
migrateetc
A related fix will be in the next release, though
https://github.com/payloadcms/payload/pull/4995thank you, it works 👍
Just another question regarding that topic: is it possible to make payload create migration automatically based on collection and block schema changes?
I tried
payload migrate:create <name>but it just generates a migration file
Regarding possible question about migration prompt when starting dev server - it does not show up. This is my config and server, I use nodemon in dev modee
Or is it possible only with postgres?
ignore me
The new schema is automatically pushed when running in development.
So when i change for example slug of a block, does payload recognise it somehow?
I have changed block slug and move some field from array in a block to upper scope. Doesn't it require a migration? i dont want to lose data from it
And what about prodcution?
For production you want to maintain a more strict approach to creating migrations and then running them as part of your deployment steps
Think of it like versioning for the database schema
With postgres (and most sql dbs) you
willlose data when making schema changes unless you migrate that data as well, the automated migrations only handle schema, so you would have to add additional logic for the data itself, it just comes with the territory
thank you for that, and sorry not to say that explicit: I use MongoDB right now and this is a DB I don't have an experience with comparing to postgres. So my questions are connected to Mongo.
So you say I'll have to create a migration for mongo manually for some basic changes like renaming block?
Mongo is different, it's far more lenient for data schema so you can just make changes on the fly
There will be inconsistencies with documents though and sometimes this can cause errors, since old docs wont have dead fields removed and this probably where you might want to do migrations in mongo
but if you're just devving you most likely dont need to worry about it
I have a site on prod right now where there is some data and wanted to change some stuff, ended up extending the schema and no error came up so far. It's a fairly fresh app so there is not much of a threat of something breaking up.
If I understand correctly, there is no automatic helper/prompt in mongo that detects changes and provides some solution as it is for postgres, right?
And if sth bigger happens, migration is a way to go, right? Is there any article you can recommend about how it can be done? Or just mongo docs?
yeah thats basically right, most of the time though this isnt an issue because schema changes dont happen
thatoften and the areas where you may see errors is where the API expects certain data formats...for example if you change a
contentfield from an array of blocks to richtext, then old content will error for you
a migration script can be just a ts script file that uses the local API to modify data tbh
yeah id look through the docs and other tutorials, i dont have any on hand to recommend
Great, thank you very much for your help!

Star
Discord
online
Get dedicated engineering support directly from the Payload team.