1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | -- Reconcile the teams feature with the code that uses it.
--
-- Same class as 0113. src/db/schema-extensions.ts declared its own `teams`,
-- `team_members` and `team_repos` alongside src/db/schema.ts, and only
-- schema.ts is in drizzle.config.ts. Comparing the extensions definitions
-- against migration 0003 (the real database):
--
-- teams extensions adds `permission`, omits the NOT NULL `slug`.
-- src/routes/orgs.tsx inserts without slug and renders
-- team.permission — so team creation fails on the NOT NULL
-- slug, and the badge reads a column that does not exist.
-- team_members extensions omits `role`; harmless, it has a default.
-- team_repos HAS NO MIGRATION AT ALL. The table has never existed, yet
-- orgs.tsx selects and joins it to render a team's repository
-- list, so that panel could only ever have errored.
--
-- Adding rather than removing, for the same reason as 0113: the team create
-- form collects a permission level and the team page is built to list repos.
-- Deleting those would throw away working UI to match an accident of history.
--
-- `permission` is defaulted so existing rows remain valid.
ALTER TABLE "teams" ADD COLUMN IF NOT EXISTS "permission" text DEFAULT 'read' NOT NULL;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "team_repos" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"team_id" uuid NOT NULL,
"repository_id" uuid NOT NULL,
"permission" text DEFAULT 'read' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "team_repos_team_fk" FOREIGN KEY ("team_id") REFERENCES "teams"("id") ON DELETE cascade,
CONSTRAINT "team_repos_repo_fk" FOREIGN KEY ("repository_id") REFERENCES "repositories"("id") ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "team_repos_unique" ON "team_repos" ("team_id", "repository_id");
|