Branching and merging
Published 23 February 2016
When you develop without branches, SQL Source Control deploys migration scripts in the order they're committed.
When using branches, you'll need to manually specify which order the migration scripts are deployed in. This order is set in the deployment order file when you merge two branches with new migration scripts.
In this example deployment order file:
- lines 7 and 8 are in conflict with lines 10 and 11.
- lines 6, 9 and 12 are conflict-resolution markers added by Git (these vary according to your VCS and merge tools).
Example conflict
{ "About this file": "This is a Redgate SQL Source Control metadata file. It controls the order that changes are deployed in. Learn more: http://www.red-gate.com/SOC4/order-file-more-info", "Deployment order": [ {"Description":"Changes before migration script 'data only'","Type":"Compare","Id":"2016-02-14-133701 u5 auto"}, {"Description":"Migration script 'data only'","Type":"Migration","Id":"2016-02-14-133701 u6 user"}, <<<<<<< HEAD {"Description":"Changes before migration script 'Rename tblUsers to tblCustomers'","Type":"Compare","Id":"2016-02-16-141421 x1 auto"}, {"Description":"Migration script 'Rename tblUsers to tblCustomers'","Type":"Migration","Id":"2016-02-16-141421 x2 user"}, ======= {"Description":"Changes before migration script 'Make the id column NOT NULL'","Type":"Compare","Id":"2016-02-16-153040 j7 auto"}, {"Description":"Migration script 'Make the id column NOT NULL'","Type":"Migration","Id":"2016-02-16-153040 j8 user"}, >>>>>>> not-null ], "Conflict in this file?": "If there’s a conflict in this file, you probably want to keep both changes. Learn more: http://www.red-gate.com/SOC4/order-file-more-info" }
This conflict has occurred because both branches added a migration script. To complete the merge, you'll need to resolve this conflict and choose how your migrations will be deployed.
In the above example conflict, you need to choose which order to deploy the migrations in:
Deploy
Rename tblUsers to tblCustomers
followed byMake the id column NOT NULL
. This is "keep mine" followed by "keep theirs" in your merge tool.Deploy
Make the id column NOT NULL
followed byRename tblUsers to tblCustomers
. This is "keep theirs" followed by "keep mine" in your merge tool.
To configure Git to automatically merge the file in this way, set DeploymentOrder.json merge=union
in your .gitattributes file. To learn more, see gitattributes (git-scm).