Repository navigation
fix(db): undo migration 0097 #9710
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e59b115
fix(db): undo migration 0097 with 0098
TheSentinel454 4d50899
style(db): rustfmt 0098 test assertions
TheSentinel454 088dce9
fix(db): split the 0097 unwind into check, validate and contract steps
TheSentinel454 d80c3d0
docs(chart): name the required stop before migration 0100
TheSentinel454 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| -- Undo 0097 (community artifact expand), step 1 of 3. The community-scoped | ||
| -- artifact feature that needed 0097 was reverted (#9689), and no release after | ||
| -- the revert reads or writes the columns 0097 added. 0097 stays in place | ||
| -- because databases that auto-migrated have recorded its checksum. | ||
| -- | ||
| -- Required stop: every relay pod and job must run #9689 or a later release | ||
| -- before 0100 runs. Relays built from #9650 itself read artifact_heads.scope | ||
| -- and write with ON CONFLICT on artifact_heads_scoped_identity. | ||
| -- | ||
| -- This step fails closed on a database whose artifact head key is not the | ||
| -- channel key. Only a database that ran the removed operator contract script, | ||
| -- or was bootstrapped from #9650's declared schema, has the scoped key. Such a | ||
| -- database needs the separate recovery step in #9689 first. | ||
| -- | ||
| -- Then it starts restoring NOT NULL on artifact_heads.channel_id without a | ||
| -- table scan under ACCESS EXCLUSIVE: 0099 validates this check, and 0100 sets | ||
| -- NOT NULL from it. | ||
| SET LOCAL lock_timeout = '5s'; | ||
| SET LOCAL statement_timeout = '30s'; | ||
|
|
||
| DO $$ | ||
| BEGIN | ||
| IF (SELECT array_agg(a.attname::text ORDER BY k.ordinality) | ||
| FROM pg_constraint c | ||
| CROSS JOIN LATERAL unnest(c.conkey) WITH ORDINALITY AS k(attnum, ordinality) | ||
| JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = k.attnum | ||
| WHERE c.conrelid = 'artifact_heads'::regclass AND c.contype = 'p') | ||
| IS DISTINCT FROM ARRAY['community_id', 'artifact_id'] THEN | ||
| RAISE EXCEPTION 'artifact_heads primary key is not (community_id, artifact_id); recover this database as described in #9689 before migrating'; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| ALTER TABLE artifact_heads | ||
| ADD CONSTRAINT artifact_heads_channel_id_not_null CHECK (channel_id IS NOT NULL) NOT VALID; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| -- Undo 0097, step 2 of 3. Validate separately from the write-blocking DDL: | ||
| -- VALIDATE CONSTRAINT scans artifact_heads under SHARE UPDATE EXCLUSIVE, so | ||
| -- channel artifact reads and writes continue while it runs. | ||
| SET LOCAL lock_timeout = '5s'; | ||
| SET LOCAL statement_timeout = '30s'; | ||
|
|
||
| ALTER TABLE artifact_heads VALIDATE CONSTRAINT artifact_heads_channel_id_not_null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| -- Undo 0097, step 3 of 3. Requires every relay pod and job to run #9689 or a | ||
| -- later release (see 0098). | ||
| -- | ||
| -- SET NOT NULL uses the check validated in 0099 and skips the table scan. The | ||
| -- drops are catalog-only. Each statement takes ACCESS EXCLUSIVE on its table; | ||
| -- fail the deployment rather than queue relay reads and writes behind a long | ||
| -- holder. | ||
| SET LOCAL lock_timeout = '5s'; | ||
| SET LOCAL statement_timeout = '30s'; | ||
|
|
||
| ALTER TABLE artifact_heads ALTER COLUMN channel_id SET NOT NULL; | ||
| ALTER TABLE artifact_heads DROP CONSTRAINT artifact_heads_channel_id_not_null; | ||
|
|
||
| DROP INDEX artifact_heads_live_type; | ||
| DROP INDEX artifact_heads_scoped_identity; | ||
| DROP INDEX artifact_revisions_scoped_identity; | ||
|
|
||
| ALTER TABLE artifact_heads DROP COLUMN scope; | ||
| ALTER TABLE artifact_revisions | ||
| DROP COLUMN scope, | ||
| DROP COLUMN community_event, | ||
| DROP COLUMN redacted; | ||
| ALTER TABLE communities DROP COLUMN artifact_type_policies; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Minor, non-blocking: this error, and the chart README's new upgrade note, tell the operator to recover the database "as described in #9689". #9689's Compatibility section only lists the two checks (the primary key is on
(community_id, artifact_id), noscope = 'community'rows) and says a database that fails them "needs a separate recovery step". It never describes that step, so an operator who hits this error has nothing to follow. Either write the recovery here and in the README, or drop the pointer and say plainly that this database needs manual recovery before upgrading. Only databases that ran #9650's operator contract script can hit this, so it's rare.