The application we are building is a multi-tenant SAAS, with each tenant on same database with different schema.
EF core (7.0.4)
Database Provider -> Postgres
Package -> Npgsql.EntityFrameworkCore.PostgreSQL (7.0.3)
Database schema pattern -> Code First
The objective is to create a single version of migration scripts that can be executed against every tenant. We don't want to create separate migration scripts for each tenant.
Issue/Concern: It seems the created migration script always contains a schema name.
migrationBuilder.EnsureSchema(name: "sysdba");
migrationBuilder.CreateTable(name: "Test",schema: "sysdba",
We want to have a placeholder for schema name during creation and able to inject a schema name during execution/update of migration scripts.
I looked for similar queries, like Multi-Tenant With Code First EF6. It provides a solution, but its an old thread and would be looking for a solution that part of ef core itself.
Another reference https://learn.microsoft.com/en-us/ef/core/miscellaneous/multitenancy#multiple-schemas mentions that this is not recommended by Microsoft.
Tried to override IDesignTimeDbContextFactory to create a dbcontext aware of schema, but it will also create multiple migration scripts for each tenant. Will have issues when managing updates to database if we maintain separate migrations per tenant