Migration scripts not included in deployment scripts
dwade
Posts: 5
Context: SQL Source Control 3.0 (trial), SQL Compare 10.0 (trial), SourceGear Vault, SQL Server 2008 R2, and Windows Server 2008 R2. I am using a fresh copy of a production database that is restored on a development SQL Server (I'll refer to it as WidgetDevDB)
In order to test migration scripts (great idea by the way) I added a check constraint to an existing column that requires the first character to be a 'v'. Next I created a migration script for that checkin. In the migration script I added an UPDATE statement just before the ALTER TABLE command to make sure all of the column values began with a 'v' prior to the check constraint being applied.
After creating and checking in the migration script I made other checkings that included other schema hanges. Now off to test creating deployment scripts.
For the first test, I restored a second copy of the production database on the development SQL Server (named WidgetDevDB2). In SQL Compare I generated a deployment script using the "Latest (Head)" version of the source controled database as the Source and using WidgetDevDB2 as the Target database. When SQL Compare listed the differences, it showed that there was migration scripts on the appropriate table and I was able to right-click and view the migration script as expected. I checked all objects and then used the Deployment Wizard to generate the deployment script. And as expected the migration script was utilitized in the deployment script just as SQL Compare indicated it would be.
Well, that wasn't a real world test because in our environment I am not able to connect to the production SQL Server (it is offsite at a customer's loction). So for the second test I used SQL Compare to generate a deployment script between two different versions of the source controlled database. I selected the "Latest (Head)" version as the Source and I selected the original checkin version (9165) as the Target. I verified that SQL Compare listed all the appropriate schema changes and that all were checked. Next I launched the Deployment Wizard and it showed me the list of migration scripts (mine was listed and was checked). It also showed be the nifty little graphic that shows the deployment script would be generated by SQL Compare for 9165 -> 9167; Migration Script for 9167 -> 9168; and SQL Compare for 9168 -> 9181. Everything looked good at this point. So I clicked "Next" and then "Open Script in Editor". It popped open my new deployment script in SQL Server Management Studio but unfortunately the script that was generated included everything except UPDATE statement that I added to the migration script. It appears that the entire script (9165 -> 9181) was generated by SQL Compare and it skipped using the migration script even though every indication was that it would.
In order to test migration scripts (great idea by the way) I added a check constraint to an existing column that requires the first character to be a 'v'. Next I created a migration script for that checkin. In the migration script I added an UPDATE statement just before the ALTER TABLE command to make sure all of the column values began with a 'v' prior to the check constraint being applied.
After creating and checking in the migration script I made other checkings that included other schema hanges. Now off to test creating deployment scripts.
For the first test, I restored a second copy of the production database on the development SQL Server (named WidgetDevDB2). In SQL Compare I generated a deployment script using the "Latest (Head)" version of the source controled database as the Source and using WidgetDevDB2 as the Target database. When SQL Compare listed the differences, it showed that there was migration scripts on the appropriate table and I was able to right-click and view the migration script as expected. I checked all objects and then used the Deployment Wizard to generate the deployment script. And as expected the migration script was utilitized in the deployment script just as SQL Compare indicated it would be.
Well, that wasn't a real world test because in our environment I am not able to connect to the production SQL Server (it is offsite at a customer's loction). So for the second test I used SQL Compare to generate a deployment script between two different versions of the source controlled database. I selected the "Latest (Head)" version as the Source and I selected the original checkin version (9165) as the Target. I verified that SQL Compare listed all the appropriate schema changes and that all were checked. Next I launched the Deployment Wizard and it showed me the list of migration scripts (mine was listed and was checked). It also showed be the nifty little graphic that shows the deployment script would be generated by SQL Compare for 9165 -> 9167; Migration Script for 9167 -> 9168; and SQL Compare for 9168 -> 9181. Everything looked good at this point. So I clicked "Next" and then "Open Script in Editor". It popped open my new deployment script in SQL Server Management Studio but unfortunately the script that was generated included everything except UPDATE statement that I added to the migration script. It appears that the entire script (9165 -> 9181) was generated by SQL Compare and it skipped using the migration script even though every indication was that it would.
Comments
I've had a look into reproducing this and can't think of an obvious reason how this could happen. Unless you did forget to commit the migration script to source control, or the .migrationScript file is committed and the .sql file is missing.
Please clarify what you meant by “I’ve had a look into reproducing.†Does that mean you tested the scenario and that SQL Compare actually used the migration scripts when generating a deployment script to go from one source control version to another?
When you compare a live database, it puts the migration script location in an extended property of the database.