-- Multi-team missions: a mission can have N teams, each tagged with a -- purpose (research / coding / security / benchmark / etc). The wizard -- picks templates per purpose; on_launch mints one team per (purpose, -- template) pick and records the link here. -- -- missions.team_id stays around as a legacy pointer to the FIRST minted -- team for single-team surfaces (Team tab default view, etc). It is -- redundant with (mission_teams WHERE mission_id = X LIMIT 1) but -- preserving it avoids a broader refactor in this slice. BEGIN; CREATE TABLE mission_teams ( mission_id UUID NOT NULL REFERENCES missions(id) ON DELETE CASCADE, team_id UUID PRIMARY KEY REFERENCES teams(id) ON DELETE CASCADE, purpose TEXT NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX mission_teams_mission_idx ON mission_teams (mission_id); COMMIT;