Moving a column from one table to another
MGibson
Posts: 15 Bronze 2
I have the latest SQL Source control and DML components and am trying to move a column with data from one table to another. I have tried doing this using the following steps.
1. Add new column to table 1 and commit change.
2. Create a migration script to populate the new column in table1 from the old column in table2.
3. Drop the old column from table2.
I can check this all in fine.
The DLM automation process is fine after step 1, but fails on step 2.
Running DLM automation after committing the migration script gives
Error: Comparison of 'Scripts.state' and 'vsdevbuildsvr1.VETSPACE_SNAPSHOT_INTEGRATION' failed: A duplicate definition
was found for the trigger '[dbo].[tr_Category_B_D]'. Ensure that case sensitivity options are set correctly and all
object creation scripts are valid.If the problem persists, contact Redgate support.
So currently I cannot populate the data and drop the old column.
I will have to populate the data in a post script, and drop the old column in a later iteration.
Does anyone else have issues moving columns with DLM automation?
Thanks
1. Add new column to table 1 and commit change.
2. Create a migration script to populate the new column in table1 from the old column in table2.
3. Drop the old column from table2.
I can check this all in fine.
The DLM automation process is fine after step 1, but fails on step 2.
Running DLM automation after committing the migration script gives
Error: Comparison of 'Scripts.state' and 'vsdevbuildsvr1.VETSPACE_SNAPSHOT_INTEGRATION' failed: A duplicate definition
was found for the trigger '[dbo].[tr_Category_B_D]'. Ensure that case sensitivity options are set correctly and all
object creation scripts are valid.If the problem persists, contact Redgate support.
So currently I cannot populate the data and drop the old column.
I will have to populate the data in a post script, and drop the old column in a later iteration.
Does anyone else have issues moving columns with DLM automation?
Thanks
Tagged:
Comments
So there's not a general issue with moving columns using migration scripts, but there is a problem with using migration scripts to make changes to tables with triggers attached.
Redgate Software
Do you know when a fix will be issued for this?
We are currently running 5.8.3.6733 of SQL Source Control.
Just to confirm, the Category table that is producing the error has a before and after trigger.
The migration script does not attempt to change data in the Category table.
I'm afraid I can't give you any timelines on when the trigger dependency bug will be fixed.
Redgate Software
Redgate Software
If we cannot run the migration script, we are going to have to populate the new column in a post deployment script, and then remove the old column in a later iteration, which is far from ideal and leads to us deploying code that is sub-optimal to work around a defect in your software.
If the workaround works as I have described, can I strongly suggest this bug is treated as high priority, This one defect has caused us huge problem in our development process, and was first raised to you months ago. We have been going back and forward trying to work out what the problem was, and trying different solutions.
The workaround did not work. I added the sql as you said in out pre-deployment and got the same error as before about the duplicate trigger.
Please advise.
Sorry, I wasn't clear enough. The migration that you need to mark as already deployed is the automatic schema change part that comes before the migration script you want to run - it's incorrectly trying to add a trigger that has already been deployed to your target database. I've been more specific with the names and ids of the relevant migration in the support ticket response to your colleague - I'll get you added to that ticket.
Mike
Redgate Software
Therefore we currently cannot create any new migration scripts without this defect being fixed.
What that means for us in the case of moving a non-nullable column to a different table as an example;
1. We add the new column as nullable and check this in.
2. We populate the data in the new column from the old one in a post deployment script which runs after all the other processes have completed in our CI.
3. We raise a JIRA for the next release cycle to remove the old column and make the new column non-nullable, which will involve another post deployment fix to ensure there are no null values.
This means we are shipping a half way change to production and this will become very complex for major database refactoring work, which we are about to embark on for some parts of our system.
I cannot emphasis enough how important this defect fix is to us.
If possible I would like to discuss this with someone at Redgate over the phone.
Thanks
You can request a phone call through the support ticket, which I think you've now been added to.
We have investigated further on that support ticket, and narrowed the issue down to an interaction between having the trigger created and deployed in an earlier commit (i.e. not a migrations commit) and having the Ignore Fill Factor and Ignore Filegroups options enabled. If you can work without those options enabled, then the migrations pre-state should work correctly.
This is quite an environment-specific issue, so it would be easier to continue the support discussion via the support ticket where we can be more specific about the details. Hopefully you have been sent a link to that ticket, but if not please let me know.
Thanks,
Mike
Redgate Software