Skip to content

PS: Cleanup upgrade/downgrade chains #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025

Conversation

MathiasVP
Copy link
Collaborator

An upgrade script is identifies by a hash, and that hash is computed by git hash-object path-to-dbscheme (git hash-object just prefixes some constant string onto the stream before computing it's sha1 digest).

A subtle issue that I failed to realize in all my previous upgrade/downgrade scripts is that care must be taken related to windows vs. unix line-endings when computing this sha. For example git will to "normalize" line-endings depending on your OS/git settings, and if that's done to your dbscheme file after you have computed the hash you may end up with a sha that's incorrect. So when the CodeQL cli tries to match up the hash in the upgrade scripts folder with the hash of the dbscheme that was used to build an old DB the hashes won't match!

To fix this I've deleted all the old dbscheme upgrade/downgrades and remade a single upgrade/downgrade script while taking extra care to match the line endings. So now we have a single upgrade script which:

  • does all the necessary upgrades from the "initial dbscheme" (i.e., from before we started working on PowerShell QL libraries) to the current dbscheme, and
  • converts Windows line-endings to Unix line-endings.

Similarly, we have a single downgrade script which:

  • does all the necessary downgrades from the current dbscheme to the "initial dbscheme", and
  • converts Unix line-endings to Windows line-endings.

So now the upgrade/downgrade scripts can just be Unix-style line endings going forward like the other CodeQL supported languages uses.

We can delete those old dbscheme upgrade/downgrade scripts because the PowerShell extractor was never published after I made those incorrect upgrade/downgrade scripts 😂.

Additionally, I've also added an entry in .gitattributes to ensure that git doesn't normalize the line endings in a way that messes things up the first time git touches the files.

While here, I also noticed that we were missing an operation in the PowerShell build script that copied over the downgrade scripts when building the PowerShell extractor. I've fixed this in 2bf076d.

I've tested that this works on a random old DB I had from a previous failing PowerShell campaign run. And for that one it now works perfectly 🥳

MathiasVP added 3 commits May 13, 2025 18:46
… current dbscheme, and add a single downgrade script that downgrades the current dbscheme to the old dbscheme. IMPORTANT: the .gitattributes ensure that we keep CLRF (i.e., windows) line-endings on the old dbscheme scripts so that they match what is produced by the extractor.
@dilanbhalla dilanbhalla merged commit 2ef6dd9 into main May 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants