Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

0003_orgs_and_teams.sql

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

0003_orgs_and_teams.sqlBlame66 lines · 1 contributor
5cc5d95Claude1-- Gluecron migration 0003: Block B1 — organizations + teams.
2-- Schema is additive; does not touch existing tables.
3
4--> statement-breakpoint
5CREATE TABLE IF NOT EXISTS "organizations" (
6 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
7 "slug" text NOT NULL UNIQUE,
8 "name" text NOT NULL,
9 "description" text,
10 "avatar_url" text,
11 "billing_email" text,
12 "created_by_id" uuid NOT NULL,
13 "created_at" timestamp DEFAULT now() NOT NULL,
14 "updated_at" timestamp DEFAULT now() NOT NULL,
15 CONSTRAINT "organizations_created_by_fk" FOREIGN KEY ("created_by_id") REFERENCES "users"("id") ON DELETE restrict
16);
17
18--> statement-breakpoint
19CREATE TABLE IF NOT EXISTS "org_members" (
20 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
21 "org_id" uuid NOT NULL,
22 "user_id" uuid NOT NULL,
23 "role" text NOT NULL DEFAULT 'member',
24 "created_at" timestamp DEFAULT now() NOT NULL,
25 CONSTRAINT "org_members_org_fk" FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE cascade,
26 CONSTRAINT "org_members_user_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade
27);
28
29--> statement-breakpoint
30CREATE UNIQUE INDEX IF NOT EXISTS "org_members_unique" ON "org_members" ("org_id", "user_id");
31
32--> statement-breakpoint
33CREATE INDEX IF NOT EXISTS "org_members_user" ON "org_members" ("user_id");
34
35--> statement-breakpoint
36CREATE TABLE IF NOT EXISTS "teams" (
37 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
38 "org_id" uuid NOT NULL,
39 "slug" text NOT NULL,
40 "name" text NOT NULL,
41 "description" text,
42 "parent_team_id" uuid,
43 "created_at" timestamp DEFAULT now() NOT NULL,
44 "updated_at" timestamp DEFAULT now() NOT NULL,
45 CONSTRAINT "teams_org_fk" FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE cascade
46);
47
48--> statement-breakpoint
49CREATE UNIQUE INDEX IF NOT EXISTS "teams_org_slug" ON "teams" ("org_id", "slug");
50
51--> statement-breakpoint
52CREATE TABLE IF NOT EXISTS "team_members" (
53 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
54 "team_id" uuid NOT NULL,
55 "user_id" uuid NOT NULL,
56 "role" text NOT NULL DEFAULT 'member',
57 "created_at" timestamp DEFAULT now() NOT NULL,
58 CONSTRAINT "team_members_team_fk" FOREIGN KEY ("team_id") REFERENCES "teams"("id") ON DELETE cascade,
59 CONSTRAINT "team_members_user_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade
60);
61
62--> statement-breakpoint
63CREATE UNIQUE INDEX IF NOT EXISTS "team_members_unique" ON "team_members" ("team_id", "user_id");
64
65--> statement-breakpoint
66CREATE INDEX IF NOT EXISTS "team_members_user" ON "team_members" ("user_id");