r/ProgrammerHumor • • Sep 06 '26

Meme cleaningUpTheMess

Post image
16k Upvotes

474 comments sorted by

View all comments

Show parent comment

-1

u/aLokilike Sep 06 '26

Okay, so the smallest implementation required in that case is to change the ID of a single table to a UUID. That means every query which uses that ID must be updated to use the UUID if you're required to permanently change its field name in the migration. That means the minimum number of lines changed is directly tied to the number of times that field is mentioned in a query across your entire codebase. Enjoy working out how to split that up.

0

u/[deleted] Sep 06 '26

[deleted] — view deleted comment

0

u/aLokilike Sep 06 '26

I don't think splitting the individual query changes into their own PRs is a valuable use of time, personally. I do agree that doing a copy-over, double-write-single-read, then migrate is a fine strategy - I just don't think it's a strategy that removes the LOC change requirements at all. Splitting the individual query changes does, but it also completely removes the context of those changes from the actual PRs.

2

u/SuitableDragonfly Sep 06 '26 edited Sep 06 '26

Well, in this particular case, we were using an ORM, so there was not, in fact, much in the way of SQL queries to update. Also, no, that's not the smallest implementation piece. We did it in phases.

Phase 1: Update the code to pass IDs around as structs containing an int and a string, instead of just an int. The int in the struct is the same one we'd be passing normally. This can be done on a microservice-by-microservice basis, and is a pretty small change, in terms of LOC.

Phase 2: Add the UUID column to all the tables and generate UUIDs there, and add the UUID field to the ORM. Can be done on a table-by-table basis, and is like basically three LOC per table (one line to change the declaration of the table, one to generate the UUID, and one to add the UUID field to the ORM).

Phase 3: Populate the ID struct with the UUID field from the ORM. Can be done on an object-by-object basis, and is also very few LOC.

Phase 4: Switch the code over from using the int in the ID struct to using the UUID. This is the most intensive in terms of LOC, but it can also be done on an object-by-object basis, because the int IDs are still there and still function perfectly well, and other parts of the codebase can still use them and continue to be functional.

Phase 5: Switch from passing around an ID struct to passing around just the UUID. Basically just the inverse of Phase 1.

Phase 6: Delete the now unused int ID from the ORM and the SQL. Another three-line-per-table change.

I don't think any PRs on the project ever exceeded 200 LOC.

0

u/aLokilike Sep 06 '26

I don't think splitting the individual query changes into their own PRs is a valuable use of time, personally. I'm shocked anyone would, because it actually makes it more difficult to evaluate the reason for the change.

2

u/SuitableDragonfly Sep 06 '26

Yeah, since those were literally just three lines of code per table they were done microservice-by-microservice rather than table-by-table. I'm just describing the full extent to which this supposedly unsplittable task could be split. 

Also, all PRs are labeled with the ticket number, so if you don't know what the purpose of them was, you can just go look at the ticket. 

0

u/aLokilike Sep 06 '26

Ah yes, playing ring around the rosie with your platforms is way easier than just already have the context for that change because it's the same exact context for the 200 other query changes. I would anticipate you could also copy paste that entire ticket into your PR description 200x!

2

u/SuitableDragonfly Sep 06 '26

Everyone who was working on the project had all the context they needed about the project, because we'd literally all sat together is meetings about the project discussing exactly how it was going to be done, and we also had a special slack channel for discussing the project and it's status. If you're somehow not able to remember anything about the project even with all that stuff to remind you, this might not be the job for you.

0

u/aLokilike Sep 06 '26

Hey, must be nice to have big meetings over changing an ID field to a UUID. I'm glad that's a point of focus for your group.

2

u/SuitableDragonfly Sep 06 '26

It was a 15 minute meeting with four people. We didn't invite any POs, so it was very efficient, actually. 

Using incrementing numerical IDs for objects that are accessible via an API is a security hole. I guess you don't take those seriously at your company?

1

u/aLokilike Sep 06 '26

Using numerical IDs for objects that are accessible via an API isn't a security hole. Using numerical IDs for private objects that are publicly accessible via an API is a security hole. I also wouldn't rely on the UUID protecting you long-term. Nice try though!

2

u/SuitableDragonfly Sep 06 '26

Everything is accessible to some people and inaccessible to other people. That's just basic permissioning.

And no, nobody relies on only one security feature for security. In fact, using UUIDs means you don't have to entirely rely on other security features, too. The more individual things that you have to mess up before there's a security breach, the less likely a breach is to happen. 

→ More replies