Fix council-team foreign key constraint violation

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 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2025-10-10 11:33:32 +11:00
parent 9aeaa433fc
commit 192bd99dfa

View File

@@ -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,