Creating SQL Scripts from Migrations
To create SQL scripts from Visual Studio:
· Open your model.
· From the Migrations menu, choose Run Migrations. The Migrations window is displayed.
· Check that the Method is set to Generate SQL script and that the database is correct. If you want LightSpeed to work out the starting version for the script by connecting to the database, check that the connection string is correct; if you want to specify the starting version for the SQL script yourself, check that the connection string shows Not connected. If you need to change any of these settings, choose the Change button. (See below for more info.)
· 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.)
· If you’re connected to a database, select the target version which you’d like to generate a SQL script for migrating to.
· If you’re not connected to a database, select the start and end versions for which you’d like to generate a SQL script for migrating between.
· Select Generate SQL.
LightSpeed generates the SQL script and displays it in Visual Studio. You can save this SQL script to the folder of your choice.
Choosing the Generation Settings
Before you first generate a SQL script, you need to choose the target database type; optionally, you can also choose a database instance from which LightSpeed will work out the current version. To do this:
· Choose the Change button next to the database connection information.
· LightSpeed displays the Migration Settings wizard.
· Choose Generate SQL that I can later apply to a database and click Next.
· If you’d like LightSpeed to work out the current version automatically each time you generate a script, choose I’m connected to the database from this computer. Otherwise, choose I’m not connected to the database from this computer. Click Next.
· If you chose connected operation, either select a Server Explorer connection, or choose a database type and enter a connection string.
· If you chose disconnected operation, choose a database type.
· Click Finish.
If you subsequently need to change the migration settings, choose the Change button again and re-run the wizard.