Use Strapi with existing Postgre database

System Information
  • Strapi version: 4.11.7
  • OS: Ubuntu/Mac
  • DB: Postgre
  • Node version: 18

Hey guys. We want to use Strapi with our existing Postgres db. The idea is to create a separate schema to isolate everything Strapi related. But then, we saw this warning in documentation:

“Strapi applications are not meant to be connected to a pre-existing database, not created by a Strapi application, nor connected to a Strapi v3 database. The Strapi team will not support such attempts. Attempting to connect to an unsupported database may, and most likely will, result in lost data.”

So now I have the following questions:

  • Does Strapi change data outside of the provided schema?
  • If no, is the warning above even applicable in our use case, or it is rather a blanket statement that any tables within the schema can be deleted at any point by Strapi? Can we basically ignore it?
  • What kind of permissions the Postgre DB user should have for Strapi to properly function? I see here that Postgre user must have all SCHEMA privileges and I wonder why is it needed, if Strapi works within one schema.

Bump, also interested in this.
I’d prefer to not have to run a dockerised postgres alongside an existing local instance.

Aight, I will try to answer. I have another issue but also connected to the DB, so maybe you find my findings helpful.

TLDR:
So in short, you should not have the same schema for strapi and other applications, though you can easily have multiple schemas and in the same postgres instance

Here is longer version:

  1. Strapi does change the whole schema, in fact it fully flushes the db structure but somehow keeps the data itself on any schema changes, like when you change the content-type. I may be wrong because I didn’t check the code directly. So yes it deletes all the alien tables from database. My use case was when wanted to implement my own migrations there, and the extra table to store migrations_versions kept getting removed.

  2. No, you shouldn’t ignore it, it will cost you lots of nerves and few new white hairs, if you still have them :smiley:

  3. I believe you misunderstood the statement. It requires all the privileges on that single schema, not all privileges on all schemas.

P.S. I am just another fellow developer using strapi, so I may be wrong