Strapi on heroku resetting on deploy

I just have a quick question.
I’m using heroku with postrgres to host my strapi application and the data persists fine.
But is there any way to avoid resetting all of the data whenever I deploy a new build of strapi?
It would become very tedious to have to re make all of your data every time you want to push a new change to your strapi application.

I thought at first your strapi data you made locally would be pushed to heroku as well when deploying your app but this is not the case.

And well, you can’t change any contenttypes when the app is deployed.

You need to use a dedicated database to keep the data(it should not be hosted on the same Dino) . As you are already using Heroku, than you may take a look at this: Fully Managed Database as a Service - PostgreSQL | Heroku or any other cloud service (aws, gcloud, azure, digitalocean). Some of them offer free databases with limited resources.

1 Like

This is not the issue, I am using PostgresQL through Heroku and the data is persisting just fine for over a week, and the heroku server shuts down after some inactivity as expected.
It seems to have solved itself after setting up a new Strapi project.
Every time i deployed a new build of the strapi project all the data would be lost but the collection types would remain.
But setting up a new strapi project solved it.

Most likely was missing the NODE_ENV meaning it was trying to use SQLite instead of the PG database. Happens fairly often :wink:

2 Likes

Hi,
I have same problem witch overriding. In addition, I have set NODE_ENV.

Rest of my code.

config/env/production/database.js

const parse = require("pg-connection-string").parse;
const config = parse(process.env.DATABASE_URL);

module.exports = ({ env }) => ({
  connection: {
    client: "postgres",
    connection: {
      host: config.host,
      port: config.port,
      database: config.database,
      user: config.user,
      password: config.password,
      ssl: {
        rejectUnauthorized: false,
      },
    },
    debug: false,
  },
});

config/env/production/server.js

module.exports = ({ env }) => ({
  url: env("https://mywebsite.herokuapp.com/"),
});

Do you have any idea?

I changed config/env/production/database.js and is working

const parse = require("pg-connection-string").parse;
const config = parse(process.env.DATABASE_URL);

module.exports = ({ env }) => ({
  defaultConnection: "default",
  connections: {
    default: {
      connector: "bookshelf",
      settings: {
        client: "postgres",
        host: config.host,
        port: config.port,
        database: config.database,
        username: config.user,
        password: config.password,
        ssl: {
          rejectUnauthorized: false,
        },
      },
      options: {
        ssl: true,
      },
    },
  },
});

2 Likes

The previous answers were not working for me with Strapi V4 and Heroku so I rewrote database.js based on the latest doc and it now works!

const { parse } = require("pg-connection-string");

module.exports = ({ env }) => {
    const { host, port, database, user, password } = parse(env("DATABASE_URL"));
    
    return {
        connection: {
            client: 'postgres',
            connection: {
                host,
                port,
                database,
                user,
                password,
                ssl: { rejectUnauthorized: false },
            },
            debug: false,
        },
    }
};

Well, it’s probably worked for me too. Maybe documentation should be updated. Because in instruction for Heroku deployment is code from your previous post, that seems not working (at least for me). I’m a little bit confused. But thanks for sharing it!