Skip to content

Migrations

Simon Hughes edited this page Oct 12, 2022 · 3 revisions

Converting your database to use migrations moving forward

This assumes your DBAs are relinquishing control of the database schema over to using migrations.

  1. In your generator <database>.tt setting file, set Settings.GenerateSeparateFiles = true; and press save to reverse engineer the database.
  2. Enable migrations using the package management console using the command enable-migrations
  3. Add your first migration using the command Add-Migration Init -IgnoreChanges

    -IgnoreChanges Scaffolds an empty migration ignoring any pending changes detected in the current model. This can be used to create an initial, empty migration to enable Migrations for an existing database. Note: Doing this assumes that the target database schema is compatible with the current model, which is exactly what you now have.

  4. Delete the <database>.tt setting file and the EF.Reverse.POCO.v3.ttinclude file as you will no longer need them.
  5. Inform the DBAs that the database schema is now managed by migrations from now on.

DBAs keep control of the database schema

There is no need for migrations in this case as the DBAs will keep the database up to date by applying patches. You have to keep your local development database up to date by applying the same patches the DBAs applied to prod.

After you have applied the patches to your database, you need to update your entity framework DB context and models. Simply open the <database>.tt file and re-save it. The database is fully reverse engineer each time, so any changes the DBAs made will be brought in. You can then commit this change to source control and do a push.

Clone this wiki locally