Ivan Vulović
Ivan Vulović

Reputation: 2224

Doctrine migration on Symfony for updating tables in multiple Schemas

We are migrating our Software from our own and legacy PHP framework to Symfony. Our application has different Schema for every user. So beside public Schema, we have about 2.000 user Schemas. Let's say that we have a system similar to the marketplace, and every user can customize some tables inside their own Schema, but let's not focus on that.

We are currently searching for the best solutions for two problems:

  1. When a new user is registered, our Symfony should run migrations only for that newly created user Schema.
  2. When we create migration we need that that migration affects ALL existing user Schemas.

Currently, in our old system, we do these kinds of migration with a bunch of PHP logic, and I would like to avoid customizing DoctrineMigrationsBundle or have hundreds of lines of PHP code in a single migration.

So I would like to know is there any easier way to handle all user Schemas in Doctrine/Symfony, so when I run for example:

php bin/console doctrine:migrations:migrate

all our existing user Schemas are updated.


Our user Schema names are like app234234, app453453 and except those Schemas we have only default public Schema

We are using:

Upvotes: 1

Views: 900

Answers (1)

Yoann MIR
Yoann MIR

Reputation: 821

1 - For every schema you have, you can define a schema filter. Let's say you prefix user table with schema name app234234_ . To prevent migrations from removing your other tables, you can use doctrine dbal schema_filter property in your config.yml/doctrine.yml or wherever you define new users's schema

## doctrine.yml

    doctrine:
        dbal:
            connections:
                 app234234:
                       schema_filter: "/^app234234_/" ## more likely a %schema_name% parameter

According to symfony doc: This ignores the tables on the DBAL level and they will be ignored by the diff command.

Note that if you have multiple connections configured then the schema_filter configuration will need to be placed per-connection

2- Regarding your second point, i don't know if this is something you can/should handle with symfony.

Upvotes: 2

Related Questions