December 19, 2022 at 1:24 pm
Hi all
Firstly, full disclosure, we're only getting started with this so late to the party (and complete novices).
Tools we're using (not just for DevOps):-
SQL Clone
SQL Compare
SQL Prompt
SSMS (V18)
We're just getting started with Clone and found it to be very useful.
The bit that's not so useful (probably because we're using it wrong) is branching in Azure.
Here's the steps I take along with an example at the bottom.
Create Azure repository
Clone to local folder (Folder1)
Attach Database1 to Folder1 and do initial commit/push
In Azure, create branches Branch1 and Branch2
Clone branches to local folders (keeping the folder names the same as the branches)
Create two database clones (Database1_Branch1 and Database1_Branch2)
Attach each cloned database to local folders
Do Get Latest/Commit as necessary (nothing to do at this point)
On Database1_Branch1, make a table change to Table1, commit and push
On Database1_Branch2, make a table change to Table2, commit and push. This is where it goes wrong because there's a conflict in the table changes
One thing I did notice (after hunting around) is that the HTTPS address for the branches in Azure are identical to the main repository.
Is this a shortcoming in Azure, am I doing something wrong or have I just got completely the wrong idea?
As an example, I have a DummyDatabase I use for tinkering purposes (and for things like this).
The address in Azure for the main repository is:-
https://<myorg>@dev.azure.com/<myorg>/DummyDatabase/_git/DummyDatabase
To get my local copy, I use Git Bash and simply do a "git clone" command with that address
To get local copies of the branches, I use:-
git clone https://<myorg>@dev.azure.com/<myorg>/DummyDatabase/_git/DummyDatabase Database1_Branch1
or
git clone https://<myorg>@dev.azure.com/<myorg>/DummyDatabase/_git/DummyDatabase Database1_Branch2
to get them into separate folders (mostly for my own housekeeping).
Any help on this would be appreciated.
Any questions, feel free to ask.
Regards
Richard
December 19, 2022 at 1:44 pm
No.
Create a "Main" branch. You can consider that that "Version 1". Clone that into a "Release" branch. You can call that "Version 2".
When you, or someone else, needs to do some work, you create a "Richard" branch off of release. DO NOT share branches across developers. That will make you crazy every time. Another developer makes his own branch, etc. The different peoples branches can be considered "Version 3"
When you are completed, you merge the changes from the "Richard" branch into "Release". Same with the other developers. Unless you have some really poor processes for assigning work, and more than one person is working on the same thing on a regular basis, then the number of merge conflicts should be next to nothing. As the changes from the different peoples branches get merged, you ONLY deploy from the "Release" branch. It should be a rare situation where you deploy from another branch than "Release".
On a regular basis, you merge "Release" into "Main".
When the next set of changes need to be made, you make another branch called "Richard2" from "Release". Repeat the process. The "Release" branch contains the code that is currently in production, or is about to be deployed into production.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
December 19, 2022 at 1:52 pm
Hi @michael-2 Apart from the Release branch, that's what we're trying to do.
The problem is, we might need to make multiple changes to the same database under different projects.
E.g. I might have two projects on the go at once that both require changes to DummyDatabase so I'd create two branches or there could conceivably be two developers working on two different projects, both of which require changes to DummyDatabase
As soon as I commit/push the changes from branch1, I can't commit/push from branch2 as there are now conflicts (even though I've changed 2 completely different objects).
This is the bit that's throwing me (as well as the URL for the branches matching the main repository).
Regards
Richard
December 19, 2022 at 2:13 pm
I'm confused. Unless multiple people where making changes to the same object, or related objects, you should not get a merge conflict error.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
December 19, 2022 at 2:45 pm
It's entirely possible that I could have two projects affecting the same database (not just the same object). The would have two different timeframes but could be worked on simultaneously as they are for different objects.
The issue I'm getting is when I try to alter two tables (for example) on two separate branches (and two clones).
Once I've altered Table1 (for example) and done a commit/push, I can't then alter Table2 and do a commit/push as I get the conflict.
It's also possible to have two developers making changes to the same database (hence the clones) who would end up with the same problem.
I haven't tried it with "proper" databases (as opposed to clones) but I don't think that would make any difference.
I think the issue stems from the fact that the URL for the branches are identical (as far as I can see) and something is getting confused.
December 19, 2022 at 3:17 pm
This sounds more like an issue with the various software or configuration.
There would be no reason to prevent a merge from different branches on the same database, but different objects. I would think that it would be normal to have person A working on table X, and person B working on table Y.
I'm stumped.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
December 20, 2022 at 5:51 am
That makes two of us.
Forgot to mention, I'm using SQL Source Control (from RedGate) to do the Commit/Push) so I'll have a look through the settings and see if I've missed anything.
December 20, 2022 at 1:09 pm
So, you should be able to merge changes from two different tables, just fine. Nothing SQL Source Control does this. It's all in the source control system. The issue is if there are different changes made the same objects, then you're going to run into trouble. A common one, and has been for a very long time, is relying on automatic naming of objects. Then you'll see two databases, nominally identical, showing all sorts of conflicts because the primary key (or whatever) is named differently even though they're the same.
Branching and merging requires quite a bit of discipline at the best of times. Even more so when it comes to databases. The whole issue is, while you can branch code, databases, by their nature, don't branch. You can only have two copies for two branches. Then, your coding practices have to be such that you can merge back together because the two teams are working on two different objects. Otherwise, FIFO is going to be winner here and then a bunch of other pain gets involved.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
December 21, 2022 at 6:06 am
Hi @Grant
Thanks for that and that seems fine.
In this case, I'm making changes to two different objects when I encountered the conflicts.
Richard
December 21, 2022 at 12:30 pm
Are you letting constraint names or similar be automatically generated? That could lead to the issue. Stuff like that is likely the cause.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
December 21, 2022 at 12:45 pm
Hi Grant
As far as I know, there are no constraints on any table in this database.
I'll create a new database (so it's just a shell) and retry.
Regards
Richard
December 21, 2022 at 1:06 pm
Steps taken so far:-
Create brand new database RG_Test
Create new project in Azure (also called RG_Test)
Use Git Bash to clone project repository (Azure) to local repository
Connect RG_Test to local repository and commit/push changes under initial commit
Create two branches in Azure (Branch1 and Branch2)
Create two clones of RG_Test (called cl_RG_Test_Branch1 and cl_RG_Test_Branch2)
Use Git Bash to clone branch repositories (Azure) to local repositories (using new folder names RG_Test_Branch1 and RG_Test_Branch2). For this I used the syntax "git clone https://<OrgName>@dev.azure.com/<OrgName>/RG_Test/_git/RG_Test RG_Test_Branch2"
Attach clones to respective local repositories
In cl_RG_Test_Branch1, create table1 with column1 DATETIME)
In cl_RG_Test_Branch2, create table2 with column2 BIGINT)
Commit/Push changes from cl_RG_Test_Branch1 to Azure (all works as expected)
Commit changes from cl_RG_Test_Branch2 to local repository
When I try to do the Push, I get the following error:-
Unable to push. This may be because a reference that you are trying to update on the remote contains commits that are not present locally. Try to pull from the Get Latest tab and try again.
To https://dev.azure.com/<OrgName>/RG_Test/_git/RG_Test
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://dev.azure.com/<OrgName>/RG_Test/_git/RG_Test'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I think I'm getting ahead of myself and I need to do a refresh of some description and then redo my changes on cl_RG_Test_Branch2 but, if I do a PULL, won't that overwrite my changes?
Regards
Richard
December 21, 2022 at 1:25 pm
I am bringing in some help on this one. I may be horribly wrong in what I've been saying.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
December 21, 2022 at 1:46 pm
Thanks Grant
Just as an update.....
On a whim (and because it's a database I don't care about) I did a PULL/APPLY CHANGES request in SSMS to get the changes from Branch1 into Branch2.
I didn't (as I expected) wipe out my changes to Branch2 but it did allow me to then PUSH my changes up to Azure.
The only thing I've got to do now (apart from lots more testing) is to figure out how to stop it automatically applying the changes to the main branch.
Wish me luck (I may be back)
Regards
Richard
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply