Strapi database reset after re-deploy

I'm curious if it's working as intended that the Postgres database deletes all custom data and resets to default whenever I deploy my newest Strapi backend from git. If so, is there a workaround to have the database persist?
26 Replies
Medim
Medim•3y ago
As stated in the readme, if you're using the https://github.com/railwayapp-starters/strapi Railway's filesystem is ephemeral which is why any changes to the filesystem are not persisted between deploys. This is why, this example uses Cloudinary for storage.
GitHub
GitHub - railwayapp-starters/strapi: Deploy Strapi on Railway. Next...
Deploy Strapi on Railway. Next-gen headless CMS. Contribute to railwayapp-starters/strapi development by creating an account on GitHub.
Medim
Medim•3y ago
As far as i know, you can't persist files on re-deploy without using external cloud storage with strapi. (one of the reasons I migrated to directus tbh)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
I'm using Cloudinary for the media files which works well and persists. It's just the postgres database which Railway automatically created for me while installing Strapi that gets reset every time.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
It does, unfortunately. It's a total fresh Strapi installation without any changes to config files or anything like that. I just entered the environment variables and watched railway install strapi. So I wouldn't know how to fix that. I haven't found any configuration options on the railway dashboard.
angelo
angelo•3y ago
The issue is that Strapi wipes and reconfigures all table data on deploy when setting up a new deploy of Strapi.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
That's weird. I've been searching the web for this issue and found tons of people that have the same problem with heroku wiping the db. Are you maybe using an external postgres db for your heroku-hosted Strapi @thanneman ? If it's true that Strapi wipes the db on each deploy, the whole thing is pretty much useless. They can't expect the user to always have exactly the same build running for years and years only to preserve data
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
Got it. Maybe it's just the free plan on heroku that wipes the db then. Thanks a lot for the info! @Angelo Are you sure that Railway always sets up the Strapi build to reconfigure the db after each delopy? In that case, I know that I can stop tinkering to make it work 😄
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
Only had that problem with render.com and heroku free plans but that's how it's supposed to be cause their free tier goes to sleep after a while. Could it be the JWT session token that's getting thrown away after some time so you get 401 unauthorized? Strapi might have to re-auth after long periods of inactivity. My Strapi wasn't up long enough to experience these kinds of problems, tho. Still struggling with non persistent data 😄 1 min is an awful long time, though. That's almost how long the full deploy takes...
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
On your Railway Stapi?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
You're a magician. Would you mind sending me the contents of your /config/database.js and plugins.js? Without any hardcoded secrets ofc 😄
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
Thanks! My database.js looks pretty much like yours but my plugins.js looks like this:
module.exports = ({ env }) => ({
'users-permissions': {
config: {
jwtSecret: env('JWT_SECRET'),
},
},
upload: {
config: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
actionOptions: {
upload: {},
delete: {},
},
},
},
});
module.exports = ({ env }) => ({
'users-permissions': {
config: {
jwtSecret: env('JWT_SECRET'),
},
},
upload: {
config: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
actionOptions: {
upload: {},
delete: {},
},
},
},
});
Are you not using any media hosting service? maybe you could try this part:
'users-permissions': {
config: {
jwtSecret: env('JWT_SECRET'),
},
},
'users-permissions': {
config: {
jwtSecret: env('JWT_SECRET'),
},
},
who knows, maybe it fixes your 401 error. make sure to add a JWT_SECRET env in your railway variables
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
Got it. I'm using v4.1.9 right now (in dev mode) @thanneman My db persists! Thx a lot for your help, brother. Not sure if it's because of the env variable change or the plugin.js but it works 😄 btw, have you figured out how to backup your postgres db on railway?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
thank you wyzlle!
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
erztemplerobba
erztemplerobba•3y ago
That's unfortunate:/ I will let you know if I run into a problem like this!
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server