Base solution for your next web application
Open Closed

db migrations for data updates with separate database per tenant #10979


User avatar
0
henryand created

Running ANZ10 Angular/Core

we are adding a new tenant to our system. we have a host database and a db for each tenant.
we are using migrations for Code First EF and SeedHelper to maintain some stock metadata.

since the tenants have different data, a migration written for one db won't necessarily be right for another.
is it possible to use migrations for tenant specific db data updates?
a) can a migration be run only for one tenant? b) how does anz support separate databases per tenant with the db snapshot?

-Rocco-


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @henryand

    a) I think this will not be possible because the web app will require the latest database scheme and if your Tenant DBs have different schemes, the web app will throw an exception. If you also host multiple web apps, then you need to manually (using dotnet ef tool) apply migrations to specific tenant dbs.

    b) I couldn't understand this question very well. Could you explain it a bit more detailed ?

    If you want to use same database scheme for all tenant dbs but use different data, maybe you need to create tenant specific Seeder classes and execute them for the correct tenant. In that case, you can use the Migrator app in the solution becuase it will update host db and all tenant dbs when it is runned.

    Thanks,

  • User Avatar
    0
    henryand created

    are there any examples or documentation for having a separate seeders per tenant?

    we do have a standard schema across all tenants, but the data is tenant specific. we need a methodology for updating the data in each tenant database when running the backend before the frontend brings up the login screen. that seems like it would be in the seedhelper. I don't want the seedhelper to run against the default host db, it needs to run against the tenant dbs. when my devs are running localhost to their 3 databases (host, tenant1, tenant2) we would want a seedhelper1 to run against tenant1 connectionstring and then run seedhelper2 against tenant2 connectionstring.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @henryand

    In the app, the seed is applied here but this is only for the HostDB.

    To implement your approach, you can get the list of tenants like this and run any Seeder class you will create here.

    But, I suggest to do this in Migrator app. If you do this in app startup of the web app, it will slow down the startup process.