- You must use a second Visual Studio to debug the first one. The easiest way is to use the System.Diagnostics.Debugger.Launch method. By calling that method, inside your code, a second Visual Studio will open and debug the first one that is executing the migration command. The second Visual Studio will be in debug mode.
- The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration.cs file that you can edit to configure Migrations.
Recently I was working on providing a database migrations solution for a quite large.NET learning management system. It was a shame that there was nothing to automate processof updating production databases, and everything must have been done manually. We are usinga custom ORM solution, VS Database project to keep database schemas in source control andfactories to populate databases with static and some test data. Schemas are large - containhundreds of tables, views, and thousands of stored procedures which is why when I was lookingfor a database migrations solution a good maintaining of updating changes in procedures was a must.
Solution
I managed to find the only one which satisfied these needs - roundhouse.Unfortunately, there were some problems in applying roundhouse to this project but maybe a detailedmigration process is a topic for another post. There were, in short, some changes necessary to be made in rhlibrary and I didn’t like the way of creating database which was “get the initial schema and run all migrations”.I preferred to create a “fresh” database directly from the schema which would support database projectand that’s why I am using both roundhouse (to apply migrations and changes in views/stored procs/functions -and in general keeping database in specific version) and database project (to keep schema in sourcecontrol and creating database from schema).
The process of development requires creating differential scripts besides applying changesin the database project. Diff scripts do not need to store changes in stored procedures/views/functionsbecause roundhouse ensures that. So, a developer can now update the database project directly usingdesigner tool in Visual Studio and save generated update script as a new migration.To apply changes to databases he needs to use roundhouse. But manually creating a script witha specific name every few minutes is boring, and it is therefore first on the list to automate this process.
What we need is to perform a few simple steps.
- Change schema in the database project.
- Compare database project with the database on the developer server. Using schema compare tool we canignore specific object types e.g. stored procedures/views/functions and save comparison as comparison profile in scmp file.
- Generate script with changes and save it to migration folder with specific name eg. with a formatlike YYYYMMddhhmmss_MIGRATION_NAME.sql
Migration to Visual Studio 2017. I’ve developed WhatsApp Viewer with the good old Visual Studio 2008. It’s a bit dated and doesn’t support all of the new C features. Since the new Visual Studio 2017 is free (no costs) for personal usage and open-source projects, I thought it might be worth a shot.
Unfortunately, there is no way (or at least I cannot find one), to compare database project with databaseusing a command line tool where I could provide a list of types of objects to ignore.That’s why I create PowerShell script running commands inside Visual Studio.
To create migration you must have your solution with the database project opened.The running script will add a migration file to your solution (do not mess around in the editor while the script is running).
Examples:
PM> .AddMigration.ps1 –n MigrationName
For other database project in solution
Visual Studio For Mac Tutorial
PM> .AddMigration.ps1 –n MigrationName –p NotDefaultDatabaseProject
To generate only empty file for migration
Visual Studio For Mac Download
PM> .AddMigrations.ps1 –n MigrationName –of
Visual Studio For Mac Free
This solution is not ideal mainly because is slow, but it is working, and is better than a manual process.