-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrations: How to have multi tenant application with same model in different schemas #4004
Comments
If you let an instance of a web site run |
@MaximBalaganskiy I've tried that, but the problem is that migrations do not honor the |
I've moved this one over to our docs repo, because we will put together documentation on how to do this. We haven't built out a full example of this yet... so it may drive specific improvements in the code base too. |
Did we get the answer to this? |
No. Maybe @rowanmiller has an update? |
Some discussion about how to do this in #4410 I'm working away at the list of docs at the moment, so I should have some proper docs on this in the next couple of weeks |
In case you landed here via search, I posted a simple working solution to this problem at dotnet/EntityFramework.Docs#96 (comment) |
I have a multi tenant application, where the same dbcontext, TenantDbContext is used for each tenant, and where each tenant uses a different schema.
I am doing this by specifying the schema name in the TenantDbContext constructor, and in
OnModelCreating
settingmodelBuilder.HasDefaultSchema(TenantSchema)
. When I use the TenantDbContext this is silently hidden by a custom DI factory for the context.The problem comes when I want to do migrations, as I only have one DbContext seen from "dnx ef dbcontexts list", namely the general one.
I was wondering if it is possible somehow to make a placeholder for the schemaname when the migration is added, which is later replaced during the individual database updates.
I was thinking along the way:
etc. The
--replace-schema
should, when applying the migration, take all objects in the migration ondbo
and do the migration on thetenant1
schema instead.This would meen that the same migration is applied multiple times to the same database which might be a problem.
Any input on how to accomplish this, or maybe something similar?
The text was updated successfully, but these errors were encountered: