Skip to content

feat: add state migration to remove ServiceUserRole resources#357

Merged
rshoemaker merged 2 commits intomainfrom
feat/PLAT-555/state-migration-service-user-role
Apr 21, 2026
Merged

feat: add state migration to remove ServiceUserRole resources#357
rshoemaker merged 2 commits intomainfrom
feat/PLAT-555/state-migration-service-user-role

Conversation

@rshoemaker
Copy link
Copy Markdown
Contributor

Summary

  • Add state migration (v1.1.0) to remove swarm.service_user_role resources from existing deployments
  • Deletes all swarm.service_user_role entries from etcd state regardless of service type
  • Scrubs swarm.service_user_role references from all other resources' dependency lists
  • Bumps state version from 1.0.0 to 1.1.0

Context

Now that MCP (#338), RAG (#351), and PostgREST (#352) all use connect_as, the auto-created svc_*_ro/svc_*_rw service accounts are no longer needed. This migration cleans up stale state from existing v0.7.0 deployments.

Note: orphaned Postgres roles (svc_*_ro/svc_*_rw) are not dropped from the database — they remain as harmless orphans. Dropping them would require SQL execution during a workflow, which is out of scope for a state migration.

Test plan

  • TestVersion_1_1_0/removes_service_user_role_resources — MCP RO+RW removed, deps scrubbed
  • TestVersion_1_1_0/removes_service_user_role_resources_across_all_service_types — MCP, RAG, PostgREST roles removed in single state
  • TestVersion_1_1_0/no-op_when_no_service_user_role_resources_exist — safe on clean state
  • TestVersion_1_1_0/empty_state — safe on empty state
  • Full test suite passes (1061 tests

Add Version_1_1_0 migration that removes all swarm.service_user_role
resources from etcd state and scrubs dependency references from all
remaining resources. Covers MCP, RAG, and PostgREST service types.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

Added a state migration Version_1_1_0 that removes swarm.service_user_role resources and their dependencies from state, updated version tracking to reflect StateVersion_1_1_0, registered the migration in the provider, and adjusted test initialization logic.

Changes

Cohort / File(s) Summary
Test Infrastructure
server/internal/resource/migrations/1_0_0_test.go, server/internal/resource/migrations/1_1_0_test.go
Modified 1_0_0_test.go to explicitly initialize state version and resource map. Added comprehensive test suite 1_1_0_test.go validating migration behavior including resource deletion, dependency cleanup, and no-op scenarios.
Migration Implementation
server/internal/resource/migrations/1_1_0.go
New migration that targets swarm.service_user_role resources, deletes all matching resources, and removes references from dependency lists across remaining resources.
Version and Registration
server/internal/resource/migrations/provide.go, server/internal/resource/state.go
Added StateVersion_1_1_0 constant and updated CurrentVersion to reference the new version. Registered Version_1_1_0 migration in the state migrations provider.

Poem

🐰 A rabbit hops through migration gates,
Sweeping roles to cleaner states,
Dependencies removed with care,
Version bumps through the air! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly summarizes the main change: adding a state migration to remove ServiceUserRole resources.
Description check ✅ Passed The description provides a comprehensive summary, clear context, and test plan. It covers the primary change (state migration v1.1.0), explains the rationale, lists key testing, and notes database cleanup limitations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/PLAT-555/state-migration-service-user-role

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 20, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · 0 duplication

Metric Results
Complexity 6
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copy link
Copy Markdown
Member

@jason-lynch jason-lynch left a comment

Choose a reason for hiding this comment

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

Nice! This looks good to me. The comment is non-blocking if you're in a hurry. We can fix it on the next update.

@@ -1,4 +1,4 @@
{
"version": "1.0.0",
"version": "1.1.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having these change on every update is going to be a nuisance. We should probably switch 1_0_0_test.go to not use NewState:

diff --git a/server/internal/resource/migrations/1_0_0_test.go b/server/internal/resource/migrations/1_0_0_test.go
index 703880a2..fb74a858 100644
--- a/server/internal/resource/migrations/1_0_0_test.go
+++ b/server/internal/resource/migrations/1_0_0_test.go
@@ -139,7 +139,10 @@ func TestVersion_1_0_0(t *testing.T) {
 		},
 	} {
 		t.Run(tc.name, func(t *testing.T) {
-			state := resource.NewState()
+			state := &resource.State{
+				Version:   resource.StateVersion_1_0_0,
+				Resources: map[resource.Type]map[string]*resource.ResourceData{},
+			}
 			state.Add(tc.in...)
 
 			migration := &migrations.Version_1_0_0{}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Avoid golden file churn by constructing state with an explicit version
instead of NewState(), which picks up CurrentVersion.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/internal/resource/migrations/1_1_0.go`:
- Around line 25-35: The migration currently filters out serviceUserRoleType
from each ResourceData's Dependencies but misses TypeDependencies; update the
same loop over state.Resources (the block handling ResourceData) to also remove
entries equal to serviceUserRoleType from each data.TypeDependencies slice
(e.g., build a filtered slice like you do for data.Dependencies and assign back
to data.TypeDependencies). Ensure you reference ResourceData.TypeDependencies
and the serviceUserRoleType constant so persisted TypeDependencies entries like
"swarm.service_user_role" are scrubbed as well.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e593b052-25cb-4d9f-9160-a8d7c744a270

📥 Commits

Reviewing files that changed from the base of the PR and between a7e1e07 and 08f887f.

📒 Files selected for processing (5)
  • server/internal/resource/migrations/1_0_0_test.go
  • server/internal/resource/migrations/1_1_0.go
  • server/internal/resource/migrations/1_1_0_test.go
  • server/internal/resource/migrations/provide.go
  • server/internal/resource/state.go

Comment thread server/internal/resource/migrations/1_1_0.go
@rshoemaker rshoemaker merged commit a682f3e into main Apr 21, 2026
3 checks passed
@rshoemaker rshoemaker mentioned this pull request Apr 21, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants