Skip to content

Commit 67b0dd1

Browse files
authored
Rename team → organization, mirror minimally from WorkOS (#130)
Reshape the data model to mirror WorkOS naming and reduce duplication: - `users`/`teams`/`team_members`/`invitations` → `accounts` + `organizations` - `team_id` → `organization_id` everywhere (shared schema, postgres package, cloud) - Drop membership and invitation tables — AuthKit owns these - `accounts` is just the WorkOS user ID (FK anchor); profile data lives in WorkOS - `organizations` mirrors org id + name for fast executor creation Swap auth resolution to proper Effect HttpApi middleware: - `SessionAuth` middleware (cookie security) provides `SessionContext` — used by /auth/me, /auth/logout, /auth/organization - `OrgAuth` middleware provides `AuthContext` (org required) — used by all protected executor endpoints - Three-tier API split: public (login/callback), session (auth ops), protected (org-required executor ops) Wire createOrganization through WorkOS SDK so first-time users can bootstrap their org via the /setup flow.
1 parent 3d7b233 commit 67b0dd1

45 files changed

Lines changed: 2177 additions & 1127 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/cloud/.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
.env.op
3+
.env.local
4+
.dev-db/

‎apps/cloud/drizzle.config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "drizzle-kit";
2+
3+
export default defineConfig({
4+
schema: ["./src/services/schema.ts", "../../packages/core/storage-postgres/src/schema.ts"],
5+
out: "./drizzle",
6+
dialect: "postgresql",
7+
});
Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,65 @@
1-
CREATE TABLE "invitations" (
1+
CREATE TABLE "accounts" (
22
"id" text PRIMARY KEY NOT NULL,
3-
"team_id" text NOT NULL,
4-
"email" text NOT NULL,
5-
"invited_by" text NOT NULL,
6-
"status" text NOT NULL,
7-
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
8-
"expires_at" timestamp with time zone NOT NULL
3+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
4+
);
5+
--> statement-breakpoint
6+
CREATE TABLE "organizations" (
7+
"id" text PRIMARY KEY NOT NULL,
8+
"name" text NOT NULL,
9+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
910
);
1011
--> statement-breakpoint
1112
CREATE TABLE "plugin_kv" (
12-
"team_id" text NOT NULL,
13+
"organization_id" text NOT NULL,
1314
"namespace" text NOT NULL,
1415
"key" text NOT NULL,
1516
"value" text NOT NULL,
16-
CONSTRAINT "plugin_kv_team_id_namespace_key_pk" PRIMARY KEY("team_id","namespace","key")
17+
CONSTRAINT "plugin_kv_organization_id_namespace_key_pk" PRIMARY KEY("organization_id","namespace","key")
1718
);
1819
--> statement-breakpoint
1920
CREATE TABLE "policies" (
2021
"id" text NOT NULL,
21-
"team_id" text NOT NULL,
22+
"organization_id" text NOT NULL,
2223
"name" text NOT NULL,
2324
"action" text NOT NULL,
2425
"match_tool_pattern" text,
2526
"match_source_id" text,
2627
"priority" integer NOT NULL,
2728
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
28-
CONSTRAINT "policies_id_team_id_pk" PRIMARY KEY("id","team_id")
29+
CONSTRAINT "policies_id_organization_id_pk" PRIMARY KEY("id","organization_id")
2930
);
3031
--> statement-breakpoint
3132
CREATE TABLE "secrets" (
3233
"id" text NOT NULL,
33-
"team_id" text NOT NULL,
34+
"organization_id" text NOT NULL,
3435
"name" text NOT NULL,
3536
"purpose" text,
3637
"encrypted_value" "bytea" NOT NULL,
3738
"iv" "bytea" NOT NULL,
3839
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
39-
CONSTRAINT "secrets_id_team_id_pk" PRIMARY KEY("id","team_id")
40+
CONSTRAINT "secrets_id_organization_id_pk" PRIMARY KEY("id","organization_id")
4041
);
4142
--> statement-breakpoint
4243
CREATE TABLE "sources" (
4344
"id" text NOT NULL,
44-
"team_id" text NOT NULL,
45+
"organization_id" text NOT NULL,
4546
"name" text NOT NULL,
4647
"kind" text NOT NULL,
4748
"config" jsonb NOT NULL,
4849
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
49-
CONSTRAINT "sources_id_team_id_pk" PRIMARY KEY("id","team_id")
50-
);
51-
--> statement-breakpoint
52-
CREATE TABLE "team_members" (
53-
"team_id" text NOT NULL,
54-
"user_id" text NOT NULL,
55-
"role" text NOT NULL,
56-
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
57-
CONSTRAINT "team_members_team_id_user_id_pk" PRIMARY KEY("team_id","user_id")
58-
);
59-
--> statement-breakpoint
60-
CREATE TABLE "teams" (
61-
"id" text PRIMARY KEY NOT NULL,
62-
"name" text NOT NULL,
63-
"created_at" timestamp with time zone DEFAULT now() NOT NULL
50+
CONSTRAINT "sources_id_organization_id_pk" PRIMARY KEY("id","organization_id")
6451
);
6552
--> statement-breakpoint
6653
CREATE TABLE "tool_definitions" (
6754
"name" text NOT NULL,
68-
"team_id" text NOT NULL,
55+
"organization_id" text NOT NULL,
6956
"schema" jsonb NOT NULL,
70-
CONSTRAINT "tool_definitions_name_team_id_pk" PRIMARY KEY("name","team_id")
57+
CONSTRAINT "tool_definitions_name_organization_id_pk" PRIMARY KEY("name","organization_id")
7158
);
7259
--> statement-breakpoint
7360
CREATE TABLE "tools" (
7461
"id" text NOT NULL,
75-
"team_id" text NOT NULL,
62+
"organization_id" text NOT NULL,
7663
"source_id" text NOT NULL,
7764
"plugin_key" text NOT NULL,
7865
"name" text NOT NULL,
@@ -81,14 +68,5 @@ CREATE TABLE "tools" (
8168
"input_schema" jsonb,
8269
"output_schema" jsonb,
8370
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
84-
CONSTRAINT "tools_id_team_id_pk" PRIMARY KEY("id","team_id")
85-
);
86-
--> statement-breakpoint
87-
CREATE TABLE "users" (
88-
"id" text PRIMARY KEY NOT NULL,
89-
"email" text NOT NULL,
90-
"name" text,
91-
"avatar_url" text,
92-
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
93-
CONSTRAINT "users_email_unique" UNIQUE("email")
71+
CONSTRAINT "tools_id_organization_id_pk" PRIMARY KEY("id","organization_id")
9472
);

0 commit comments

Comments
 (0)