Skip to content
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

tapdb: fix multiple issues around migration file handling #1089

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

guggero
Copy link
Member

@guggero guggero commented Aug 15, 2024

Fixes #1071.

This PR is the result after almost two days of debugging #1071.
The TL;DR is: due to a git branch cherry-pick mishap, the migration number 14 wasn't included in the v0.3.3 release version. Some users then applied the migration directly as it was in the source directory, which lead to them not having properly working auto incrementing primary keys.

The first commit in this PR adds a CI check that verifies migration numbers in the file names are continuous.

The second commit re-applies the migration 14 (somewhat modified) as migration 23.

The last commit then fixes the workaround with the primary key type replacements we used. See comment in scripts/gen_sqlc_docker.sh if you want to understand the full problem and solution.

This commit adds a check script to our CI that makes sure there are no
"holes" in the numbering of our migration version files.
The script would also detect duplicate numbers in the migration
prefixes.
This is to prevent mistakes from cherry-picking commits onto branches
that contain migration files.
@guggero guggero requested review from Roasbeef and jharveyb August 15, 2024 15:10
@coveralls
Copy link

coveralls commented Aug 15, 2024

Pull Request Test Coverage Report for Build 10406480087

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 19 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.01%) to 40.177%

Files with Coverage Reduction New Missed Lines %
commitment/tap.go 1 83.64%
tapdb/migrations.go 2 75.37%
asset/asset.go 2 81.54%
tapgarden/caretaker.go 4 68.5%
universe/interface.go 10 51.12%
Totals Coverage Status
Change from base Build 10385622104: 0.01%
Covered Lines: 23691
Relevant Lines: 58967

💛 - Coveralls

Due to a git branch cherry-pick mishap, the migration number 14 wasn't
included in a released version and therefore wasn't applied on some
systems. Because the tables in that migration file were only being used
with a recently released version (v0.4.0/v0.4.1), this wasn't noticed
for a long time.
We fix this by re-applying the same migration as number 23, slightly
modified so that it's a no-op if the tables and entries already exist on
a system.
@dstadulis dstadulis added this to the v0.4.2 milestone Aug 15, 2024
@guggero guggero requested review from ffranr and removed request for Roasbeef August 15, 2024 15:40
Our SQL scripts on disk were neither SQLite nor Postgres compatible, we
used a version suited for sqlc to generate the correct data types we
wanted, then did some type replacements in-memory when actually applying
the migration files.
This is somewhat dangerous as it will lead to situations where if a user
applies a migration file manually, they'll end up with table primary
keys that ARE NOT auto incrementing.

To fix this issue, we make sure that we always write fully SQLite
compatible SQL code and only apply fixes for the sqlc code generation
directly before generating the code.
Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 I've tested the script locally on Linux.

@ffranr
Copy link
Contributor

ffranr commented Aug 15, 2024

Another fee estimation itest here:

--- FAIL: TestTaprootAssetsDaemon/fee_estimation (16.48s)

I will re-run the job.

@guggero
Copy link
Member Author

guggero commented Aug 15, 2024

You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit

Maybe we need to enable the docker image cache, since we pull a new Postgres image every time we run the CI with docker...

Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Tested the script with a fake migration of prefix 000025, both only with up and up/down.

Also checked on the BIGINT PRIMARY KEY -> INTEGER PRIMARY KEY replacement, and that BIGSERIAL is the right Postgres type to use here.

scripts/check-migration-numbering.sh Show resolved Hide resolved
@guggero
Copy link
Member Author

guggero commented Aug 15, 2024

Going to verify the postgres itest suceeds locally before merging. I'm also going to build a litd image with this and test it against my own node.

@guggero
Copy link
Member Author

guggero commented Aug 15, 2024

Going to verify the postgres itest suceeds locally before merging. I'm also going to build a litd image with this and test it against my own node.

Applied this to my node without problems and also ran the full postgres itest locally.

@guggero guggero merged commit 2110839 into main Aug 15, 2024
16 of 17 checks passed
@guggero guggero deleted the fix-migration-14 branch August 15, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[bug]: when trying to sync proofs we get either sqllite error or empty array
5 participants