R
Railway2y ago
molul

strapi project deletes all data and config on every deploy

Hi. This must be a noobie question, but yesterday I made my first strapi deploy on railway, and after the first one I updated the repo with a few small tweaks, and everytime a new deploy was made, all config and data was erased and I had to set up all roles permissions and email templates. Other than that, everything seems to work properly once setup is done. What an I missing?
12 Replies
Percy
Percy2y ago
Project ID: 3fedc45b-412f-4493-8ac0-01faa7d93ccb
Percy
Percy2y ago
Yes, it appears that Strapi wipes and reconfigures all table data on deploy when setting up a new deploy of Strapi.
⚠️ experimental feature
molul
molulOP2y ago
Project ID: 3fedc45b-412f-4493-8ac0-01faa7d93ccb Ok, so what should I do if/when I want to make a modification to the CMS?
Adam
Adam2y ago
Any data you’ve stored in your repo will be lost each time you redeploy I’m not sure what a CMS is, but if it’s a file you want to make changes to then you’ll have to push a new commit each time
IgnisDa
IgnisDa2y ago
I think the actual problem here is the database being used
molul
molulOP2y ago
But strapi is connected to a postgres database from the very first deploy. Shouldn't it be stored there?
IgnisDa
IgnisDa2y ago
Must not be connected properly. Can you show config?
molul
molulOP2y ago
Hmm makes sense, I guess. I'm far from the computer but I'll post it tomorrow 👍
Seb
Seb2y ago
You gotta have prod env deployed on Strapi and a dev env locally on your PC. Every time you want to make a change (new data model, ...) you have to do it locally and then push it to the prod version
molul
molulOP2y ago
Actually, the things I pushed so far were environment variables changes, not new collections or whatever, so I guess it makes sense strapi was fully rebuilt. The changes I pushed were to try to have the confirmation email link working properly, which I haven't yet achieved. Will try a few things tomorrow and get back Happy 2023, by the way! 🙂 Ok, I'm starting to see things but I'm still confused. I think the Strapi deploy in Railway is still connected to the sqlite and not to the postgres database I created. I'll try to explain. No need to read this now, but I followed this tutorial and other guides in strapi forums and docs: https://dev.to/yinks/how-to-create-and-deploy-a-strapi-project-on-railway-3kja The important things: -I added NODE_ENV=production, BACKEND_URL=<<the railway Strapi deploy URL>> and BACKEND_URL_LOCAL=http://localhost:1337 to the Strapi .env file (which is added to .gtignore so it's not pushed -I added the three variables to Railway deploy variables -I edited ./config/server.js like this: module.exports = ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), url: env('BACKEND_URL_LOCAL'), app: { keys: env.array('APP_KEYS'), }, }); -I created the directory "env/production" and then added a file "database.js" with the Postgres database info, and also a file "server.js" with this content: module.exports = () => ({ host: env('HOST'), port: env.int('PORT'), url: env('BACKEND_URL'), }) Now, if I start my local Strapi project with this command: ENV_PATH=./.env.production NODE_ENV=production npm run start When it's done, I get this info: "To manage your project 🚀, go to the administration panel at: http://localhost:1337/admin" I would expect to get "To manage your project 🚀, go to the administration panel at: <<my railway strapi URL>>/admin" So, as I'm getting localhost:1337 and not "my strapi URL", I guess it's using the ./config/server.js file (the local one) and not ./env/production/server.js. I confirmed that by changing the ./config/server.js to this: module.exports = ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), url: env('BACKEND_URL'), app: { keys: env.array('APP_KEYS'), }, }); In this case, when I run Strapi, I'm being told to go to my Railway Strapi URL So the question would be: how is it getting ./config/server.js and not ./node/production/server.js, when I'm using NODE_ENV=production? Ok, I finally understood everything and all is finally working. First, everytime you change anything regarding environment variables, all data and config will be wiped. But not when you add a new data model. That's a relief. Second, mixing tutorials is not good. Continuing from the previous message, I deleted ./env/production/server.js, as it wasn't ignored. It was just a matter of setting ./config/server.js like this: module.exports = () => ({ host: env('HOST'), port: env.int('PORT'), url: env('BACKEND_URL'), }) And then have BACKEND_URL as http://localhost:1337/ in my .env variable for development (.env is not being tracked in github) and as my Railway URL in Railway.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Adam
Adam2y ago
Please read the above messages
Want results from more Discord servers?
Add your server