We have some existing applications where we are retrofitting entity framework as an ORM.
The aim is to use code first (from existing database) with migrations, but we are having problems getting migrations to fit to the existing database scenario:
- a test/prod database which already has all tables that matches the code. No migrationsTable though.
- A localhost development database which is empty.
The goals
- a developer can run a unit test project and the database will create itself along with all tables.
- it will be possible to generate a script from migrations that will take care of generating the __migrationsHistory table and all changes onwards needed for production.
Using package-manager it is possible to solve 1 with default migration initializer. Or solve 2 with the ignore-changes switch. But no success having both to work simultaneously.
I have tried:
- Add-migration InitialCreate; add-migration MigrationHistoryTable -ignore-changes;
The idea being that developers could do: update-database
When going into test / prod a script could be generated using update-database -Script -SourceMigration: $InitialDatabase. The problem is that the script will find the initialCreate migration to missing and attempt to re-add existing tables. A source migration from MigrationHistoryTable doesn't add the Migration history table if missing (which it is in test/prod). - Another attempt was to have two migration projects, one for unit test and the other database. This became a bit messy though.
Any other suggestion?
Thx Kim