Running Migrations
Running Migrations from Visual Studio
To run migrations from Visual Studio:
· Open your model.
· From the Migrations menu, choose Run Migrations. The Migrations window is displayed.
· The Migrations window shows the available migrations and the current database version. (If you see a “migrations project does not build” message, open the Errors window and fix the problems, then click Refresh to try again.)
· Check that the Method is set to Apply to connected database and that the database and connection string are correct. If not, choose Change to change your settings. (See below for more info. You will always need to do this the first time you run a given migration project.)
· Select the target version that you’d like to migrate the database to.
· Select Apply Now.
LightSpeed will figure out whether to run the Up or Down migrations depending on the current database version.
Before you first run a migration from Visual Studio, you need to choose the target database. To do this:
· Choose the Change button next to the database connection information.
· LightSpeed displays the Migration Settings wizard.
· Choose Apply migrations directly to a database and click Next.
· Either select a Server Explorer connection, or choose a database type and enter a connection string.
· Click Finish.
If you subsequently change the migration target, to run the migrations against a different database, choose the Change button again and re-run the wizard.
Running Migrations from the Command Line
To run migrations from the command line, run the lsmigrate.exe program. You can find this in the installation folder, under the Migrations subfolder. lsmigrate compiles migration source code files from the current directory. (You do not need to have a migrations project and you do not need to build the migrations yourself.)
The syntax for lsmigrate is:
lsmigrate provider_name connection_string [to_version]
· provider_name: The type of database. See the Appendices for permitted values.
· connection_string: The database connection string.
· to_version: The version to which to migrate the database. If omitted, the latest version will be selected.
LightSpeed will figure out whether to run the Up or Down migrations depending on the current database version.
Running Migrations from Your Application
To run migrations from your application, call the Migrator.Migrate method. You will normally call the overload that takes an IMigrationLoader, passing an AssemblyMigrationLoader for the DLL containing your mgirations.
Running migrations from code |
var source = new AssemblyMigrationLoader(typeof(MyMigration).Assembly); |
If you want to monitor migration progress, for example to provide an interactive display or to log SQL for diagnostic purposes, use Migrator.CreateMigrator to create a Migrator instance, then call Migrator.Execute to run the migrations. You can set the MigrationLogger property to log migrations, and handle the MigrationExecuting and MigrationExecuted events to provide interactivity.
Note that the migrations assembly has several dependencies which are not part of the normal LightSpeed redistributable.