How can we help you today? How can we help you today?
AlexYates
Good morning, This is a tricky unusual case that isn't handled well out of the box. The problem is ordering. 1. SQL Compare tries to add the new column, but fails because of the NOT NULL constraint. 2. Data Compare squirts in the data, but it never gets to this point because step 1 has already failed. Possible work arounds: UNLINK/RE-LINK STATIC DATA 1. Unlink static data 2. Deploy new column as NULLABLE all the way up to prod 3. INSERT static data manually all the way to prod, or relink static data to source control and then deploy all the way to prod 3. Add NOT NULL constraint, commit to source control and deploy all the way to PROD 4. Re-link static data (if not already done so) This option is probably the simplest, but it requires a multi-step deployment. If you have short release cycles and a good DevOps maturity this should not be too big an issue, but if you have long release cycles and poor release management processes this can be a pain to manage. PRE/POST DEPLOYMENT SCRIPTS SQL Source Control has recently released a new feature which, at the time of writing, is still only available via the frequent updates release channel: https://documentation.red-gate.com/soc6/common-tasks/working-with-pre-post-deployment-scripts 1. Unlink static data and add a filter to ignore the table schema 2. Add a pre-deploy script to add the column as NULL, insert appropriate data and then apply the NOT NULL constraint. Your script needs to be rerunnable, so consider adding an IF EXISTS statement at the top and using a MERGE statement to squirt in the data. 3. Deploy the change all the way to production. 4. Remove the table filter and re-link the static data. Also, remove the pre-deploy script. Once the update has been deployed everywhere you don't need it any more. This option requires less manual intervention/project management but it does rely on more complex and bleeding edge features that have not yet been released on the regular SQL Source Control release channel. / comments
Good morning,This is a tricky unusual case that isn't handled well out of the box. The problem is ordering.1. SQL Compare tries to add the new column, but fails because of the NOT NULL constraint.2...
0 votes
Fair point, i suppose my instructions for option 1 should have read: UNLINK/RE-LINK STATIC DATA 1. Unlink static data 2. Deploy new column as NULLABLE all the way up to prod ****AND TO EVERY DEV WORKSTATION**** 3. INSERT static data manually all the way to prod ****AND TO EVERY DEV WORKSTATION****, or relink static data to source control and then deploy all the way to prod ****AND TO EVERY DEV WORKSTATION**** 3. Add NOT NULL constraint, commit to source control and deploy all the way to PROD ****AND TO EVERY DEV WORKSTATION**** 4. Re-link static data (if not already done so)  In retrospect, perhaps the following is a better solution all round: PRE/POST DEPLOYMENT SCRIPTS (v2) 1. Unlink static data table 2. Add a pre deploy to:   a. Check if target table is in the before state and that it already holds data   b. If so, create a new table called OriginalTableName_Temp   c. Copy all data to new temp table   d. Truncate original table 3. Add a post-deploy to:   a. check if OriginalTableName_Temp exists   b. if so, copy all data, including new default data for new NOT NULL col into original table (by the time this script runs, the new col should exist).   c. delete OriginalTableName_Temp 4. Commit your new pre- and post-deploy script, along with your new NOT NULL column as a single commit. 5. Deploy this change to all environments, including prod and all dev workstations 6. Re-link static data * For now, you probably need to manually patch all the other dev workstations. Sorry I forgot to include dev workstations in my original answer. Forgive me, I'm a only fallible human. :-) / comments
Fair point, i suppose my instructions for option 1 should have read:UNLINK/RE-LINK STATIC DATA1. Unlink static data2. Deploy new column as NULLABLE all the way up to prod ****AND TO EVERY DEV WORKS...
0 votes
Not sure why that's not working, one for support I guess. In the meantime, reverting to the raw SQL Compare command line is my de facto quick fix where possible. / comments
Not sure why that's not working, one for support I guess.In the meantime, reverting to the raw SQL Compare command line is my de facto quick fix where possible.
0 votes