Including non-code into Pull Request code reviews

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
My team uses Git (via BitBucket if it matters) and do code reviews on pull requests. The idea came up that some pull requests involve non-code items (most commonly SQL Schema or Store Procedure changes) Although the database changes themselves are tracked in a separate GIT repository, they are not part of the pull request. (They are automatically committed when a processes sees that the changes were made in the database)

We would like a process to include things like this in our pull requests, without actually cluttering up our application source code with SQL code. Our initial idea was to mention what SQL changes need to be reviewed in the comments of the pull request, but are wondering if there is a better way.

How have you guys seen non-code items like this included into the code reviews that happen for pull requests? Is there a "good" way to do it?
 

Tristram

Ars Scholae Palatinae
1,428
Subscriptor
In a previous project, we committed all DDL, init dmp, and some 'standard' test data dmp files used during deploy or testing.

We currently (different projects) have postman config files (test and dev references for onboarding consumers), README.md (and other md files) and other files as supplementary documentation (.html, .txt and .yaml for different purposes), env config files (arguably code), CI/CD .rc files (also arguably code).

We also, for purpose of library packaging, commit auto generated code. Ugh.

The trick is to make sure the 'to be reviewed' artifacts can be easily distinguished from 'review not needed' (generated files, like the .dmp db files)
 
D

Deleted member 43669

Guest
Although the database changes themselves are tracked in a separate GIT repository, they are not part of the pull request. (They are automatically committed when a processes sees that the changes were made in the database)
I'm not sure I entirely follow this bit. If these changes can be viewed at some URL when the pull request is created, then just include a link.

