0

I understand database migrations might not be the best method to deploy this solution, so any suggestions would be greatly appreciated.

I have x identical database schemas, one per client.

I also have models for each one of these databases and am able to deploy a migration which creates a new clone. Up until this point, I had been using PHP and scripts to loop through all the schemas and update any changes to the structure. We are moving over to C# and EF6 due to Web API 2 and attribute routing.

My question is; Is there a way to:

  1. Deploy a build command which will do what update-database would do for a migration, and pass it a database name (in order to create a new clone schema of the account database?

  2. Deploy a build command which might do what update-database would do recursively through each one of the target databases?

francisco.preller
  • 6,559
  • 4
  • 28
  • 39

1 Answers1

0

"I have x identical database schemas, one per client "
and
"I also have models for each one of these databases"

Did you mean I also have models for each one of these Schemas?

Ef model entities are linked to a Schema/TableName.

entity.ToTable("tableName", "schemaName");

So if each client gets their own schema, then each model has all tables in that schema and the client gets their own model. So how do I run update-database on each Context model. I another way of looking at the issue.

So the answer lies with how you are tracking the schema per client info.

Powershell migrate.exe approach might be interest for your so that you can trigger migration on many context models.

Custom migration operations might also be interesting. Rowan is an EF developer.

EDIT: based on Auto Migration comment, this is worth a look Managing migration triggers in code

Community
  • 1
  • 1
phil soady
  • 11,043
  • 5
  • 50
  • 95
  • Thanks Phil. For clarification: I have a set of models which build a database schema which is then cloned multiple times, once per client. Connecting to the right context is not an issue I have set up a handler for that. I also discovered that I am able to use context.Database.CreateIfNotExists() to create a new database. I will have a look at the tools you linked, thanks. I have an inkling that this is the right answer, so I'll go ahead and mark it. I feel like I did not do enough research on the matter in the first place. – francisco.preller Dec 04 '13 at 04:17
  • if you are going to use Automated Migrations, then you can loop over your client database list and trigger Migrate. Ill add a link shortly – phil soady Dec 04 '13 at 04:19
  • Legendary! Thanks Phil :) – francisco.preller Dec 04 '13 at 04:22
  • Don't use EF Migrations for updating tenants.. it can get really complicated and hairy if something breaks and the error messages are useless. Better use a SQL Project and use SQL Packages. Much better visibility and deployment strategies can be used. – Piotr Kula Mar 21 '19 at 11:18