-
Notifications
You must be signed in to change notification settings - Fork 43
feat(AGX1-274): record task creator identity and FGAC migration safety #246
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
asherfink
wants to merge
2
commits into
main
Choose a base branch
from
asher.fink/agx1-274-task-dual-write
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.
+1,093
−164
Open
Changes from all commits
Commits
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
68 changes: 68 additions & 0 deletions
68
...base/migrations/alembic/versions/2026_05_21_1508_add_task_creator_columns_a1f73ada66c5.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,68 @@ | ||
| """add_task_creator_columns | ||
| Revision ID: a1f73ada66c5 | ||
| Revises: 6c942325c828 | ||
| Create Date: 2026-05-21 15:08:51.441535 | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "a1f73ada66c5" | ||
| down_revision: str | None = "6c942325c828" | ||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column("tasks", sa.Column("creator_user_id", sa.String(), nullable=True)) | ||
| op.add_column( | ||
| "tasks", sa.Column("creator_service_account_id", sa.String(), nullable=True) | ||
| ) | ||
| with op.get_context().autocommit_block(): | ||
| # Partial indexes — the columns are NULL for all pre-migration rows and | ||
| # remain majority-NULL for legacy traffic indefinitely. A WHERE clause | ||
| # keeps the indexes scoped to populated rows so we don't pay storage or | ||
| # write amplification for NULL entries. | ||
| op.execute( | ||
| "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_creator_user_id " | ||
| "ON tasks (creator_user_id) WHERE creator_user_id IS NOT NULL" | ||
| ) | ||
| op.execute( | ||
| "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_creator_service_account_id " | ||
| "ON tasks (creator_service_account_id) " | ||
| "WHERE creator_service_account_id IS NOT NULL" | ||
| ) | ||
| # Add the CHECK as NOT VALID so the brief ACCESS EXCLUSIVE lock doesn't have to | ||
| # wait on an existence scan, then VALIDATE under SHARE UPDATE EXCLUSIVE which | ||
| # doesn't block concurrent reads/writes. `tasks` is a high-write table; even the | ||
| # short ACCESS EXCLUSIVE held during a vanilla CHECK addition queues behind | ||
| # in-flight transactions and blocks readers until it releases. | ||
| # | ||
| # Each ALTER must commit before the next one runs — otherwise Alembic's | ||
| # default single-transaction wrapper holds the ACCESS EXCLUSIVE from | ||
| # `NOT VALID` straight through the `VALIDATE` scan, collapsing the | ||
| # two-statement split into one long blocking window. Use autocommit_block | ||
| # to release locks between statements. | ||
| with op.get_context().autocommit_block(): | ||
| op.execute( | ||
| "ALTER TABLE tasks ADD CONSTRAINT ck_tasks_at_most_one_creator " | ||
| "CHECK ((creator_user_id IS NULL) OR (creator_service_account_id IS NULL)) " | ||
| "NOT VALID" | ||
| ) | ||
| op.execute("ALTER TABLE tasks VALIDATE CONSTRAINT ck_tasks_at_most_one_creator") | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_constraint("ck_tasks_at_most_one_creator", "tasks", type_="check") | ||
| with op.get_context().autocommit_block(): | ||
| op.execute( | ||
| "DROP INDEX CONCURRENTLY IF EXISTS ix_tasks_creator_service_account_id" | ||
| ) | ||
| op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_tasks_creator_user_id") | ||
| op.drop_column("tasks", "creator_service_account_id") | ||
| op.drop_column("tasks", "creator_user_id") | ||
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.
I'm curious, do we actually need the additional creator column? Can't we use spark-authz to persist who creates (owns) the task?
If spark-authz register fails as the first step, we fail the whole request - then we don't really need any postgres db schema change, right?