But something about these changes being automatically made in a different repo bugs me. Either they are committed before the PR in review is made (sounds bad? you're merging code related to a PR that has not been approved yet?), or they are not commited when the PR is created (so how would someone would be able to test the PR for reviewing?).

I'll say something controversial: a lot of pain comes from keeping things in separate repos, when those things should not be in separate repos (mostly: you want to make atomic changes...).
 

rain shadow

Ars Tribunus Angusticlavius
6,679
Subscriptor++
I'll say something controversial: a lot of pain comes from keeping things in separate repos, when those things should not be in separate repos (mostly: you want to make atomic changes...).
I'll say about 2% of my pull requests are cross-repo. They're on the same gitlab server, but there is no way to co-ordinate the changes in spite of that. It's even worse is when the different repos are owned by different people. My observation is each just commits their set of changes without really checking anything first. If it breaks they'll just tell me to fix it anyway, just like the old days before CI.

So that is something I miss about svn. You could check out a subtree or subsubtree etc so it was more reasonable to have lots of stuff in the same repo. Assuming you knew what you were going to be messing with you would check out the smallest subtree that covered all your changes and your checkins would be atomic.
 
D

Deleted member 43669

Guest
Subversion with all its warts, was an "interesting" VCS.

I don't know. I think going monorepo is hard, and there's probably a lot of struggles. I have never been able to work that way. All I know are the pains of making changes in lockstep to different repos.

Most of the advocacy for manyrepos I see is either plain wrong, or it doesn't apply at the scales I work (mostly small dev teams). There is some good valid criticism of monorepos, but it's weird that this is something that a lot of trendy people do, yet so many are so opposed to it...
 

minnmass

Ars Tribunus Militum
2,087
Subscriptor
Stored procedures are definitely code. DDL is arguably code.
100% this. For reasons, we have a separate Migrations repo where all of the DB changes go: modifying schema, modifying stored procedures, even some one-off data updates (eg.: we used to store some times in UTC and some in server-local; when we moved everything over to UTC, we ran a migration to update all of the old server-local timestamps to UTC).

The deploy process runs an app that queries the target DB (prod/stage/...) for the git hash of the last successful run then finds all of the files that were modified after that hash (on the appropriate branch - each environment has its own) and logically concatenates them into one giant transaction with just a touch of logic about making sure that sub-folders are run in the right order (eg.: schema updates before stored procedure updates). The transaction ends with updating the "last run" hash in the DB. We do still try to make everything idempotent, just in case something hiccups.

Tickets do often include multiple PRs: one for the app(s!) and one for the DB, which isn't ideal, but single-vs-multiple repos is a whole 'nother question (and it looks like multiple repos will continue to be appropriate for us, with several dev teams and a lot of work put into automating releases per-app/repo).
 

Lt_Storm

Ars Tribunus Angusticlavius
21,343
Subscriptor++
So that is something I miss about svn. You could check out a subtree or subsubtree etc so it was more reasonable to have lots of stuff in the same repo. Assuming you knew what you were going to be messing with you would check out the smallest subtree that covered all your changes and your checkins would be atomic.
Git partial clones are a thing....
 

ramases

Ars Tribunus Angusticlavius
9,016
Subscriptor++
Stored procedures are definitely code. DDL is arguably code.

This.

I'd also ask why database schema definitions are hosted in a different repository than the application(s)[0] that are consuming the schema. All the reasons given so far for it sound like bad ones to me, considering that you can just put things into different subtrees and do partial checkouts.

[0] You don't have to go full mono-repo, but if you are in a situation where the database is your API between applications (and if you have multiple applications that access the same DB schema your DB is an API) those applications ought to go into the same repo.
 
  • Like
Reactions: ShuggyCoUk

rain shadow

Ars Tribunus Angusticlavius
6,679
Subscriptor++
Git partial clones are a thing....
True, but that didn't seem to impact my various upper level coworkers decision to create literally hundreds of small projects when they switched to git. I think they were more interested in doing management things like politicizing who got to be the owners and maintainers. I'm more of a floater, so our previous setup (just two large svn repos) was a better fit for me. However the world is not about me, so...yeah.
 

Lt_Storm

Ars Tribunus Angusticlavius
21,343
Subscriptor++
True, but that didn't seem to impact my various upper level coworkers decision to create literally hundreds of small projects when they switched to git. I think they were more interested in doing management things like politicizing who got to be the owners and maintainers. I'm more of a floater, so our previous setup (just two large svn repos) was a better fit for me. However the world is not about me, so...yeah.
That kind of thing is heavily dependent on tooling. Ideally, you would have some kind of dependency management system sort of like Maven (but language independent) which keeps track of the source versions used to build each package version, and then a couple tools to check those repositories out at a particular version. Add that to a few cross directory git command that can run git in multiple directories at a time so that you can, for instance, create a commit in ten repositories simultaneously, and using a dozen or two micro-repositories is pretty easy. But, if you are missing one of those tools, then it makes things really really difficult, which really just means you should figure out how to write those tools.

Edit: Also, it's worth noting: even if you have a mono-repo, you really do still need a similar Maven-like tool to manage microservices. After all, most deployments involve multiple assemblies, which, for various reasons, could be made from multiple branches of your mono-repo. So, when something goes wrong, you still need some kind of tool to check out whatever is currently deployed in production, which implies a Maven-like tool to track the source versions for each build artifact. You might have less pain without such a tool if you have a mono-repo, but the mono-repo doesn't really solve the problem in question completely.
 
Last edited:

Lt_Storm

Ars Tribunus Angusticlavius
21,343
Subscriptor++
Why would you do this? It increases complexity a lot, and I can't really see why this would be necessary.
Quick patches, testing / prototyping various new features, profiling, third party libraries, or simply by mistake. The point is that deployments happen at the assembly level no matter what you do, and so being able to link a given deployed assembly to a given source version is a valuable asset regardless of what model you use for your source repositories. There are a wide variety of reasons to track this kind of detail in separately from your source control.
 

Lt_Storm

Ars Tribunus Angusticlavius
21,343
Subscriptor++
Just create a temp branch and merge whatever you need into it. No need to complicate things.
Except that dependency management is inherently a complicated problem. For instance, you might be building a Python library that needs to run on both Python 2 and Python 3, and so now you need to deploy it with two different sets of dependencies. There is a reason that pretty much all languages include a fairly sophisticated dependency management system like RubyGems or Pip. If you work within a single language, that system will probably work for your needs. But, once you are using a dozen different languages, it typically makes sense to have something language independent to do that kind of thing.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
I have to use multiple repos for my work (because a repo is a unit of permission in git and most modern VCS systems for many good reasons)
This sucks, and requires much tooling and pain. But for perms it is inevitable.

You don’t have to go mono repo, but you should have as few as you are needed for separating things that either utterly unrelated, or required due to permissions (note you can solve ownership at a sub repo level with things like CODEOWNERS if you really need to).

If you’re trying to approach things from an “Amazon like”[1] perspective, an app owns its database/backing store and no one else touches it directly, then putting the db code in a different repo is a complete anti pattern.

Therefore I think the most valuable architectural change you could make here is not to make multi repo work better, it’s to make your “unit of work” for making a change only encompass one repo

1. I think Amazon was smart to approach backing stores this way, and it applies at scales way smaller than Amazon is or was at the time they did this.
 
D

Deleted member 43669

Guest
I have to use multiple repos for my work (because a repo is a unit of permission in git and most modern VCS systems for many good reasons)
This sucks, and requires much tooling and pain. But for perms it is inevitable.

You don’t have to go mono repo, but you should have as few as you are needed for separating things that either utterly unrelated, or required due to permissions (note you can solve ownership at a sub repo level with things like CODEOWNERS if you really need to).
I am not entirely familiar with CODEOWNERS, but I believe the only "significant" limitation it has is that it only can prevent modification of code, not viewing?

And I think the "viewing" problem is better solved through non-technical means.
 
D

Deleted member 43669

Guest
I mean, my "starting" criteria is that if you want to make atomic changes to two files, those two files belong in the same repo. In this case, I think that limiting what can someone see is an organizational problem (everyone should view all files, but some "dumb" thing is making people think otherwise) rather than something that needs to be enforced. (In that case, I assume Copybara or whatever the other Google tool for transforming git repos would be the best option.)

In any case, I also think that in most organizations, the only thing you should do is really enforce in software that people cannot rewrite history in branches which are deployed to production. That means that people can't do "malicious" stuff. I believe that "incorrect" stuff (like merging stuff without following agreements) should be more of a "social agreement" than a software-enforced rule. If you really need that automatic enforcement... well, I think the "trust level" in your organization is something that needs to be addressed.

(Excluding regulations you must really follow, and environments where there might be huge incentives to do damaging stuff that can slip undetected for too long before it can be reverted well.)
 
  • Like
Reactions: Vince-RA

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
everyone should view all files, but some "dumb" thing is making people think otherwise
I would love this to not be the case, but when some things are worth millions of dollars and easy to walk away with then it gets very tricky very fast.

Just because you’re paranoid doesn’t mean people aren’t out to get you
 
D

Deleted member 43669

Guest
Actually, my preferred configuration prevents direct pushes to branches (and no history rewriting, etc., no exceptions), so it requires PRs- but no approvals (but people should agree to get approvals in most cases, and have a clear picture of what doesn't need an approval- typo fixes, emergencies, etc.). It's hard enough to make mistakes with that configuration for my tastes (and scenarios). Your mileage will vary, of course.

As I mentioned, there are likely cases where not everyone should be allowed to see everything, yes. But a good chunk of those are wrong- while another chunk is right. If for your eyes only must be enforced, I would consider using Copybara or something similar to do that, while allowing a bigger monorepo behind the scenes.
 
  • Like
Reactions: Vince-RA

rain shadow

Ars Tribunus Angusticlavius
6,679
Subscriptor++
A practice I'd like to see more of is having branches do the same CI/CD/automated QA as master, excepting the actual install to production at the end. You should already know whether something is going to pass before a merge.

(Don't tell my employer, but I've gone so far as to edit the CI scripts in-branch to do a full build, then reverted that before doing a pull request.)

How does branch CI/CD work at your places of employment?
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
If for your eyes only must be enforced, I would consider using Copybara or something similar to do that, while allowing a bigger monorepo behind the scenes.

I took a quick look at https://github.com/google/copybara. It wouldn’t cut it for our use case. We instead have plugins that pretend multi repo is a mono repo to the CI system and tooling to fake the things you can’t see from the artefacts of the relevant builds. This is a lot of work but strictly more powerful than copybara.

Like i said it has to really be a thing you can put a very high notional value against to do, but once you have the tooling it can work.
 
D

Deleted member 43669

Guest
I suppose the people who don't do full testing of branches is due to lack of resources. I know in a gig we had some tests that only ran as nightly builds because (at the time) they were very costly. Optimization of automated QA is a topic which doesn't get as much attention as it deserves.

We instead have plugins that pretend multi repo is a mono repo to the CI system and tooling to fake the things you can’t see from the artefacts of the relevant builds. This is a lot of work but strictly more powerful than copybara.

Like i said it has to really be a thing you can put a very high notional value against to do, but once you have the tooling it can work.
Yeah, that sounds a bit like Google's "repo" tool. I haven't dabbled with it much. As I always say, I like monorepos but people have strongly opposed them everywhere I've been- and in some cases they would have been a bad idea- so I'm only used to working in manyrepos with not-sophisticated tooling to deal with them. At the scale of the places I work with, where I think monorepos wouldn't have most of their problems, this means I've suffered in vain :D
 
  • Like
Reactions: rain shadow

Vince-RA

Ars Praefectus
5,519
Subscriptor++
A practice I'd like to see more of is having branches do the same CI/CD/automated QA as master, excepting the actual install to production at the end. You should already know whether something is going to pass before a merge.
AND you should not even be allowed to merge without tests passing and builds succeeding! :judge:

I've worked on projects in the past where full integration testing was a massive endeavor (time- and compute-wise) and only done as a prerequisite to actual UAT/production deployment. I think carving something like this out of the branch CI/CD can be an acceptable pragmatic decision to make.

Honestly this is all a pretty hard needle to thread properly. You really need a balance of:
  • Fast builds
  • Fast test cycle
  • Meaningful tests
The more commits/committers you have in a repo the more critical a low cycle time becomes.

And back to the topic at hand - I prefer EVERYTHING be included in the same repo (and thus PRs): application code, infrastructure code, database code, and configuration. Good tooling can help make this more manageable but is not magic. Even in highly regulated environments (for example, where the same person can't write the code and deploy it into production) this strategy can often be used if appropriate controls and auditing are put in place.
 
  • Like
Reactions: rain shadow