-
Notifications
You must be signed in to change notification settings - Fork 37
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.
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
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
| """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(): | ||
| op.execute( | ||
| "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_creator_user_id " | ||
| "ON tasks (creator_user_id)" | ||
| ) | ||
| op.execute( | ||
| "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_creator_service_account_id " | ||
| "ON tasks (creator_service_account_id)" | ||
| ) | ||
| # 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. | ||
| 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.
Both
ADD CONSTRAINT ... NOT VALIDandVALIDATE CONSTRAINTexecute inside the same default Alembic transaction. PostgreSQL holds transaction-level locks until the transaction commits, so theACCESS EXCLUSIVElock acquired byADD CONSTRAINT ... NOT VALIDis never released until the entireupgrade()function commits — meaning the full-table validation scan runs whileACCESS EXCLUSIVEis still held. On a largetaskstable this blocks all concurrent reads and writes for the same wall-clock duration as a plainADD CONSTRAINTwithoutNOT VALID. The CONCURRENTLY indexes are correctly placed insideautocommit_block(each statement gets its own autocommit transaction), but the constraint pair is not.To achieve the stated goal, both constraint statements need to run in separate transactions — either by wrapping them together inside their own
autocommit_block(eachop.executebecomes its own transaction in autocommit mode, soNOT VALIDcommits with a briefACCESS EXCLUSIVEandVALIDATEthen runs underSHARE UPDATE EXCLUSIVEwith concurrent writes allowed), or by splitting into two separate revisions.Prompt To Fix With AI