Env setup for production and local development

ok, so if I use a different database for each env, then how does the database gets updated between env? You have a command similar to “php artisan migrate” or just doing the npm build will take care of updating the database?

Currently there isn’t any tooling for this other than the core_store table in the database (Content-Manager views for both list and edit) in which case you can use the CLI options to dump/restore these:

For your data, these migrations need to be done manually, also for schema changes we don’t handle this yet (See: Deleting/Updating content-type doesn't drop/migrate the database · Issue #1114 · strapi/strapi · GitHub)


To the above points, we have a database refresh coming in Q3: Database layer (v4) - Roadmap | Product Roadmap

Among the changes we want to handle:

  • Automatically clean up deleted tables (models)
  • Automatically clean up deleted columns (fields)
  • Automatically rename columns when changes are made in Strapi
  • Provide some basic tooling to migrate Users, Roles, Permissions, and Data between environments

What isn’t planned for this refresh but we want to do:

  • Migration from other CMSes (headless, decoupled, or monolithic)
  • Advanced migrations for Strapi updates
  • Automated migrations for Strapi updates

A strong point I would like to make, if you plan on having a large database (or just want to maintain your sanity) I suggest you avoid MongoDB for non-hobby projects.

  • PostgreSQL for single node speed
  • MariaDB Galera Clusters for HA/LB high load applications
  • MySQL if you are more familiar with their clustering solution.
2 Likes

what are the problems with mongoDB?

Mainly performance but there are some issues with data management and migrations. But to put it bluntly it’s a nightmare to properly maintain a production MongoDB database (bias opinion I suppose, but I prefer to give it to you all straight).

To put it another way: Strapi is a strict schema, relational, headless CMS

MongoDB is neither strict schema, nor relational (and we don’t follow their best practices regarding child documents over multiple collections, effectively we treat it as a relational DB anyway)

SQL (PG/MDB/MSQL/SQLite) are all strict schema and relational databases. Strapi was practically designed around how SQL functions even if it wasn’t the first database we suggested. There is a reason SQLite became the quickstart option :wink:


Source on MongoDB being a nightmare, I provide support, I look at any production MongoDB server and it gives me a headache. It will wake me up in the middle of the night with terrors :scream:

Sad! I like sqlite, but I wouldn’t relly on it for large projects. And from the other choices mongoDB is my favorite… :frowning_face:

You have to put them in sync somehow, on your own, Strapi does not handle this after your deployment. That’s why I said different dev / prod databases cannot be used, for me is like a nightmare to mentain such a setup, and is a non sense too.

In simpler words, development and production must be on the same server, with the delimitation of access paths.

Of course, maybe Derrick has a different solution…

Yea I deleted my post because I realized the command is called “strapi configuration:dump”
Technically this means that only the configuration is dumped, and the user cannot make changes to the configuration. If it’s only dumping the configuration then you wouldn’t need the data content from production in dev. Then these restore and dump command seems to be a viable option.

But I’m using Strapi just for the website content and to provide a way for the owner to be able to quickly make changes if they wanted to. This data is not that critical so using the same database in both env is not a big issue from my perspective.

If you use different access paths and if you add extra security to the /admin path you can use same database for both dev/prod without fear on any project…

Hey @DMehaffy I will have to do it in our private network. I really need to be able to run in development mode via PM2 and keep it on all the time in development mode within our private development network.

Do you know what is the configuration to accomplish that?
I tried the configuration below but it just didn’t work. It would show as if it was in development mode but when connected you cannot edit anything.

Ok, I got it working now. For the development section, all I needed was to change the “args”
script: ‘npm’,
args: ‘run develop’,

The short answer to both of you @pm74 and @SorinGFS is your development and production environments should be atomic, the data on those should not matter in the slightest.

Usually you would pull down some snapshot (or cleaned snapshot) of the production database, make a few changes, and build a .sql migration script if required. I was just updating a personal project from v3.0.x to v3.4.x and did the exact same thing:

1 Like