A
A
ADA M2018-12-05 21:59:50
symfony
ADA M, 2018-12-05 21:59:50

Multi-tenant architecture on Symfony 4?

In general, I searched the entire Internet, but did not find an answer. I want to consult with you.
The situation is this, you need to set up a project from scratch on Symfony 4 so that it supports multi-tenant architecture, i.e. one application (code) -> many databases with the same schema.
For example: there are subsites client1.site.com, client2.site.com, etc. When opening each of this site, a connection to the main database is made, from where information on the client's database is taken, then a connection is already made directly to this client's database. Such a small SaaS project.
What I found on the Internet on this topic:
Article
Video
But it didn't help me. I was trying to override the Doctrine\DBAL\Connection class with the wrapper_class setting. As a result, I received a bunch of errors that I could not get rid of. Then he tried to delve into the innards of the doctrine, he also failed. In general, it takes a long time to describe all my attempts to set up the doctrine, console commands for updating schemas and rolling migrations, etc. Maybe someone has already done this, or is there any fresh open source project with such an architecture on the net?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ADA M, 2018-12-07
@adiletmurzaliev

In general, I was a little surprised, something happened. Here is the repository . If anyone is interested in this topic, please write your own, so to speak, code review. Maybe we can work this out together. Fixtures for tenant databases don't work there now. since version 3.0, the --fixtures option has been removed, and there is also a problem with the default connection, which for some reason does not change.
I will also add that I used the Symfony 4.2 version, where the logic of working with the .env file was changed .

N
nicandr, 2018-12-12
@nicandr

If I understood you correctly, then you need a lot of connections to different databases, for this there is Multiple Entity Managers
doc https://symfony.com/doc/current/doctrine/multiple_...
You can also specify in the console where to fill the database data:

bin/console doctrine:database:create --em='ваше_название_подключения'
and it will flood the base on this connection.
Well, or look in the helper how to specify the name for the connection there bin/console doctrine:database:create --help
. You just have to determine which connection to use by the route. This can be done, for example, in an event, or something else, depending on your logic.

L
LobsterJoe, 2018-12-07
@LobsterJoe

Here is a good video with a similar task: Symfoniacs #9: Features of building a SaaS service... .
I recommend viewing. The guys solved a similar issue by forwarding the database connection configuration through a custom DI container for each account in the system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question