Skip to content

Migrations

Simon Hughes edited this page Aug 23, 2020 · 6 revisions

Converting your database to use migrations moving forward

This assumes your dba's 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 dba's that the database schema is now managed by migrations from now on.

DBA's keep control of the database schema

There is no need for migrations in this case as the dba's 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 dba's 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 dba's made will be brought in. You can then commit this change to source control and do a push.

Clone this wiki locally