Open Closed

General question about multi-tenancy with separate tenant dbs #7613


User avatar
0
O_SAG created
  • ABP Framework version: v8
  • UI Type: Angular
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

Hello,

we are trying to implement an architecture with separate tenant dbs.

However, the docs in this regard are lacking. We could not find anything really useful to us that ties everything together and explains it. Multi-tenancy with separate dbs is mentioned in multiple places, but never really explained fully.

Doc pages which mention it (but only briefly or only one aspect of it):

  • https://abp.io/docs/latest/framework/data/entity-framework-core/migrations#separating-host-tenant-database-schemas
  • https://abp.io/docs/latest/modules/saas
  • https://abp.io/docs/latest/modules/tenant-management this references the saas module docs which explains nothing
  • https://abp.io/docs/latest/framework/architecture/multi-tenancy
  • https://abp.io/docs/latest/framework/fundamentals/connection-strings this references the multi-tenancy document which explains nothing for our problem

Could you please provide a general guide on multi-tenancy with separate tenant dbs? Especially in regards to the DbMigrator, which we could not get working at all.


8 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    it's easy to do

    you just need fill the database connect string when creating a tenant, the database will be created automatically

  • User Avatar
    0
    O_SAG created

    Sorry, but this does not answer my questions at all.

    I was first of all asking for a general guide, a summary or something else concerning a multi-tenant architecure with separate tenant dbs (for example in docker containers on another server than the host db). I believe we would not be the only ones working with abp who would profit from having such a guide, since the documentation is lacking in this topic.


    Secondly, it seems you are talking about a out-of-the box abp commercial solution with the saas module. We are aware of this. This was not the question, however.

    We need to know how to get to this point with our architecture. There needs to happen some setup for what you said to work with separate tenant dbs.

    Questions:

    • Do we need a 2. DbContext for all TenantDBs (with MultiTenancySide=Tenant)?
    • Does the DbMigrator support migrations and data seeding without extra modification for a multi-tenant architecure with separate tenant dbs? (assuming everything else is correctly set up)
    • How do we customize the seeding data for every tenant (like, a admin user with a certain password)?
    • If running the DbMigrator separately (with dotnet run), how does the DbMigrator find out which tenants are new and need to be setup and data seeded?
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    They already have built-in support

    Do we need a 2. DbContext for all TenantDBs (with MultiTenancySide=Tenant)?

    no, you don't.

    Does the DbMigrator support migrations and data seeding without extra modification for a multi-tenant architecure with separate tenant dbs? (assuming everything else is correctly set up)

    yes, without any change.

    How do we customize the seeding data for every tenant (like, a admin user with a certain password)?

    See https://abp.io/docs/latest/framework/infrastructure/data-seeding

    If running the DbMigrator separately (with dotnet run), how does the DbMigrator find out which tenants are new and need to be setup and data seeded?

    it will seed all tenant's data, so you have to make sure idempotence

  • User Avatar
    0
    O_SAG created

    Thank you for your answers. We have more questions:

    We want to automate the tenant creation process. Since we want our tenant dbs in docker containers, before the tenant db is created and seeded we need to create the docker container (with a script executed on the server), and only then we know what the connection string for the tenant will look like.

    As a second step, we plan to execute the DbMigrator to apply migrations and seeding data to this newly created tenant db container.

    Is there a way to pass seeding data to the DbMigrator when executing it with dotnet run? Asked another way: How does the DbMigrator get the admin credentials of a newly created tenant if it is executed separately with dotnet run?

    Or does it make more sense to inject the DbMigrator Service in the backend and execute it that way instead?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    We want to automate the tenant creation process. Since we want our tenant dbs in docker containers, before the tenant db is created and seeded we need to create the docker container (with a script executed on the server), and only then we know what the connection string for the tenant will look like.

    I don't understand; you can use the same DB container instead of create a new DB container.

    Is there a way to pass seeding data to the DbMigrator when executing it with dotnet run? Asked another way: How does the DbMigrator get the admin credentials of a newly created tenant if it is executed separately with dotnet run?

    When you create a new tenant, you need to enter the admin credentials

    As a second step, we plan to execute the DbMigrator to apply migrations and seeding data to this newly created tenant db container.

    you don't need to do it; ABP will publish a tenant-created event, and the handler will create a database.

  • User Avatar
    0
    O_SAG created

    I don't understand; you can use the same DB container instead of create a new DB container.

    Those are unfortunately our requirements: We have to be able to host every tenant db on a separate server, which means every tenant db needs to be a separate container.

    you don't need to do it; ABP will publish a tenant-created event, and the handler will create a database.

    Ok. So we could modify HandleEventAsync() of this handler to call a script on the server to create the docker container and only then apply the migration?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Those are unfortunately our requirements: We have to be able to host every tenant db on a separate server, which means every tenant db needs to be a separate container. Ok. So we could modify HandleEventAsync() of this handler to call a script on the server to create the docker container and only then apply the migration?

    You can use a DOCKER CLI NET client library to create containers https://github.com/dotnet/Docker.DotNet

  • User Avatar
    0
    O_SAG created

    Thank you. You have been very helpful.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09