From 192bd99dfad967335b9022ea6e5d35542023312c Mon Sep 17 00:00:00 2001 From: Claude Code Date: Fri, 10 Oct 2025 11:33:32 +1100 Subject: [PATCH] Fix council-team foreign key constraint violation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Councils couldn't be assigned to tasks because they didn't exist in teams table - Foreign key constraint tasks_assigned_team_id_fkey required valid team record - Councils ARE teams (special subtype for project kickoffs) Solution: Create team record when forming council - Added team INSERT in storeCouncilComposition() - Use same UUID for both team.id and council.id - Team name: 'Council: {ProjectName}' - ON CONFLICT DO NOTHING for idempotency Result: Tasks can now be assigned to councils, unblocking task execution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/council/council_composer.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/council/council_composer.go b/internal/council/council_composer.go index 193a4d2..ddf2f7f 100644 --- a/internal/council/council_composer.go +++ b/internal/council/council_composer.go @@ -211,6 +211,29 @@ func (cc *CouncilComposer) formatRoleName(roleName string) string { // storeCouncilComposition stores the council composition in the database func (cc *CouncilComposer) storeCouncilComposition(ctx context.Context, composition *CouncilComposition, request *CouncilFormationRequest) error { + // First, create a team record for this council (councils ARE teams) + teamQuery := ` + INSERT INTO teams (id, name, description, status, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, $6) + ON CONFLICT (id) DO NOTHING + ` + + teamName := fmt.Sprintf("Council: %s", composition.ProjectName) + teamDescription := fmt.Sprintf("Project kickoff council for %s", composition.ProjectName) + + _, err := cc.db.Exec(ctx, teamQuery, + composition.CouncilID, // Use same ID for team and council + teamName, + teamDescription, + "forming", // Same status as council + composition.CreatedAt, + composition.CreatedAt, + ) + + if err != nil { + return fmt.Errorf("failed to create team record for council: %w", err) + } + // Store council metadata councilQuery := ` INSERT INTO councils (id, project_name, repository, project_brief, status, created_at, task_id, issue_id, external_url, metadata) @@ -227,7 +250,7 @@ func (cc *CouncilComposer) storeCouncilComposition(ctx context.Context, composit taskID = request.TaskID } - _, err := cc.db.Exec(ctx, councilQuery, + _, err = cc.db.Exec(ctx, councilQuery, composition.CouncilID, composition.ProjectName, request.Repository,