-
-
Notifications
You must be signed in to change notification settings - Fork 240
Implement within_fleets filter via entity_fleet_id #4062
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
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
47 changes: 47 additions & 0 deletions
47
.../migrations/versions/2026/07_23_0822_0ebd6564f375_add_eventtargetmodel_entity_fleet_id.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,47 @@ | ||
| """Add EventTargetModel.entity_fleet_id | ||
|
|
||
| Revision ID: 0ebd6564f375 | ||
| Revises: 87d4312605e5 | ||
| Create Date: 2026-07-23 08:22:23.295309+00:00 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| import sqlalchemy_utils | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "0ebd6564f375" | ||
| down_revision = "87d4312605e5" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| with op.batch_alter_table("event_targets", schema=None) as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "entity_fleet_id", | ||
| sqlalchemy_utils.types.uuid.UUIDType(binary=False), | ||
| nullable=True, | ||
| ) | ||
| ) | ||
| batch_op.create_index( | ||
| batch_op.f("ix_event_targets_entity_fleet_id"), ["entity_fleet_id"], unique=False | ||
| ) | ||
| batch_op.create_foreign_key( | ||
| batch_op.f("fk_event_targets_entity_fleet_id_fleets"), | ||
| "fleets", | ||
| ["entity_fleet_id"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| with op.batch_alter_table("event_targets", schema=None) as batch_op: | ||
| batch_op.drop_constraint( | ||
| batch_op.f("fk_event_targets_entity_fleet_id_fleets"), type_="foreignkey" | ||
| ) | ||
| batch_op.drop_index(batch_op.f("ix_event_targets_entity_fleet_id")) | ||
| batch_op.drop_column("entity_fleet_id") |
46 changes: 46 additions & 0 deletions
46
...grations/versions/2026/07_23_0825_4d3cbb932bb2_backfill_eventtargetmodel_entity_fleet_.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,46 @@ | ||
| """Backfill EventTargetModel.entity_fleet_id | ||
|
|
||
| Revision ID: 4d3cbb932bb2 | ||
| Revises: 0ebd6564f375 | ||
| Create Date: 2026-07-23 08:25:22.615590+00:00 | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "4d3cbb932bb2" | ||
| down_revision = "0ebd6564f375" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # Events recorded before entity_fleet_id was introduced have it unset. | ||
| # The within_fleets events filter relies on entity_fleet_id, so backfill it. | ||
| # Instance targets are backfilled via the instances table, so this migration | ||
| # must run before the instance models the events reference are deleted | ||
| # (e.g. placeholder instances deleted on job termination). | ||
| # Old replicas can still record events without entity_fleet_id while | ||
| # this migration is being deployed. Such events won't be backfilled and | ||
| # won't be returned by the within_fleets events filter. | ||
| op.execute( | ||
| """ | ||
| UPDATE event_targets SET entity_fleet_id = entity_id | ||
| WHERE entity_type = 'FLEET' AND entity_fleet_id IS NULL | ||
| """ | ||
| ) | ||
| op.execute( | ||
| """ | ||
| UPDATE event_targets SET entity_fleet_id = instances.fleet_id | ||
| FROM instances | ||
| WHERE instances.id = event_targets.entity_id | ||
| AND instances.fleet_id IS NOT NULL | ||
| AND event_targets.entity_type = 'INSTANCE' | ||
| AND event_targets.entity_fleet_id IS NULL | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| pass |
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.
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.
(nit) Isn't this equivalent to
model.fleet?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.
No,
i.fleetmay raisesqlalchemy.exc.MissingGreenletif the attribute is not loaded.i.__dict__.get("fleet")would returnNone.