-
Notifications
You must be signed in to change notification settings - Fork 174
fix(BA-6025): add ON DELETE RESTRICT FK on images.registry_id #11643
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
Open
fregataa
wants to merge
4
commits into
main
Choose a base branch
from
fix/BA-6025-images-registry-fk-restrict
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b6248a
fix(BA-6025): add ON DELETE RESTRICT FK on images.registry_id
fregataa 522dee5
test(BA-6025): include ContainerRegistryRow in with_tables for image-…
fregataa c903dec
test(BA-6025): create container_registry row in deployment test_image…
fregataa 5cbaecd
changelog: add news fragment for PR #11643
fregataa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Enforce `ON DELETE RESTRICT` on `images.registry_id` so deleting a container registry that still has images is blocked at the database level instead of leaving dangling references that surfaced later as a misleading "Image not found in database" error. |
55 changes: 55 additions & 0 deletions
55
...ackend/manager/models/alembic/versions/045b0e0e4384_add_fk_from_images_registry_id_to_.py
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,55 @@ | ||
| """add FK to images.registry_id (RESTRICT) | ||
| Adds a foreign key from ``images.registry_id`` to ``container_registries.id`` | ||
| with ``ON DELETE RESTRICT``. | ||
| Rationale: the column previously carried a UUID with no DB-level FK, so | ||
| deleting a container registry left dangling references on the images | ||
| table. The sokovan scheduler would later surface this as a misleading | ||
| "Image not found in database" error during session launch. RESTRICT | ||
| prevents the registry deletion at the database level, forcing callers | ||
| to ``clear_images`` (soft-delete) or ``admin_purge`` the dependent rows | ||
| first. CASCADE was rejected because it would also hard-delete image | ||
| rows referenced by historical kernels / deployment_revisions via | ||
| SET NULL, erasing audit traceability. | ||
| Pre-existing dangling rows (image rows whose ``registry_id`` no longer | ||
| resolves) are hard-deleted before the constraint is created. The column | ||
| remains ``NOT NULL``, so a SET NULL backfill is not an option, and a | ||
| sentinel re-assignment would mask the original deletion intent. | ||
| Revision ID: 045b0e0e4384 | ||
| Revises: ba42cb865efe | ||
| Create Date: 2026-05-17 | ||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "045b0e0e4384" | ||
| down_revision = "ba42cb865efe" | ||
| # Part of: 26.5.0 | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
| _FK_NAME = "fk_images_registry_id_container_registries" | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.execute( | ||
| sa.text("DELETE FROM images WHERE registry_id NOT IN (SELECT id FROM container_registries)") | ||
| ) | ||
| op.create_foreign_key( | ||
| _FK_NAME, | ||
| source_table="images", | ||
| referent_table="container_registries", | ||
| local_cols=["registry_id"], | ||
| remote_cols=["id"], | ||
| ondelete="RESTRICT", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_constraint(_FK_NAME, "images", type_="foreignkey") | ||
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
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
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
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
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
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.
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.
It is better to reflect Copilot's review