-
Notifications
You must be signed in to change notification settings - Fork 179
refactor(BA-6948): store app_config_fragments.scope_id as a nullable UUID #12984
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
jopemachine
merged 6 commits into
main
from
feat/BA-6948-app-config-fragment-scope-id-uuid
Jul 21, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70daf4b
refactor(BA-6948): store app_config_fragments.scope_id as a nullable β¦
jopemachine 7ba7fdb
fix(BA-6948): enforce the scope_id/scope_type invariant and fix fallout
jopemachine 9c62736
refactor(BA-6948): take a UUIDEqualMatchSpec in by_scope_id_equals
jopemachine 97c36a8
refactor(BA-6948): name the scope owner type AppConfigScopeIdentifier
jopemachine dd42bab
refactor(BA-6948): move AppConfigScopeIdentifier to the identifier paβ¦
jopemachine 19ed7e6
refactor(BA-6948): keep None out of AppConfigScopeIdentifier
jopemachine 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 @@ | ||
| Store `app_config_fragments.scope_id` as a nullable UUID rather than a string, with `NULL` for the ownerless public scope. |
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,10 @@ | ||
| from typing import NewType | ||
| from uuid import UUID | ||
|
|
||
| __all__ = ("AppConfigScopeIdentifier",) | ||
|
|
||
|
|
||
| # Who an app config fragment belongs to. Polymorphic across scope kinds (domain/user); the | ||
| # concrete kind is discriminated by the accompanying ``AppConfigScopeType``, and ``public`` | ||
| # has no owner at all, so its absence is spelled ``| None`` at each use. | ||
| AppConfigScopeIdentifier = NewType("AppConfigScopeIdentifier", UUID) |
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
76 changes: 76 additions & 0 deletions
76
...kend/manager/models/alembic/versions/e5b71c94d2a8_app_config_fragment_scope_id_to_uuid.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,76 @@ | ||
| """convert app_config_fragments.scope_id to a nullable UUID | ||
|
|
||
| ``scope_id`` was a ``VARCHAR`` holding a domain or user UUID, with ``''`` for | ||
| public only because the column was ``NOT NULL``. It becomes ``UUID NULL``, where | ||
| ``NULL`` is public. | ||
|
|
||
| Public rows are forced to ``NULL``; a domain or user id that is not a UUID aborts | ||
| the migration rather than being nulled, since that binding decides who can see | ||
| the fragment. | ||
|
|
||
| ``NULL``s are distinct to a unique constraint, so public rows get a partial | ||
| unique index (``UNIQUE NULLS NOT DISTINCT`` needs Postgres 15+; the test fixture | ||
| runs 13), and a check constraint keeps ``NULL`` and public in step. | ||
|
|
||
| Revision ID: e5b71c94d2a8 | ||
| Revises: 577c7a215934 | ||
| Create Date: 2026-07-21 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "e5b71c94d2a8" | ||
| down_revision = "577c7a215934" | ||
| # Part of: NEXT_RELEASE_VERSION | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
| _PUBLIC_INDEX = "uq_app_config_fragments_public_config_name" | ||
| # Bare name β the naming convention prefixes it with ck_<table>_. | ||
| _SCOPE_ID_CHECK = "scope_id_matches_scope_type" | ||
| _TABLE = "app_config_fragments" | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.execute( | ||
| sa.text(""" | ||
| ALTER TABLE app_config_fragments | ||
| ALTER COLUMN scope_id DROP NOT NULL, | ||
| ALTER COLUMN scope_id TYPE UUID | ||
| USING ( | ||
| CASE | ||
| WHEN scope_type = 'public' THEN NULL | ||
| ELSE scope_id::uuid | ||
| END | ||
| ) | ||
| """) | ||
| ) | ||
| op.create_check_constraint( | ||
| _SCOPE_ID_CHECK, | ||
| _TABLE, | ||
| "(scope_type = 'public') = (scope_id IS NULL)", | ||
| ) | ||
| op.create_index( | ||
| _PUBLIC_INDEX, | ||
| _TABLE, | ||
| ["config_name", "scope_type"], | ||
| unique=True, | ||
| postgresql_where=sa.text("scope_id IS NULL"), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index(_PUBLIC_INDEX, table_name=_TABLE) | ||
| op.drop_constraint(_SCOPE_ID_CHECK, _TABLE, type_="check") | ||
| # Public rows go back to the empty sentinel the NOT NULL column required. | ||
| op.execute( | ||
| sa.text(""" | ||
| ALTER TABLE app_config_fragments | ||
| ALTER COLUMN scope_id TYPE VARCHAR(255) | ||
| USING (COALESCE(scope_id::text, '')) | ||
| """) | ||
| ) | ||
| op.alter_column(_TABLE, "scope_id", nullable=False) |
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.
Uh oh!
There was an error while loading. Please reload this page.