Skip to content

feat(BA-5401): Ensure every deployment has a default rolling deployment policy#10497

Merged
seedspirit merged 20 commits intomainfrom
BA-5401
Mar 30, 2026
Merged

feat(BA-5401): Ensure every deployment has a default rolling deployment policy#10497
seedspirit merged 20 commits intomainfrom
BA-5401

Conversation

@jopemachine
Copy link
Copy Markdown
Member

@jopemachine jopemachine commented Mar 25, 2026

Resolves #10487 (BA-5401)

Summary

  • Add FK constraint (fk_deployment_policies_endpoint) from deployment_policies.endpointendpoints.id with ON DELETE CASCADE
  • Ensure every endpoint always gets a default rolling deployment policy on creation (both v1 and v2 code paths)
  • Add alembic migration to backfill missing default policies and clean up orphaned ones before adding the FK

Test plan

  • check-alembic-migrations CI passed
  • lint-and-typecheck CI passed
  • Verify endpoint creation always produces exactly one deployment policy row

🤖 Generated with Claude Code

@github-actions github-actions Bot added the size:L 100~500 LoC label Mar 25, 2026
@jopemachine jopemachine added this to the 26.4 milestone Mar 25, 2026
@github-actions github-actions Bot added comp:manager Related to Manager component require:db-migration Automatically set when alembic migrations are added or updated labels Mar 25, 2026
@jopemachine jopemachine force-pushed the BA-5401 branch 3 times, most recently from e5d2d80 to b3201e9 Compare March 27, 2026 07:41
@jopemachine jopemachine requested a review from a team March 27, 2026 07:51
@jopemachine jopemachine marked this pull request as ready for review March 27, 2026 07:52
Copilot AI review requested due to automatic review settings March 27, 2026 07:52
@jopemachine
Copy link
Copy Markdown
Member Author

jopemachine commented Mar 27, 2026

This PR should be merged after updating the default values following #10563.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

seedspirit
seedspirit previously approved these changes Mar 27, 2026
fregataa
fregataa previously approved these changes Mar 30, 2026
@fregataa fregataa enabled auto-merge (squash) March 30, 2026 03:45
@jopemachine jopemachine disabled auto-merge March 30, 2026 03:51
jopemachine and others added 7 commits March 30, 2026 13:33
…e migrations

- Add ON DELETE CASCADE FK from deployment_policies.endpoint → endpoints.id
  so endpoint deletion automatically cascades to its policy
- Fix model serving create_endpoint_validated() to create a default rolling
  deployment policy (was missing, would violate NOT NULL constraint)
- Merge two migration scripts into one
- Fix Mapped[UUID | None] → Mapped[UUID] for deployment_policy_id (NOT NULL)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ints

- Remove _migration_a1b2c3d4e5f6_created_policies tracking table
- Create default policies for all endpoints (including destroyed) to
  ensure deployment_policy_id NOT NULL constraint holds
- Simplify downgrade by removing policy cleanup (column drop suffices)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tion

Revision ID a1b2c3d4e5f6 was already used by
rename_scaling_group_to_resource_group migration, causing duplicate head.
Rename to 930e9f2dd502.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jopemachine and others added 13 commits March 30, 2026 13:33
…ragment

- Fix RBACElementRef import path (repositories.base.rbac.element_ref →
  data.permission.types)
- Rebase migration down_revision to 3727dd0927cf (resolve diverged heads)
- Add news fragment for towncrier

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…lassmethod

Add DeploymentPolicyCreatorSpec.build_default() to eliminate duplicated
default rolling policy creation logic across 3 call sites.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove _get_endpoint_join_condition and
_get_endpoint_deployment_policy_join_condition, replaced by FK-based
relationships.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…te pattern

Endpoint is inserted before its policy in the same transaction, so NOT
NULL on deployment_policy_id is not feasible (NOT NULL is checked at
INSERT time, unlike DEFERRABLE FK). Column stays nullable; application
code always sets it immediately after policy creation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t_policies.endpoint FK

Remove the redundant EndpointRow.deployment_policy_id reverse FK that created
a circular dependency with DeploymentPolicyRow.endpoint. The single FK from
deployment_policies.endpoint → endpoints.id with CASCADE is sufficient for
the 1:1 relationship and ensures policy cleanup on endpoint deletion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…constraint

Migration fails if deployment_policies table contains rows referencing
non-existent endpoints. Delete orphaned rows before adding the FK.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… fix mapper init

The EndpointRow.deployment_policy relationship used string-based foreign_keys
which required DeploymentPolicyRow to be in the mapper registry at init time.
Switch to primaryjoin with a lazy import function, matching the pattern used
by all other relationships in EndpointRow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…move stale merge script

- Delete merge_930e9f2dd502_0a200d0fc480_f5338adb2de1.py (no longer needed after rebase)
- Update 930e9f2dd502 down_revision to point to all current main heads
  (17b679c98b50, 6f8a4c0d2e3g, 7h4m7ygnaao1) so this single script
  both merges the diverged heads and applies the deployment policy FK migration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…available=0%

Align build_default and migration with the new IntOrPercent-based defaults.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
await execute_rbac_entity_creator(db_sess, policy_creator)
policy_spec = spec.policy
else:
policy_spec = DeploymentPolicyCreatorSpec.build_default(endpoint.id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we define a class method that creates a CreatorSpec by injecting a policy—such as with_policy—wouldn’t that allow us to hide the if branches in the creation logic that handle situations where the policy is optional? Or is it more important to make the creation of the RBACEntityCreator more explicit in the service layer?

Copy link
Copy Markdown
Member Author

@jopemachine jopemachine Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the if statement is small and sufficiently readable, I think it does not seem to introduce any meaningful difference in terms of readability.

@seedspirit seedspirit merged commit 9ce7a51 into main Mar 30, 2026
33 checks passed
@seedspirit seedspirit deleted the BA-5401 branch March 30, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component require:db-migration Automatically set when alembic migrations are added or updated size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add migration to assign default rolling deployment policy to existing deployments

4 participants