Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix: every team is in its owner's workspace (#580)

Crofffca1f8ecdbce
diff --git a/apps/api/AGENTS.md b/apps/api/AGENTS.md
index eb105a1c..0bca5525 100644
--- a/apps/api/AGENTS.md
+++ b/apps/api/AGENTS.md
@@ -140,11 +140,13 @@ Enforced declaratively through macros, never imperative calls in handlers.
- **The workspace decides who creates a team in it** (`POST /teams`, `createTeam` in
`teams/service.ts`, `assertMayCreateTeam` in `workspaces/service.ts`): its owner by
default, also its admins, or anyone in one of its teams, as its owner sets
- `teamCreation`. `workspaceId` in the body names the workspace; left out, it is the
- instance workspace, the one the instance owner owns. Anyone else gets 403.
+ `teamCreation`. `workspaceId` in the body names the workspace and is required. Anyone
+ else gets 403.
- **Every person owns one workspace.** No route creates one: sign-up makes it
(`@repo/auth`), and `authContext` makes it on the next request for an account that has
- none (`ensurePersonalWorkspace`), while `personalWorkspaces` is on in the auth settings.
+ none (`ensurePersonalWorkspace`): the instance owner always, anyone else while
+ `personalWorkspaces` is on in the auth settings. There is no shared workspace; every
+ team is in the workspace of its owner.
A build that lets a person own more mounts its own route on `createOwnWorkspace` and
`workspaceCreation` (`workspaces/service.ts`, which refuse an agent's bot user) and
raises the number with `setOwnedWorkspaceLimit` (`shared/limits.ts`). When an account is deleted (`deleteAccount`), a workspace it
@@ -152,12 +154,12 @@ Enforced declaratively through macros, never imperative calls in handlers.
instance owner with what the account owned alone in it (`releaseOwnedWorkspaces` in
`teams/service.ts`). God mode asks about sole-owned projects only outside the account's
own workspaces. The owner deletes a workspace under the same rule
- (`DELETE /workspaces/:id`, `workspaceDeletion` in `workspaces/service.ts`); the instance
- workspace never goes. No core route hands a workspace over; `transferWorkspace` is
- there for a build that offers it. SCIM provisioning creates and attaches accounts across the
- instance, so its routes (`workspaceScim` guard) are the instance owner's alone; a hosted
- build sets SCIM up per workspace with `setWorkspaceScim()` from `@repo/auth`, which lets
- every workspace owner (see SCIM below).
+ (`DELETE /workspaces/:id`, `workspaceDeletion` in `workspaces/service.ts`). No core
+ route hands a workspace over; `transferWorkspace` is there for a build that offers it.
+ SCIM provisioning creates and attaches accounts across the instance, so it is set up in
+ god mode (`/god/scim`); a hosted build also sets it up per workspace with
+ `setWorkspaceScim()` from `@repo/auth`, whose routes (`workspaceScim` guard) are each
+ workspace owner's (see SCIM below).
- **A member of the team joins a project directly** (`POST /projects/:key/members`,
from the candidate list); anyone else joins through an invite, which puts them in
the team as well. A team invite (`/teams/:teamId/invites`) names no project. One
@@ -316,9 +318,9 @@ to provision users and groups with. Three things make it unlike every other modu
- **Mounted on the root app in `app.ts`, not under `planner`.** The planner's `authContext`
answers 401 before the bearer check could run. Authentication is one `resolve` that hands
- the token to `verifyScimToken` from `@repo/auth`, which answers with the workspace the
- token belongs to. Every route acts for that workspace, and every function in `service.ts`
- takes its id.
+ the token to `verifyScimToken` from `@repo/auth`, which answers with the provider the
+ token belongs to: the instance's (`workspaceId` null) or a workspace's. Every route acts
+ for that provider, and every function in `service.ts` takes its `workspaceId`.
- **Its own error document.** `onError` sits on a parent instance that `.use()`s the routes
and answers only for paths under `/scim/v2`, handing everything else back to the planner's
handler. Two reasons for that shape: an `onError` beside the routes widens the inferred
@@ -336,48 +338,43 @@ does, which deliberately skips the registration gate — with SCIM on, the ident
brings people in, and that is what makes `registration: 'closed'` plus SSO work.
An account is one `user` row across the instance. What a provider says about a person — its
-own id for them and whether they are active — is a `scim_user` row per (workspace, user).
-Groups belong to a workspace (`scim_group.workspace_id`), their names are unique within it,
-and their members must be accounts it sees. A create for an address that has an account
-links it. The group mappings and the settings are routes of `modules/workspaces/` (see the
-`workspaceScim` guard above). How far a provider reaches is `workspaceScim()` from
-`@repo/auth`:
-
-- **Off, as on a self-hosted instance, SCIM is the instance's.** God mode sets it up for the
- instance workspace, and only that workspace's token opens `/scim/v2`. The provider sees
- every account, PUT and PATCH write the name and address, a group maps to any project, and
- DELETE removes the account the way god mode does (409 for the only owner of a project
- outside the workspaces they own, whose projects pass to the instance owner).
+own id for them and whether they are active — is a `scim_user` row per (provider, user), where
+`workspace_id` is null for the instance's provider. Groups belong to a provider
+(`scim_group.workspace_id`, null for the instance's), their names are unique within it, and
+their members must be accounts it sees. A create for an address that has an account links
+it. The group mappings are in `scim/mappings.ts`; they and the settings are served from god
+mode (`/god/scim/...`) and, for a workspace, from `modules/workspaces/` (`/workspaces/:id/scim/...`).
+
+- **The instance's provider** is god's, set up in god mode, and every build has it. Its
+ token reads `scim_<secret>`. The provider sees every account, PUT and PATCH write the name
+ and address, a group maps to any project, and DELETE removes the account the way god mode
+ does (409 for the only owner of a project outside the workspaces they own, whose projects
+ pass to the instance owner).
A deactivated account (`user.active` false, written alongside `scim_user.active`) keeps
its teams and projects but cannot sign in, and `isAccountDeactivated` makes
`authContext`, `/me` and the MCP key check refuse what it already holds.
God mode writes `user.active` too (`POST /god/users/:userId/deactivate` and
- `/reactivate` in `modules/god/`) while no provider manages accounts
- (`accountsManagedByScim` from `@repo/auth`), and answers 409 while one does. Deactivating
+ `/reactivate` in `modules/god/`) while the instance's provider does not manage accounts
+ (`accountsManagedByScim` from `@repo/auth`), and answers 409 while it does. Deactivating
there also deletes the account's sessions, its MCP OAuth tokens and the pending invites
it created; its API keys are kept and answer 401 until it is reactivated. The instance
owner and an agent's account are refused (403). The user list and detail carry
`activeLock` (`owner`, `agent` or `scim`), the reason the switch is locked, or null.
-- **On, as in a hosted build, SCIM is each workspace's.** A workspace's provider decides who
- is in the workspace, not who has an account, so the same person can be linked by several
- workspaces. It sees the accounts it linked and the people in the workspace's teams
- (`inWorkspace` in `service.ts`), a name or address it sends is accepted and the account
- keeps its own, and a group maps to projects of its workspace only.
-- **On, with the instance's beside it** (`setInstanceScimBeside()` from `@repo/auth`), for
- a build where one organisation runs the instance: the instance workspace's provider acts
- as when SCIM is the instance's, every other workspace's as when it is each workspace's.
- `instanceScimWorkspace()` names the workspace whose provider acts on the whole instance,
- or null, and `actsOnInstance` in `service.ts` is what the routes ask. The instance's
- groups grant nothing in a workspace that set up SCIM of its own
- (`workspacesWithOwnScim`): `reconcile.ts` leaves them out there, the mapping picker
- leaves its projects out, and turning that workspace's SCIM on or off reconciles its
- mapped projects (`reconcileWorkspaceGrants` in `workspaces/scim.ts`). That provider's
- settings stay the instance owner's (`workspaceScim` guard).
-
-A create first asks the installed policy whether the workspace may provision the address
-(`email-policy.ts`). A self-hosted instance allows any address, since only its owner sets
-up provisioning; a hosted build calls `setScimEmailPolicy` with a check against the domains the workspace has
-verified, and a refused address answers 400 `invalidValue`.
+- **A workspace's provider**, where a hosted build turns `setWorkspaceScim()` on, decides
+ who is in the workspace, not who has an account, so the same person can be linked by
+ several workspaces. Its token reads `scim_<workspaceId>_<secret>`. It sees the accounts it
+ linked and the people in the workspace's teams (`inWorkspace` in `service.ts`), a name or
+ address it sends is accepted and the account keeps its own, and a group maps to projects
+ of its workspace only. The instance's groups grant nothing in a workspace that set up
+ SCIM of its own (`workspacesWithOwnScim`): `reconcile.ts` leaves them out there, the
+ mapping picker leaves its projects out, and turning that workspace's SCIM on or off
+ reconciles its mapped projects (`reconcileWorkspaceGrants` in `scim/mappings.ts`).
+
+A create first asks the installed policy whether the provider may provision the address
+(`email-policy.ts`, with `workspaceId` null for the instance's). By default it allows any
+address, since only god sets up the instance's provider; a hosted build calls
+`setScimEmailPolicy` with a check against the domains a workspace has verified, and a refused
+address answers 400 `invalidValue`.
Set up per workspace, deactivation (`active: false`) and DELETE take the person out of every
team of the workspace through `dropWorkspaceMemberships` in `teams/service.ts`, invite memberships
diff --git a/apps/api/src/__tests__/helpers/app.ts b/apps/api/src/__tests__/helpers/app.ts
index 365c7693..18239fef 100644
--- a/apps/api/src/__tests__/helpers/app.ts
+++ b/apps/api/src/__tests__/helpers/app.ts
@@ -28,3 +28,22 @@ export function scimApi(token: string) {
}
export type Api = typeof api;
+
+// The workspace the caller owns, where a test creates teams of its own.
+export async function ownWorkspaceId(client: Api): Promise<number> {
+ const own = (await client.workspaces.get()).data?.find((w) => w.role === 'owner');
+ if (!own) throw new Error('ownWorkspaceId: the caller owns no workspace');
+ return own.id;
+}
+
+type CreateProjectBody = Parameters<ReturnType<Api['teams']>['projects']['post']>[0];
+
+// Creates a project in the first team the caller owns, the team signUpTestUser gives it.
+export async function createProject(client: Api, body: CreateProjectBody) {
+ const teams = (await client.teams.get()).data ?? [];
+ const own = teams
+ .filter((team) => team.role === 'owner' && team.via === 'member')
+ .sort((a, b) => a.id - b.id)[0];
+ if (!own) throw new Error('createProject: the caller owns no team');
+ return client.teams({ teamId: own.id }).projects.post(body);
+}
diff --git a/apps/api/src/__tests__/helpers/auth.ts b/apps/api/src/__tests__/helpers/auth.ts
index 5f7c9f4e..afe527bf 100644
--- a/apps/api/src/__tests__/helpers/auth.ts
+++ b/apps/api/src/__tests__/helpers/auth.ts
@@ -1,6 +1,7 @@
import { createHash } from 'node:crypto';
import { auth } from '@repo/auth';
-import { db, instanceWorkspaceId } from '@repo/db';
+import { db, workspaceManager } from '@repo/db';
+import { and, eq } from 'drizzle-orm';
import { insertOwnedTeam } from '#modules/teams/service';
import { app } from './app';
@@ -13,6 +14,9 @@ export interface TestUser {
// The handle the sign-up hook derived from the address, which is how a test
// mentions this user.
username: string;
+ // The workspace sign-up gave the account, or null when it got none (personal
+ // workspaces off, and not the instance owner).
+ workspaceId: number | null;
}
let counter = 0;
@@ -23,7 +27,8 @@ let counter = 0;
// tests do not collide. Pass this cookie to authenticated requests.
//
// Sign-up creates no team. Most tests need one to create projects in, so the user is
-// given a team named after its username, without a slug, unless `team` is false.
+// given a team named after its username, without a slug, in its own workspace, unless
+// `team` is false.
//
// Note: the very first user created in a fresh database becomes the "god" role
// (better-auth create hook). resetDb() clears users between tests, so whichever
@@ -56,13 +61,19 @@ export async function signUpTestUser(
if (!userId) throw new Error(`signUpTestUser: no user id returned for ${email}`);
const username = body.user?.username;
if (!username) throw new Error(`signUpTestUser: no username returned for ${email}`);
+ const [own] = await db
+ .select({ workspaceId: workspaceManager.workspaceId })
+ .from(workspaceManager)
+ .where(and(eq(workspaceManager.userId, userId), eq(workspaceManager.role, 'owner')));
+ const workspaceId = own?.workspaceId ?? null;
if (overrides.team !== false) {
- await db.transaction(async (tx) =>
- insertOwnedTeam(tx, await instanceWorkspaceId(tx), username, userId),
- );
+ if (workspaceId === null) {
+ throw new Error(`signUpTestUser: ${email} has no workspace for a team; pass team: false`);
+ }
+ await db.transaction(async (tx) => insertOwnedTeam(tx, workspaceId, username, userId));
}
- return { cookie, userId, email, username };
+ return { cookie, userId, email, username, workspaceId };
}
// Opens a magic link for `email` as the web asks for one (errorCallbackURL on the sign-in
diff --git a/apps/api/src/__tests__/helpers/db.ts b/apps/api/src/__tests__/helpers/db.ts
index 1c2f1d51..bc599f9c 100644
--- a/apps/api/src/__tests__/helpers/db.ts
+++ b/apps/api/src/__tests__/helpers/db.ts
@@ -1,4 +1,4 @@
-import { db, workspace } from '@repo/db';
+import { db } from '@repo/db';
import { sql } from 'drizzle-orm';
// TRUNCATEs every table in the test database so each test starts clean. Two
@@ -17,8 +17,7 @@ export async function resetDb(): Promise<void> {
// All application and better-auth tables live in the public schema. The
// drizzle migrations bookkeeping table is excluded so migrations are not
// re-run, and so is the MCP resource better-auth writes once, at startup.
- // RESTART IDENTITY resets serial ids; CASCADE handles FK order. The instance
- // workspace the migration created goes with them, so it is written again.
+ // RESTART IDENTITY resets serial ids; CASCADE handles FK order.
const rows = (await db.execute(sql`
SELECT tablename FROM pg_tables
WHERE schemaname = 'public' AND tablename NOT IN ('__drizzle_migrations', 'oauth_resource')
@@ -27,5 +26,4 @@ export async function resetDb(): Promise<void> {
const tables = rows.map((r) => `"${r.tablename}"`).join(', ');
if (tables.length === 0) return;
await db.execute(sql.raw(`TRUNCATE ${tables} RESTART IDENTITY CASCADE`));
- await db.insert(workspace).values({ name: 'Workspace' });
}
diff --git a/apps/api/src/__tests__/integration/email-domains.test.ts b/apps/api/src/__tests__/integration/email-domains.test.ts
index 09ae4d28..06b0fd31 100644
--- a/apps/api/src/__tests__/integration/email-domains.test.ts
+++ b/apps/api/src/__tests__/integration/email-domains.test.ts
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
import { auth, setAuthSettings, setRegistrationEmailPolicy } from '@repo/auth';
import { setInviteEmailPolicy } from '#modules/invites/email-policy';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { openMagicLink, signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -11,7 +11,7 @@ import { resetDb } from '#tests/helpers/db';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
await setAuthSettings({ allowedEmailDomains: ['company.com'] });
return { asOwner };
}
@@ -69,7 +69,7 @@ describe('allowed email domains', () => {
it('invites an account that already exists at another domain', async () => {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
await signUpTestUser({ email: '[email protected]' });
await setAuthSettings({ allowedEmailDomains: ['company.com'] });
const res = await asOwner
diff --git a/apps/api/src/__tests__/integration/invite-forms.test.ts b/apps/api/src/__tests__/integration/invite-forms.test.ts
index 77f8b582..84b6709d 100644
--- a/apps/api/src/__tests__/integration/invite-forms.test.ts
+++ b/apps/api/src/__tests__/integration/invite-forms.test.ts
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from 'bun:test';
import { auth, setAuthSettings } from '@repo/auth';
import { db, teamInvite } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { app, authedApi, apiKeyApi } from '#tests/helpers/app';
+import { app, authedApi, apiKeyApi, createProject } from '#tests/helpers/app';
import { openMagicLink, signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { mcpAccessToken } from '#tests/helpers/mcp';
@@ -18,7 +18,7 @@ const DAY = 24 * 60 * 60 * 1000;
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner, teamId: project.data!.teamId };
}
diff --git a/apps/api/src/__tests__/integration/openapi.test.ts b/apps/api/src/__tests__/integration/openapi.test.ts
index 94f5ef89..750e2567 100644
--- a/apps/api/src/__tests__/integration/openapi.test.ts
+++ b/apps/api/src/__tests__/integration/openapi.test.ts
@@ -49,9 +49,9 @@ describe('OpenAPI document', () => {
const doc = await document();
const genericMediaTypes = ['application/json', 'multipart/form-data', 'text/plain'];
- expect(Object.keys(doc.paths['/projects']!.post!.requestBody!.content!)).toEqual([
- 'application/json',
- ]);
+ expect(Object.keys(doc.paths['/teams/{teamId}/projects']!.post!.requestBody!.content!)).toEqual(
+ ['application/json'],
+ );
expect(
Object.keys(doc.paths['/issues/{issueId}/attachments']!.post!.requestBody!.content!),
).toEqual(['multipart/form-data']);
diff --git a/apps/api/src/__tests__/integration/usernames.test.ts b/apps/api/src/__tests__/integration/usernames.test.ts
index 2df3125f..32e21f72 100644
--- a/apps/api/src/__tests__/integration/usernames.test.ts
+++ b/apps/api/src/__tests__/integration/usernames.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { auth } from '@repo/auth';
-import { authedApi } from '../helpers/app';
+import { authedApi, createProject } from '../helpers/app';
import { signUpTestUser } from '../helpers/auth';
import { resetDb } from '../helpers/db';
import { createAgent } from '../helpers/agents';
@@ -17,7 +17,7 @@ async function usernameOf(cookie: string): Promise<string | null> {
async function projectWithAgent(handle: string): Promise<void> {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
await createAgent(asOwner, 'MKT', {
name: 'Design Bot',
username: handle,
diff --git a/apps/api/src/mcp/__tests__/integration/attachments.test.ts b/apps/api/src/mcp/__tests__/integration/attachments.test.ts
index db07eaf5..de4143e5 100644
--- a/apps/api/src/mcp/__tests__/integration/attachments.test.ts
+++ b/apps/api/src/mcp/__tests__/integration/attachments.test.ts
@@ -3,7 +3,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { CallToolResultSchema, type CallToolRequest } from '@modelcontextprotocol/sdk/types.js';
import { auth } from '@repo/auth';
-import { app, authedApi } from '#tests/helpers/app';
+import { app, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { buildMcpServer } from '../../server';
@@ -47,7 +47,7 @@ async function connect(userId: string) {
async function setup() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const issue = await asOwner
.projects({ projectKey: 'MKT' })
diff --git a/apps/api/src/mcp/__tests__/integration/mcp-teams.test.ts b/apps/api/src/mcp/__tests__/integration/mcp-teams.test.ts
index 7d183e92..b3d15edd 100644
--- a/apps/api/src/mcp/__tests__/integration/mcp-teams.test.ts
+++ b/apps/api/src/mcp/__tests__/integration/mcp-teams.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it } from 'bun:test';
import { auth } from '@repo/auth';
-import { app, authedApi } from '#tests/helpers/app';
+import { app, authedApi, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { resetDb } from '#tests/helpers/db';
import { signUpTestUser } from '#tests/helpers/auth';
import { createAgent, setAgentProjectRole, teamOf } from '#tests/helpers/agents';
@@ -43,7 +43,7 @@ async function call(apiKey: string, name: string, args: Record<string, unknown>
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const teamId = await teamOf(asOwner, 'MKT');
const role = await createRole(asOwner, 'MKT', {
name: 'Agent Admin',
@@ -86,7 +86,7 @@ describe('MCP team resolution', () => {
const { agentKey, roleId } = await setup();
const other = await signUpTestUser({ name: 'Other', email: '[email protected]' });
const asOther = authedApi(other.cookie);
- await asOther.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOther, { key: 'OPS', name: 'Ops' });
const otherTeam = await teamOf(asOther, 'OPS');
await call(agentKey, 'create_ai_agent', {
@@ -103,7 +103,11 @@ describe('MCP team resolution', () => {
it('asks a person in more than one team to name the team', async () => {
const { owner, asOwner, agentKey } = await setup();
- await asOwner.teams.post({ name: 'Second Team', slug: 'second-team' });
+ await asOwner.teams.post({
+ name: 'Second Team',
+ slug: 'second-team',
+ workspaceId: await ownWorkspaceId(asOwner),
+ });
const personKey = (await auth.api.createApiKey({ body: { userId: owner.userId, name: 'mcp' } }))
.key;
@@ -121,7 +125,11 @@ describe('MCP team resolution', () => {
it('lists the teams of the caller', async () => {
const { owner, asOwner } = await setup();
- await asOwner.teams.post({ name: 'Second Team', slug: 'second-team' });
+ await asOwner.teams.post({
+ name: 'Second Team',
+ slug: 'second-team',
+ workspaceId: await ownWorkspaceId(asOwner),
+ });
const personKey = (await auth.api.createApiKey({ body: { userId: owner.userId, name: 'mcp' } }))
.key;
diff --git a/apps/api/src/mcp/__tests__/integration/structured-results.test.ts b/apps/api/src/mcp/__tests__/integration/structured-results.test.ts
index 2eff8728..da6c2cf3 100644
--- a/apps/api/src/mcp/__tests__/integration/structured-results.test.ts
+++ b/apps/api/src/mcp/__tests__/integration/structured-results.test.ts
@@ -3,7 +3,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { CallToolResultSchema, type CallToolRequest } from '@modelcontextprotocol/sdk/types.js';
import { auth } from '@repo/auth';
-import { app, authedApi } from '#tests/helpers/app';
+import { app, authedApi, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { buildMcpServer } from '../../server';
@@ -80,7 +80,7 @@ describe('MCP structured results through the SDK client', () => {
it('validates structured validation, conflict, and permission errors without changing their text', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.projects.post({ key: 'PRIVATE', name: 'Private project' });
+ await createProject(api, { key: 'PRIVATE', name: 'Private project' });
const client = await connect(owner.userId);
await client.listTools();
for (const [args, status] of [
@@ -119,7 +119,11 @@ describe('MCP structured results through the SDK client', () => {
it('returns the same error envelope for missing team arguments and unknown tools', async () => {
const user = await signUpTestUser();
- await authedApi(user.cookie).teams.post({ name: 'Another team', slug: 'another-team' });
+ await authedApi(user.cookie).teams.post({
+ name: 'Another team',
+ slug: 'another-team',
+ workspaceId: await ownWorkspaceId(authedApi(user.cookie)),
+ });
const client = await connect(user.userId);
await client.listTools();
const missing = await callTool(client, { name: 'list_ai_agents' });
diff --git a/apps/api/src/mcp/__tests__/integration/team-projects.test.ts b/apps/api/src/mcp/__tests__/integration/team-projects.test.ts
index ff030118..1b874331 100644
--- a/apps/api/src/mcp/__tests__/integration/team-projects.test.ts
+++ b/apps/api/src/mcp/__tests__/integration/team-projects.test.ts
@@ -3,11 +3,11 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { CallToolResultSchema, type CallToolRequest } from '@modelcontextprotocol/sdk/types.js';
import { auth } from '@repo/auth';
-import { app, authedApi, type Api } from '#tests/helpers/app';
+import { app, authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
-import { routeTools, withoutFields } from '../../generate';
+import { routeTools } from '../../generate';
import { buildMcpServer } from '../../server';
const clients: Client[] = [];
@@ -36,12 +36,10 @@ async function addTeamMember(api: Api, teamId: number, role: 'manager' | 'member
}
describe('MCP team project route', () => {
- it('advertises the guarded team route with the existing project schemas', () => {
+ it('advertises project creation on the guarded team route only', () => {
const tools = routeTools(app);
- const tool = tools.find((tool) => tool.name === 'create_team_project');
- const generic = tools.find((tool) => tool.name === 'create_project')!;
+ const tool = tools.find((tool) => tool.name === 'create_project');
- expect(tool).toBeDefined();
expect(tool).toMatchObject({
method: 'POST',
path: '/teams/:teamId/projects',
@@ -55,9 +53,7 @@ describe('MCP team project route', () => {
},
});
expect(tool!.inputSchema.required).toContain('teamId');
- expect(withoutFields(tool!.inputSchema, ['teamId'])).toEqual(generic.inputSchema);
- expect(tool!.outputSchema).toEqual(generic.outputSchema);
- expect(generic).toMatchObject({ method: 'POST', path: '/projects', pathParams: [] });
+ expect(tools.some((tool) => tool.method === 'POST' && tool.path === '/projects')).toBe(false);
});
});
@@ -67,18 +63,24 @@ describe('MCP team project creation', () => {
await Promise.all(clients.splice(0).map((client) => client.close()));
});
- it('creates in the explicitly selected team and keeps generic creation in the first owned team', async () => {
+ it('creates in the explicitly selected team', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
const firstTeamId = (await api.teams.get()).data![0].id;
- const second = (await api.teams.post({ name: 'Second team', slug: 'second-team' })).data!;
+ const second = (
+ await api.teams.post({
+ name: 'Second team',
+ slug: 'second-team',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
const client = await connect(owner.userId);
const listed = await client.listTools();
- const tool = listed.tools.find((tool) => tool.name === 'create_team_project')!;
+ const tool = listed.tools.find((tool) => tool.name === 'create_project')!;
expect(tool.inputSchema.required).toContain('teamId');
const created = await callTool(client, {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: second.id, key: 'TEAM', name: 'Team project', description: 'Details' },
});
expect(created.isError).toBe(false);
@@ -91,16 +93,6 @@ describe('MCP team project creation', () => {
expect((await api.teams({ teamId: second.id }).projects.get()).data?.items).toMatchObject([
{ key: 'TEAM', isMember: true },
]);
-
- const generic = await callTool(client, {
- name: 'create_project',
- arguments: { key: 'GENERIC', name: 'Generic project' },
- });
- expect(generic.isError).toBe(false);
- expect(generic.structuredContent).toMatchObject({
- status: 201,
- data: { teamId: firstTeamId, key: 'GENERIC' },
- });
});
it('uses the existing key-derived team for a person with one MCP-enabled team', async () => {
@@ -108,14 +100,12 @@ describe('MCP team project creation', () => {
const api = authedApi(owner.cookie);
const teamId = (await api.teams.get()).data![0].id;
const client = await connect(owner.userId);
- const tool = (await client.listTools()).tools.find(
- (tool) => tool.name === 'create_team_project',
- )!;
+ const tool = (await client.listTools()).tools.find((tool) => tool.name === 'create_project')!;
expect(tool.inputSchema.properties).not.toHaveProperty('teamId');
expect(tool.inputSchema.required).not.toContain('teamId');
const created = await callTool(client, {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { key: 'ONE', name: 'One team' },
});
expect(created.isError).toBe(false);
@@ -125,9 +115,13 @@ describe('MCP team project creation', () => {
it('requires teamId when more than one team is available', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.teams.post({ name: 'Second team', slug: 'second-team' });
+ await api.teams.post({
+ name: 'Second team',
+ slug: 'second-team',
+ workspaceId: await ownWorkspaceId(api),
+ });
const result = await callTool(await connect(owner.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { key: 'MISSING', name: 'Missing team' },
});
expect(result.isError).toBe(true);
@@ -144,7 +138,7 @@ describe('MCP team project creation', () => {
const teamId = (await api.teams.get()).data![0].id;
const manager = await addTeamMember(api, teamId, 'manager');
const result = await callTool(await connect(manager.user.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId, key: 'MANAGED', name: 'Managed project', preset: 'software' },
});
expect(result.isError).toBe(false);
@@ -163,7 +157,7 @@ describe('MCP team project creation', () => {
const teamId = (await api.teams.get()).data![0].id;
const member = await addTeamMember(api, teamId, 'member');
const result = await callTool(await connect(member.user.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId, key: 'DENIED', name: 'Denied project' },
});
expect(result.isError).toBe(true);
@@ -175,10 +169,16 @@ describe('MCP team project creation', () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
const privateTeamId = (await api.teams.get()).data![0].id;
- const visible = (await api.teams.post({ name: 'Visible', slug: 'visible' })).data!;
+ const visible = (
+ await api.teams.post({
+ name: 'Visible',
+ slug: 'visible',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
const outsider = await addTeamMember(api, visible.id, 'member');
const result = await callTool(await connect(outsider.user.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: privateTeamId, key: 'PRIVATE', name: 'Private project' },
});
expect(result.isError).toBe(true);
@@ -189,8 +189,10 @@ describe('MCP team project creation', () => {
it('refuses an agent key even when the caller names another team', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- const project = (await api.projects.post({ key: 'SOURCE', name: 'Source project' })).data!;
- const other = (await api.teams.post({ name: 'Other', slug: 'other' })).data!;
+ const project = (await createProject(api, { key: 'SOURCE', name: 'Source project' })).data!;
+ const other = (
+ await api.teams.post({ name: 'Other', slug: 'other', workspaceId: await ownWorkspaceId(api) })
+ ).data!;
const agent = (
await createAgent(api, 'SOURCE', {
name: 'Agent',
@@ -199,7 +201,7 @@ describe('MCP team project creation', () => {
})
).data!;
const result = await callTool(await connect(agent.agent.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: other.id, key: 'AGENT', name: 'Agent project' },
});
expect(result.isError).toBe(true);
@@ -213,11 +215,21 @@ describe('MCP team project creation', () => {
it('refuses a team with MCP disabled while its HTTP route remains available', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.teams.post({ name: 'Second', slug: 'second' });
- const disabled = (await api.teams.post({ name: 'Disabled', slug: 'disabled' })).data!;
+ await api.teams.post({
+ name: 'Second',
+ slug: 'second',
+ workspaceId: await ownWorkspaceId(api),
+ });
+ const disabled = (
+ await api.teams.post({
+ name: 'Disabled',
+ slug: 'disabled',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
await api.teams({ teamId: disabled.id }).mcp.patch({ enabled: false });
const result = await callTool(await connect(owner.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: disabled.id, key: 'BLOCKED', name: 'Blocked project' },
});
expect(result.isError).toBe(true);
@@ -235,7 +247,13 @@ describe('MCP team project creation', () => {
it('validates team and project fields without creating a project', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- const target = (await api.teams.post({ name: 'Target', slug: 'target' })).data!;
+ const target = (
+ await api.teams.post({
+ name: 'Target',
+ slug: 'target',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
const client = await connect(owner.userId);
for (const fields of [
{ teamId: 'invalid' },
@@ -249,7 +267,7 @@ describe('MCP team project creation', () => {
{ preset: 'invalid' },
]) {
const result = await callTool(client, {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: target.id, key: 'VALID', name: 'Valid project', ...fields },
});
expect(result.isError).toBe(true);
@@ -264,7 +282,7 @@ describe('MCP team project creation', () => {
const teamId = (await api.teams.get()).data![0].id;
const description = 'x'.repeat(2000);
const result = await callTool(await connect(owner.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { key: 'A123456789', name: 'Boundary project', description },
});
expect(result.isError).toBe(false);
@@ -277,9 +295,13 @@ describe('MCP team project creation', () => {
it('returns 404 for an unknown team', async () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.teams.post({ name: 'Second', slug: 'second' });
+ await api.teams.post({
+ name: 'Second',
+ slug: 'second',
+ workspaceId: await ownWorkspaceId(api),
+ });
const result = await callTool(await connect(owner.userId), {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: 999999, key: 'UNKNOWN', name: 'Unknown team' },
});
expect(result.isError).toBe(true);
@@ -291,11 +313,17 @@ describe('MCP team project creation', () => {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
const firstTeamId = (await api.teams.get()).data![0].id;
- const second = (await api.teams.post({ name: 'Second', slug: 'second' })).data!;
+ const second = (
+ await api.teams.post({
+ name: 'Second',
+ slug: 'second',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
const client = await connect(owner.userId);
for (const teamId of [firstTeamId, second.id]) {
const result = await callTool(client, {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId, key: 'SHARED', name: 'Shared key' },
});
expect(result.isError).toBe(false);
@@ -305,7 +333,7 @@ describe('MCP team project creation', () => {
});
}
const duplicate = await callTool(client, {
- name: 'create_team_project',
+ name: 'create_project',
arguments: { teamId: second.id, key: 'SHARED', name: 'Duplicate' },
});
expect(duplicate.isError).toBe(true);
diff --git a/apps/api/src/modules/actions/__tests__/integration/actions.test.ts b/apps/api/src/modules/actions/__tests__/integration/actions.test.ts
index a7db9cdd..5e276eb3 100644
--- a/apps/api/src/modules/actions/__tests__/integration/actions.test.ts
+++ b/apps/api/src/modules/actions/__tests__/integration/actions.test.ts
@@ -1,12 +1,12 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
async function setupOwnerProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, projectId: project.data!.id };
}
@@ -187,7 +187,7 @@ describe('actions', () => {
it('ignores ids that belong to another project', async () => {
const { asOwner } = await setupOwnerProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const mkt = (await asOwner.projects({ projectKey: 'MKT' }).actions.post({ name: 'Mine' }))
.data!;
// The OPS action sits at position 0; the reorder below places its id at
diff --git a/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts b/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts
index d60ff0ae..6df4657f 100644
--- a/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts
+++ b/apps/api/src/modules/agents/chat/__tests__/integration/agent-chat.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { app, apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import { app, apiKeyApi, authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -26,7 +26,7 @@ it('caps configured claim wait below the runner request timeout', () => {
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const created = await createAgent(asOwner, 'MKT', {
name: 'Ext Bot',
username: 'ext',
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/agent-analytics.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/agent-analytics.test.ts
index 6ebf570c..0ffae180 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/agent-analytics.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/agent-analytics.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { SpanType } from '@mastra/core/observability';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent, projectIdOf, teamOf } from '#tests/helpers/agents';
@@ -18,7 +18,7 @@ import { getStore } from '../../runtime/store';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, teamId: await teamOf(asOwner, 'MKT') };
}
@@ -96,10 +96,6 @@ const teamDashboard = (api: Api, teamId: number) => api.teams({ teamId })['agent
const workspaceDashboard = (api: Api, workspaceId: number) =>
api.workspaces({ workspaceId })['agent-analytics'];
-async function ownWorkspaceId(api: Api): Promise<number> {
- return (await api.workspaces.get()).data!.find((one) => one.role === 'owner')!.id;
-}
-
describe('agent analytics', () => {
beforeEach(async () => {
await resetDb();
@@ -146,7 +142,7 @@ describe('agent analytics', () => {
it('splits the window by project', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const agentId = await createScout(asOwner);
const mkt = await projectIdOf(asOwner, 'MKT');
const ops = await projectIdOf(asOwner, 'OPS');
@@ -168,7 +164,7 @@ describe('agent analytics', () => {
it('narrows the window to one project', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const agentId = await createScout(asOwner);
const mkt = await projectIdOf(asOwner, 'MKT');
const ops = await projectIdOf(asOwner, 'OPS');
@@ -244,7 +240,7 @@ describe('agent analytics', () => {
it('shows a member with usage only the projects where their role grants it', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const agentId = await createScout(asOwner);
const usage = { inputTokens: 100, outputTokens: 0 };
const mkt = await projectIdOf(asOwner, 'MKT');
@@ -268,7 +264,13 @@ describe('agent analytics', () => {
it('reads every team of the workspace and compares them', async () => {
const { asOwner, teamId } = await setup();
- const ops = (await asOwner.teams.post({ name: 'Ops', slug: 'ops' })).data!;
+ const ops = (
+ await asOwner.teams.post({
+ name: 'Ops',
+ slug: 'ops',
+ workspaceId: await ownWorkspaceId(asOwner),
+ })
+ ).data!;
const meta = {
agentId: await createScout(asOwner),
projectId: await projectIdOf(asOwner, 'MKT'),
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/agent-runs.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/agent-runs.test.ts
index 1d0edc7a..f7546f7d 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/agent-runs.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/agent-runs.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent, projectIdOf, teamOf } from '#tests/helpers/agents';
@@ -17,7 +17,7 @@ import { addProjectMember } from '#tests/helpers/members';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data!.columns[0].id;
return { owner, asOwner, columnId, teamId: project.data!.teamId };
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts
index 9f909348..fc402d0a 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/agent-threads.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import type { MastraMessagePart } from '@mastra/core/agent/message-list';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { ensureThread, buildMemory } from '../../runtime/memory';
@@ -25,7 +25,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner };
}
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/agent-traces.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/agent-traces.test.ts
index c7344d79..4d13e6fd 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/agent-traces.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/agent-traces.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { SpanType } from '@mastra/core/observability';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent, projectIdOf, teamOf } from '#tests/helpers/agents';
@@ -22,7 +22,7 @@ import { setAgentSettings } from '#modules/settings/service';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, teamId: await teamOf(asOwner, 'MKT') };
}
@@ -145,7 +145,7 @@ describe('agent traces', () => {
it('gives a member only the traces of a project they belong to', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const agent = await createInternalAgent(asOwner, 'Scout', 'scout');
const mkt = await projectIdOf(asOwner, 'MKT');
const ops = await projectIdOf(asOwner, 'OPS');
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts
index bfc1464d..2cd154c9 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { apikey, db } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import { apiKeyApi, authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { createRole, listProjectRoles } from '#tests/helpers/roles';
import { addProjectMember } from '#tests/helpers/members';
import { signUpTestUser } from '#tests/helpers/auth';
@@ -22,7 +22,7 @@ import { getMastra } from '../../runtime/observability';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner, teamId: project.data!.teamId };
}
@@ -189,7 +189,11 @@ describe('ai agents', () => {
it("rejects another team's model credential with 400", async () => {
const { asOwner } = await setup();
- const otherTeam = await asOwner.teams.post({ name: 'Engineering', slug: 'engineering' });
+ const otherTeam = await asOwner.teams.post({
+ name: 'Engineering',
+ slug: 'engineering',
+ workspaceId: await ownWorkspaceId(asOwner),
+ });
await asOwner.teams({ teamId: otherTeam.data!.id }).projects.post({
key: 'ENG',
name: 'Engineering',
@@ -823,14 +827,14 @@ describe('ai agents', () => {
// A second account addresses the agent through its own team, where the store finds
// nothing: every lookup is scoped to (agentId, teamId).
const second = authedApi((await signUpTestUser()).cookie);
- const otherProject = await second.projects.post({ key: 'ENG', name: 'Engineering' });
+ const otherProject = await createProject(second, { key: 'ENG', name: 'Engineering' });
const res = await agents(second, otherProject.data!.teamId)({ agentId }).patch({ name: 'x' });
expect(res.status).toBe(404);
});
it('lists only the agents working in the project the filter names', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'ENG', name: 'Engineering' });
+ await createProject(asOwner, { key: 'ENG', name: 'Engineering' });
await createAgent(asOwner, 'MKT', { name: 'Mkt Bot', username: 'mkt-bot', kind: 'external' });
await createAgent(asOwner, 'ENG', { name: 'Eng Bot', username: 'eng-bot', kind: 'external' });
@@ -844,7 +848,7 @@ describe('ai agents', () => {
it('attaches an agent to a second project and detaches it again', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'ENG', name: 'Engineering' });
+ await createProject(asOwner, { key: 'ENG', name: 'Engineering' });
const created = await createAgent(asOwner, 'MKT', {
name: 'Bot',
username: 'bot',
@@ -874,7 +878,7 @@ describe('ai agents', () => {
kind: 'external',
});
const second = authedApi((await signUpTestUser()).cookie);
- await second.projects.post({ key: 'ENG', name: 'Engineering' });
+ await createProject(second, { key: 'ENG', name: 'Engineering' });
const res = await agents(
asOwner,
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/mention-runs.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/mention-runs.test.ts
index 4b5ef1e9..32f4d168 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/mention-runs.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/mention-runs.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { db, agentRun } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -22,7 +22,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data!.columns[0].id;
return { owner, asOwner, columnId, teamId: project.data!.teamId };
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts
index 942a3212..55a8b078 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it } from 'bun:test';
import { db, aiAgent, apikey, teamMember } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { getProjectByRef } from '#modules/projects/service';
@@ -26,7 +26,7 @@ const agents = (api: Api, teamId: number) => api.teams({ teamId })['ai-agents'];
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner, teamId: project.data!.teamId };
}
@@ -101,7 +101,7 @@ describe('internal agent route tools', () => {
it('binds projectKey: it is not asked of the model and cannot be redirected', async () => {
const { asOwner } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data?.columns[0]?.id;
if (columnId === undefined) throw new Error('Test project has no columns');
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/run-admission.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/run-admission.test.ts
index 208f03cd..e9112705 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/run-admission.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/run-admission.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
import { db, agentRun } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { apiKeyApi, authedApi } from '#tests/helpers/app';
+import { apiKeyApi, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { clearLimits, setLimits } from '#tests/helpers/limits';
@@ -16,7 +16,7 @@ import { setRunAdmission, type RunForAdmission } from '../../run-admission';
async function setup(kind: 'internal' | 'external') {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const columnId = (await asOwner.projects({ projectKey: 'MKT' }).get()).data!.columns[0].id;
const created = await createAgent(asOwner, 'MKT', { name: 'Bot', username: 'bot', kind });
const agent = created.data!.agent;
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/run-limits.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/run-limits.test.ts
index 03d15a8e..d81c11d3 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/run-limits.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/run-limits.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
import { db, agentRun } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { clearLimits, setLimits } from '#tests/helpers/limits';
@@ -21,7 +21,7 @@ import { processAgentRuns } from '../../run-poller';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data!.columns[0].id;
const agent = (
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/run-queue.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/run-queue.test.ts
index e0cbdd67..57ed86da 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/run-queue.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/run-queue.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { db, agentRun } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent, teamOf } from '#tests/helpers/agents';
@@ -22,7 +22,7 @@ import {
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data!.columns[0].id;
return { asOwner, columnId };
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/run-refusal.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/run-refusal.test.ts
index 71b12b8b..af325373 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/run-refusal.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/run-refusal.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
import { db, agentRun, issueActivity } from '@repo/db';
import { and, eq } from 'drizzle-orm';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -16,7 +16,7 @@ const REASON = 'The agent budget is spent';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = (await asOwner.projects.post({ key: 'MKT', name: 'Marketing' })).data!;
+ const project = (await createProject(asOwner, { key: 'MKT', name: 'Marketing' })).data!;
const columnId = (await asOwner.projects({ projectKey: 'MKT' }).get()).data!.columns[0].id;
const agent = (
await createAgent(asOwner, 'MKT', { name: 'Bot', username: 'bot', kind: 'internal' })
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/run-step-limit.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/run-step-limit.test.ts
index ccb12725..5ef023c3 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/run-step-limit.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/run-step-limit.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -72,7 +72,7 @@ describe('agent run step limit', () => {
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const credentialId = await createCredential(asOwner, 'MKT', {
integrationKey: 'openai-compatible',
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/run-timeout.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/run-timeout.test.ts
index 3945c5e7..bd53532d 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/run-timeout.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/run-timeout.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
import { db, agentRun } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { clearLimits, setLimits } from '#tests/helpers/limits';
@@ -31,7 +31,7 @@ describe('agent run timeout', () => {
it('ends a run that exhausts its time as failed and does not retry it', async () => {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const credentialId = await createCredential(asOwner, 'MKT', {
integrationKey: 'openai-compatible',
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/thread-cleanup.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/thread-cleanup.test.ts
index 5ce3051e..35eb2c1d 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/thread-cleanup.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/thread-cleanup.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { db } from '@repo/db';
import { sql } from 'drizzle-orm';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { ensureThread, buildMemory } from '../../runtime/memory';
@@ -18,7 +18,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
return { owner, asOwner, columnId: view.data!.columns[0].id, teamId: project.data!.teamId };
}
diff --git a/apps/api/src/modules/agents/integrations/__tests__/integration/integrations.test.ts b/apps/api/src/modules/agents/integrations/__tests__/integration/integrations.test.ts
index 3572634b..88b20b93 100644
--- a/apps/api/src/modules/agents/integrations/__tests__/integration/integrations.test.ts
+++ b/apps/api/src/modules/agents/integrations/__tests__/integration/integrations.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -15,7 +15,7 @@ import { createRole } from '#tests/helpers/roles';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner, teamId: project.data!.teamId };
}
diff --git a/apps/api/src/modules/agents/prices/__tests__/integration/model-prices.test.ts b/apps/api/src/modules/agents/prices/__tests__/integration/model-prices.test.ts
index b159f31a..8e819336 100644
--- a/apps/api/src/modules/agents/prices/__tests__/integration/model-prices.test.ts
+++ b/apps/api/src/modules/agents/prices/__tests__/integration/model-prices.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { SpanType } from '@mastra/core/observability';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent, projectIdOf, teamOf } from '#tests/helpers/agents';
@@ -16,7 +16,7 @@ import { getStore } from '../../../core/runtime/store';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const teamId = await teamOf(asOwner, 'MKT');
const agent = await createAgent(asOwner, 'MKT', {
name: 'Scout',
diff --git a/apps/api/src/modules/agents/runner/__tests__/integration/agent-runner.test.ts b/apps/api/src/modules/agents/runner/__tests__/integration/agent-runner.test.ts
index 7f31e2d9..1fc5df8f 100644
--- a/apps/api/src/modules/agents/runner/__tests__/integration/agent-runner.test.ts
+++ b/apps/api/src/modules/agents/runner/__tests__/integration/agent-runner.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import { apiKeyApi, authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent, teamOf } from '#tests/helpers/agents';
@@ -12,7 +12,7 @@ import { createAgent, teamOf } from '#tests/helpers/agents';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data!.columns[0].id;
const created = await createAgent(asOwner, 'MKT', {
diff --git a/apps/api/src/modules/agents/schedules/__tests__/integration/agent-schedules.test.ts b/apps/api/src/modules/agents/schedules/__tests__/integration/agent-schedules.test.ts
index e3db5d86..6434ac44 100644
--- a/apps/api/src/modules/agents/schedules/__tests__/integration/agent-schedules.test.ts
+++ b/apps/api/src/modules/agents/schedules/__tests__/integration/agent-schedules.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
-import { apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import { apiKeyApi, authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { untaggedRoutes } from '#tests/helpers/mcp';
@@ -15,7 +15,7 @@ const schedules = (api: Api, projectKey = 'MKT') => api.projects({ projectKey })
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
@@ -220,7 +220,7 @@ describe('agent schedules', () => {
it('rejects an agent of another project', async () => {
const { asOwner } = await setup();
- await asOwner.projects.post({ key: 'ENG', name: 'Engineering' });
+ await createProject(asOwner, { key: 'ENG', name: 'Engineering' });
const foreignId = await makeAgent(asOwner, { username: 'eng', projectKey: 'ENG' });
expect((await createSchedule(asOwner, foreignId)).status).toBe(400);
});
diff --git a/apps/api/src/modules/agents/schedules/__tests__/integration/schedule-extension.test.ts b/apps/api/src/modules/agents/schedules/__tests__/integration/schedule-extension.test.ts
index e2bb1e10..37887fa8 100644
--- a/apps/api/src/modules/agents/schedules/__tests__/integration/schedule-extension.test.ts
+++ b/apps/api/src/modules/agents/schedules/__tests__/integration/schedule-extension.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
import { HttpError } from '#shared/lib';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -16,7 +16,7 @@ const schedules = (api: Api, projectKey = 'MKT') => api.projects({ projectKey })
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const columns = (await asOwner.projects({ projectKey: 'MKT' }).get()).data!.columns;
const backlog = columns.find((c) => c.stateType === 'backlog')!;
const started = columns.find((c) => c.stateType === 'started')!;
@@ -139,7 +139,7 @@ describe('agent schedule extension', () => {
})
).data!;
const issue = (await createIssue(asOwner, backlog.id)).data!;
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const opsColumn = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!.columns[0];
const other = (await createIssue(asOwner, opsColumn.id, 'Elsewhere', 'OPS')).data!;
diff --git a/apps/api/src/modules/agents/schedules/__tests__/integration/status-schedules.test.ts b/apps/api/src/modules/agents/schedules/__tests__/integration/status-schedules.test.ts
index e652ce8e..5c270c24 100644
--- a/apps/api/src/modules/agents/schedules/__tests__/integration/status-schedules.test.ts
+++ b/apps/api/src/modules/agents/schedules/__tests__/integration/status-schedules.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { db, agentRun, issue as issueTable } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import { apiKeyApi, authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -15,7 +15,7 @@ const schedules = (api: Api) => api.projects({ projectKey: 'MKT' })['agent-sched
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const columns = (await asOwner.projects({ projectKey: 'MKT' }).get()).data!.columns;
const backlog = columns.find((c) => c.stateType === 'backlog')!;
const started = columns.find((c) => c.stateType === 'started')!;
@@ -74,7 +74,7 @@ describe('status agent schedules', () => {
it('refuses the fields of the other type and a missing required one', async () => {
const { asOwner, started, agent } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const opsColumn = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!.columns[0];
const withCron = await schedules(asOwner).post({
diff --git a/apps/api/src/modules/agents/skills/__tests__/integration/agent-skills.test.ts b/apps/api/src/modules/agents/skills/__tests__/integration/agent-skills.test.ts
index 988f5bb5..cd114700 100644
--- a/apps/api/src/modules/agents/skills/__tests__/integration/agent-skills.test.ts
+++ b/apps/api/src/modules/agents/skills/__tests__/integration/agent-skills.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { untaggedRoutes } from '#tests/helpers/mcp';
@@ -16,7 +16,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner, teamId: project.data!.teamId };
}
@@ -229,7 +229,11 @@ describe('agent skills', () => {
it('ignores a skill of another team when enabling skills on an agent', async () => {
const { asOwner, teamId } = await setup();
const mine = await skills(asOwner, teamId).post({ source: 'inline', markdown: SKILL_MD });
- const otherTeam = await asOwner.teams.post({ name: 'Design', slug: 'design' });
+ const otherTeam = await asOwner.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(asOwner),
+ });
const theirs = await skills(asOwner, otherTeam.data!.id).post({
source: 'inline',
markdown: SKILL_MD,
diff --git a/apps/api/src/modules/agents/tools/__tests__/integration/agent-tools.test.ts b/apps/api/src/modules/agents/tools/__tests__/integration/agent-tools.test.ts
index 3711f4a8..43fc6b36 100644
--- a/apps/api/src/modules/agents/tools/__tests__/integration/agent-tools.test.ts
+++ b/apps/api/src/modules/agents/tools/__tests__/integration/agent-tools.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createCredential } from '#tests/helpers/integrations';
@@ -16,7 +16,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { owner, asOwner, teamId: project.data!.teamId };
}
@@ -182,7 +182,11 @@ describe('agent tools', () => {
toolKey: 'jina_reader',
credentialId: await jinaCredential(asOwner),
});
- const otherTeam = await asOwner.teams.post({ name: 'Design', slug: 'design' });
+ const otherTeam = await asOwner.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(asOwner),
+ });
await asOwner
.teams({ teamId: otherTeam.data!.id })
.projects.post({ key: 'DSG', name: 'Design' });
diff --git a/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts b/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts
index 2326334a..96ca8703 100644
--- a/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts
+++ b/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser, type TestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { pulseRows } from '../../service';
@@ -17,7 +17,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setupProject() {
const owner: TestUser = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
const col: Record<string, number> = {};
diff --git a/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts b/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts
index 4806476a..56b27639 100644
--- a/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts
+++ b/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { clearLimits, setLimits } from '#tests/helpers/limits';
@@ -15,7 +15,7 @@ import { clearLimits, setLimits } from '#tests/helpers/limits';
async function setupIssue() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = view.data!.columns[0].id;
const issue = await asOwner
diff --git a/apps/api/src/modules/charts/__tests__/integration/charts.test.ts b/apps/api/src/modules/charts/__tests__/integration/charts.test.ts
index a4eda878..88ada7ca 100644
--- a/apps/api/src/modules/charts/__tests__/integration/charts.test.ts
+++ b/apps/api/src/modules/charts/__tests__/integration/charts.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -17,7 +17,7 @@ const spec = {
async function setupOwnerProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return asOwner;
}
diff --git a/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts b/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts
index c9171b5a..fd9db3ac 100644
--- a/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts
+++ b/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { readFileSync } from 'node:fs';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -11,7 +11,7 @@ import { resetDb } from '#tests/helpers/db';
async function setup() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
diff --git a/apps/api/src/modules/columns/__tests__/integration/autoAssign.test.ts b/apps/api/src/modules/columns/__tests__/integration/autoAssign.test.ts
index abd5b0b8..82593acd 100644
--- a/apps/api/src/modules/columns/__tests__/integration/autoAssign.test.ts
+++ b/apps/api/src/modules/columns/__tests__/integration/autoAssign.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { addProjectMember } from '#tests/helpers/members';
import { createAgent, teamOf } from '#tests/helpers/agents';
@@ -13,7 +13,7 @@ import { resetDb } from '#tests/helpers/db';
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, ownerId: owner.userId };
}
diff --git a/apps/api/src/modules/columns/__tests__/integration/columns.test.ts b/apps/api/src/modules/columns/__tests__/integration/columns.test.ts
index 791a54ff..46f580c0 100644
--- a/apps/api/src/modules/columns/__tests__/integration/columns.test.ts
+++ b/apps/api/src/modules/columns/__tests__/integration/columns.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -12,7 +12,7 @@ import { resetDb } from '#tests/helpers/db';
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
@@ -105,7 +105,7 @@ describe('columns', () => {
it('ignores ids that belong to another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const opsBefore = await columnsOf(asOwner, 'OPS');
const foreignId = opsBefore[0].id;
@@ -261,7 +261,7 @@ describe('columns', () => {
it('rejects a move whose target is in another project', async () => {
const { asOwner } = await setupProject();
const todo = await columnByName(asOwner, 'Todo');
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = (await columnsOf(asOwner, 'OPS'))[0];
const res = await asOwner
@@ -309,7 +309,7 @@ describe('columns', () => {
describe('cross-project isolation', () => {
it('does not patch a column that belongs to another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = await columnByName(asOwner, 'Todo', 'OPS');
const res = await asOwner
@@ -324,7 +324,7 @@ describe('columns', () => {
it('does not delete a column that belongs to another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = await columnByName(asOwner, 'Todo', 'OPS');
const res = await asOwner
diff --git a/apps/api/src/modules/columns/__tests__/integration/wipLimits.test.ts b/apps/api/src/modules/columns/__tests__/integration/wipLimits.test.ts
index b24d44eb..84c5df70 100644
--- a/apps/api/src/modules/columns/__tests__/integration/wipLimits.test.ts
+++ b/apps/api/src/modules/columns/__tests__/integration/wipLimits.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -14,7 +14,7 @@ import { resetDb } from '#tests/helpers/db';
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
diff --git a/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts b/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts
index 7f295418..b86fd9c3 100644
--- a/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts
+++ b/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -14,7 +14,7 @@ import { createAgent } from '#tests/helpers/agents';
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
@@ -39,7 +39,7 @@ function createType(client: Api, name: string, projectKey = 'MKT') {
async function setupWithIssue() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const issue = (
await asOwner.projects({ projectKey: 'MKT' }).issues.post({
@@ -125,7 +125,7 @@ describe('custom-fields', () => {
it('rejects a type-scoped field whose type belongs to another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreignType = (await createType(asOwner, 'Bug', 'OPS')).data!;
const res = await fields(asOwner).post({
@@ -495,7 +495,7 @@ describe('custom-fields', () => {
describe('cross-project isolation', () => {
it('does not patch a field from another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = (await fields(asOwner, 'OPS').post({ name: 'Foreign', fieldType: 'text' }))
.data!;
@@ -508,7 +508,7 @@ describe('custom-fields', () => {
it('does not delete a field from another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = (await fields(asOwner, 'OPS').post({ name: 'Foreign', fieldType: 'text' }))
.data!;
diff --git a/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts b/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts
index 05a6dccd..d4009a66 100644
--- a/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts
+++ b/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -21,7 +21,7 @@ function day(offset: number): string {
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
return {
@@ -120,7 +120,7 @@ describe('cycles', () => {
it('allows the same dates in another project', async () => {
const { asOwner } = await setup();
await createCycle(asOwner, { startDate: day(0), endDate: day(6) });
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const other = await asOwner
.projects({ projectKey: 'OPS' })
@@ -317,7 +317,7 @@ describe('cycles', () => {
it('rejects a cycle from another project', async () => {
const { asOwner, columnId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = (
await asOwner
.projects({ projectKey: 'OPS' })
@@ -430,7 +430,7 @@ describe('cycles', () => {
it('rejects a target cycle from another project', async () => {
const { asOwner } = await setup();
const cycle = (await createCycle(asOwner, {})).data!;
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = (
await asOwner
.projects({ projectKey: 'OPS' })
diff --git a/apps/api/src/modules/dashboards/__tests__/integration/dashboards.test.ts b/apps/api/src/modules/dashboards/__tests__/integration/dashboards.test.ts
index b8c6ea05..a4ff78d3 100644
--- a/apps/api/src/modules/dashboards/__tests__/integration/dashboards.test.ts
+++ b/apps/api/src/modules/dashboards/__tests__/integration/dashboards.test.ts
@@ -1,12 +1,12 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
async function setupOwnerProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, projectId: project.data!.id };
}
@@ -142,7 +142,7 @@ describe('dashboards', () => {
it('ignores ids that belong to another project', async () => {
const { asOwner } = await setupOwnerProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const mkt = (await asOwner.projects({ projectKey: 'MKT' }).dashboards.post({ name: 'Mine' }))
.data!;
// The OPS dashboard sits at position 0; the reorder below places its id at
diff --git a/apps/api/src/modules/documents/__tests__/integration/assets.test.ts b/apps/api/src/modules/documents/__tests__/integration/assets.test.ts
index 90f95468..7766e564 100644
--- a/apps/api/src/modules/documents/__tests__/integration/assets.test.ts
+++ b/apps/api/src/modules/documents/__tests__/integration/assets.test.ts
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from 'bun:test';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -9,7 +9,7 @@ type Client = ReturnType<typeof authedApi>;
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- const project = (await asOwner.projects.post({ key: 'MKT', name: 'Marketing' })).data!;
+ const project = (await createProject(asOwner, { key: 'MKT', name: 'Marketing' })).data!;
return { asOwner, owner, project };
}
diff --git a/apps/api/src/modules/documents/__tests__/integration/collaboration.test.ts b/apps/api/src/modules/documents/__tests__/integration/collaboration.test.ts
index 4d7db305..0b019b67 100644
--- a/apps/api/src/modules/documents/__tests__/integration/collaboration.test.ts
+++ b/apps/api/src/modules/documents/__tests__/integration/collaboration.test.ts
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -10,7 +10,7 @@ const contentJson = {
async function setup() {
const owner = await signUpTestUser();
const client = authedApi(owner.cookie);
- await client.projects.post({ key: 'DOC', name: 'Documents' });
+ await createProject(client, { key: 'DOC', name: 'Documents' });
const routes = client.projects({ projectKey: 'DOC' }).documents;
const created = await routes.post({ title: 'Shared', content: 'Hello world', contentJson });
const doc = routes({ documentId: created.data!.id });
diff --git a/apps/api/src/modules/documents/__tests__/integration/documents.test.ts b/apps/api/src/modules/documents/__tests__/integration/documents.test.ts
index a2fdf795..8a0d1508 100644
--- a/apps/api/src/modules/documents/__tests__/integration/documents.test.ts
+++ b/apps/api/src/modules/documents/__tests__/integration/documents.test.ts
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -9,7 +9,7 @@ type Client = ReturnType<typeof authedApi>;
async function setupOwnerProject(): Promise<{ api: Client; userId: string }> {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
return { api, userId: owner.userId };
}
@@ -114,7 +114,7 @@ describe('documents', () => {
.status,
).toBe(400);
- await api.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(api, { key: 'OPS', name: 'Operations' });
const other = (await documents(api, 'OPS').post({ title: 'Other' })).data!;
expect((await documents(api).post({ title: 'Invalid', parentId: other.id })).status).toBe(400);
expect(
@@ -559,7 +559,7 @@ describe('documents', () => {
expect((await documents(outsider).get({ query: {} })).status).toBe(403);
expect((await documents(outsider)({ documentId: document.id }).get()).status).toBe(403);
- await owner.api.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(owner.api, { key: 'OPS', name: 'Operations' });
expect((await documents(owner.api, 'OPS')({ documentId: document.id }).get()).status).toBe(404);
});
diff --git a/apps/api/src/modules/git/__tests__/integration/git-webhook.test.ts b/apps/api/src/modules/git/__tests__/integration/git-webhook.test.ts
index 772c34e8..26dbdf9e 100644
--- a/apps/api/src/modules/git/__tests__/integration/git-webhook.test.ts
+++ b/apps/api/src/modules/git/__tests__/integration/git-webhook.test.ts
@@ -1,7 +1,7 @@
import { createHmac } from 'node:crypto';
import { describe, it, expect, beforeEach } from 'bun:test';
import { app } from '../../../../app';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole, listProjectRoles } from '#tests/helpers/roles';
@@ -21,7 +21,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const settings = await asOwner.projects({ projectKey: 'MKT' }).settings.git.get();
await asOwner.projects({ projectKey: 'MKT' }).settings.git.patch({ enabled: true });
@@ -194,7 +194,7 @@ describe('Repository webhook', () => {
it('exposes connected development repositories from an issue', async () => {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const project = await asOwner.projects({ projectKey: 'MKT' }).get();
const issue = await createIssue(asOwner, project.data!.columns[0]!.id);
@@ -211,7 +211,7 @@ describe('Repository webhook', () => {
it('rejects linking from a repository outside the issue project', async () => {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const project = await asOwner.projects({ projectKey: 'MKT' }).get();
const issue = await createIssue(asOwner, project.data!.columns[0]!.id);
diff --git a/apps/api/src/modules/god/__tests__/integration/god-deactivate.test.ts b/apps/api/src/modules/god/__tests__/integration/god-deactivate.test.ts
index 78810d15..89a958e8 100644
--- a/apps/api/src/modules/god/__tests__/integration/god-deactivate.test.ts
+++ b/apps/api/src/modules/god/__tests__/integration/god-deactivate.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it } from 'bun:test';
import { auth } from '@repo/auth';
-import { apiKeyApi, app, authedApi } from '#tests/helpers/app';
+import { apiKeyApi, app, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { mcpAccessToken } from '#tests/helpers/mcp';
import { resetDb } from '#tests/helpers/db';
@@ -137,7 +137,7 @@ describe('god deactivate / reactivate', () => {
it("refuses to switch an agent's account", async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const botId = await createAgentUser(god, 'MKT');
expect((await god.api.god.users({ userId: botId }).deactivate.post()).status).toBe(403);
@@ -158,7 +158,7 @@ describe('god deactivate / reactivate', () => {
it('drops the pending invites the deactivated account created', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const inviter = await signUpTestUser({ team: false });
const invite = await god.api.projects({ projectKey: 'MKT' }).invites.post({
email: inviter.email,
diff --git a/apps/api/src/modules/god/__tests__/integration/god-project-defaults.test.ts b/apps/api/src/modules/god/__tests__/integration/god-project-defaults.test.ts
index 2c5fc094..343cce47 100644
--- a/apps/api/src/modules/god/__tests__/integration/god-project-defaults.test.ts
+++ b/apps/api/src/modules/god/__tests__/integration/god-project-defaults.test.ts
@@ -1,4 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
+import { createProject } from '#tests/helpers/app';
import { resetDb } from '#tests/helpers/db';
import { addUser, setup } from '../helpers';
@@ -50,7 +51,7 @@ describe('god project defaults', () => {
it('creates a project with MCP on under the default', async () => {
const { god } = await setup();
- const created = await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const settings = await god.api.projects({ projectKey: 'MKT' }).settings.get();
expect(created.status).toBe(201);
@@ -61,7 +62,7 @@ describe('god project defaults', () => {
const { god } = await setup();
await god.api.god['project-defaults'].put({ mcpEnabled: false });
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const settings = await god.api.projects({ projectKey: 'MKT' }).settings.get();
expect(settings.data?.mcpEnabled).toBe(false);
@@ -69,7 +70,7 @@ describe('god project defaults', () => {
it('leaves projects that already exist untouched', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const before = await god.api.projects({ projectKey: 'MKT' }).settings.get();
expect(before.data?.mcpEnabled).toBe(true);
@@ -84,7 +85,7 @@ describe('god project defaults', () => {
await god.api.god['project-defaults'].put({ mcpEnabled: false });
const alice = await addUser();
- await alice.api.projects.post({ key: 'ALC', name: 'Alice Only' });
+ await createProject(alice.api, { key: 'ALC', name: 'Alice Only' });
const settings = await alice.api.projects({ projectKey: 'ALC' }).settings.get();
expect(settings.data?.mcpEnabled).toBe(false);
diff --git a/apps/api/src/modules/god/__tests__/integration/god-projects.test.ts b/apps/api/src/modules/god/__tests__/integration/god-projects.test.ts
index c6bb2b27..c1bcd88b 100644
--- a/apps/api/src/modules/god/__tests__/integration/god-projects.test.ts
+++ b/apps/api/src/modules/god/__tests__/integration/god-projects.test.ts
@@ -1,4 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
+import { createProject } from '#tests/helpers/app';
import { resetDb } from '#tests/helpers/db';
import { addUser, createAgentUser, joinProject, setup } from '../helpers';
@@ -17,7 +18,7 @@ describe('god projects', () => {
describe('access', () => {
it('refuses both routes for a user who is not the instance owner', async () => {
const { god } = await setup();
- const created = await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const outsider = await addUser();
expect((await outsider.api.god.projects.get({ query: PAGE })).status).toBe(403);
@@ -31,7 +32,7 @@ describe('god projects', () => {
it('lists every project on the instance, including ones the owner is not in', async () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'ALC', name: 'Alice Only' });
+ await createProject(alice.api, { key: 'ALC', name: 'Alice Only' });
const res = await god.api.god.projects.get({ query: PAGE });
@@ -48,7 +49,7 @@ describe('god projects', () => {
it('counts what a project holds and when it was last active', async () => {
const { god } = await setup();
- const created = await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const project = created.data!;
const alice = await addUser({ email: '[email protected]' });
await joinProject(god, alice, 'MKT', 'member');
@@ -83,7 +84,7 @@ describe('god projects', () => {
it('counts an archived issue apart from the active ones', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const view = await god.api.projects({ projectKey: 'MKT' }).get();
const created = await god.api.projects({ projectKey: 'MKT' }).issues.post({
title: 'Old',
@@ -98,8 +99,8 @@ describe('god projects', () => {
it('matches the search term against the key or the name', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
- await god.api.projects.post({ key: 'ENG', name: 'Engineering' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'ENG', name: 'Engineering' });
const byKey = await god.api.god.projects.get({ query: { ...PAGE, search: 'mkt' } });
const byName = await god.api.god.projects.get({ query: { ...PAGE, search: 'engineer' } });
@@ -115,9 +116,9 @@ describe('god projects', () => {
it('pages with limit and offset while the total stays the full match count', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'ONE', name: 'One' });
- await god.api.projects.post({ key: 'TWO', name: 'Two' });
- await god.api.projects.post({ key: 'THR', name: 'Three' });
+ await createProject(god.api, { key: 'ONE', name: 'One' });
+ await createProject(god.api, { key: 'TWO', name: 'Two' });
+ await createProject(god.api, { key: 'THR', name: 'Three' });
const first = await god.api.god.projects.get({ query: { page: 1, pageSize: 2 } });
const second = await god.api.god.projects.get({ query: { page: 2, pageSize: 2 } });
@@ -147,7 +148,7 @@ describe('god projects', () => {
it('resolves an owner membership to full permissions', async () => {
const { god } = await setup();
const alice = await addUser({ name: 'Alice', email: '[email protected]' });
- const created = await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
const res = await god.api.god.projects({ projectId: created.data!.id }).get();
@@ -168,7 +169,7 @@ describe('god projects', () => {
it("resolves a member membership to the assigned role's matrix", async () => {
const { god } = await setup();
- const created = await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const bob = await addUser({ name: 'Bob', email: '[email protected]' });
await joinProject(god, bob, 'MKT', 'member');
@@ -183,7 +184,7 @@ describe('god projects', () => {
it("marks an agent's bot user as an agent", async () => {
const { god } = await setup();
- const created = await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const agentUserId = await createAgentUser(god, 'MKT');
const res = await god.api.god.projects({ projectId: created.data!.id }).get();
diff --git a/apps/api/src/modules/god/__tests__/integration/god-teams.test.ts b/apps/api/src/modules/god/__tests__/integration/god-teams.test.ts
index 874723c4..019cc769 100644
--- a/apps/api/src/modules/god/__tests__/integration/god-teams.test.ts
+++ b/apps/api/src/modules/god/__tests__/integration/god-teams.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { resetDb } from '#tests/helpers/db';
import { addUser, createAgentUser, setup, type Actor } from '../helpers';
+import { ownWorkspaceId, createProject } from '#tests/helpers/app';
// The instance team directory under god mode: listing every team on the instance with
// what it holds, and reading one with the projects it owns and everyone in it. These
@@ -47,7 +48,7 @@ describe('god teams', () => {
it('counts what a team holds', async () => {
const { god } = await setup();
const teamId = await ownTeamId(god);
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const view = await god.api.projects({ projectKey: 'MKT' }).get();
await god.api.projects({ projectKey: 'MKT' }).issues.post({
title: 'First',
@@ -71,7 +72,7 @@ describe('god teams', () => {
it('leaves an archived issue out of the count', async () => {
const { god } = await setup();
const teamId = await ownTeamId(god);
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const view = await god.api.projects({ projectKey: 'MKT' }).get();
const created = await god.api.projects({ projectKey: 'MKT' }).issues.post({
title: 'Old',
@@ -86,8 +87,16 @@ describe('god teams', () => {
it('matches the search term against the name', async () => {
const { god } = await setup();
- await god.api.teams.post({ name: 'Marketing', slug: 'marketing' });
- await god.api.teams.post({ name: 'Engineering', slug: 'engineering' });
+ await god.api.teams.post({
+ name: 'Marketing',
+ slug: 'marketing',
+ workspaceId: await ownWorkspaceId(god.api),
+ });
+ await god.api.teams.post({
+ name: 'Engineering',
+ slug: 'engineering',
+ workspaceId: await ownWorkspaceId(god.api),
+ });
const match = await god.api.god.teams.get({ query: { ...PAGE, search: 'market' } });
const noMatch = await god.api.god.teams.get({ query: { ...PAGE, search: 'nothing' } });
@@ -100,8 +109,16 @@ describe('god teams', () => {
it('pages with limit and offset while the total stays the full match count', async () => {
const { god } = await setup();
- await god.api.teams.post({ name: 'One', slug: 'one' });
- await god.api.teams.post({ name: 'Two', slug: 'two' });
+ await god.api.teams.post({
+ name: 'One',
+ slug: 'one',
+ workspaceId: await ownWorkspaceId(god.api),
+ });
+ await god.api.teams.post({
+ name: 'Two',
+ slug: 'two',
+ workspaceId: await ownWorkspaceId(god.api),
+ });
const first = await god.api.god.teams.get({ query: { page: 1, pageSize: 2 } });
const second = await god.api.god.teams.get({ query: { page: 2, pageSize: 2 } });
@@ -127,7 +144,7 @@ describe('god teams', () => {
it('returns the counts of the team', async () => {
const { god } = await setup();
const teamId = await ownTeamId(god);
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const res = await god.api.god.teams({ teamId }).get();
@@ -147,7 +164,7 @@ describe('god teams', () => {
it('lists the projects the team owns with what each holds', async () => {
const { god } = await setup();
const teamId = await ownTeamId(god);
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const view = await god.api.projects({ projectKey: 'MKT' }).get();
await god.api.projects({ projectKey: 'MKT' }).issues.post({
title: 'First',
@@ -169,8 +186,8 @@ describe('god teams', () => {
it('matches the search term against the key or the name, and pages', async () => {
const { god } = await setup();
const teamId = await ownTeamId(god);
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
- await god.api.projects.post({ key: 'ENG', name: 'Engineering' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'ENG', name: 'Engineering' });
const byKey = await god.api.god
.teams({ teamId })
@@ -201,7 +218,7 @@ describe('god teams', () => {
it('lists everyone in the team with their rank, and flags an agent', async () => {
const { god } = await setup();
const teamId = await ownTeamId(god);
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const agentUserId = await createAgentUser(god, 'MKT');
const res = await god.api.god.teams({ teamId }).members.get({ query: PAGE });
diff --git a/apps/api/src/modules/god/__tests__/integration/god-users.test.ts b/apps/api/src/modules/god/__tests__/integration/god-users.test.ts
index 1f789dbc..7c2c8489 100644
--- a/apps/api/src/modules/god/__tests__/integration/god-users.test.ts
+++ b/apps/api/src/modules/god/__tests__/integration/god-users.test.ts
@@ -1,6 +1,9 @@
import { describe, it, expect, beforeEach } from 'bun:test';
+import { eq } from 'drizzle-orm';
+import { db, team } from '@repo/db';
import { resetDb } from '#tests/helpers/db';
-import { addUser, createAgentUser, joinProject, setup } from '../helpers';
+import { ownWorkspaceId, createProject } from '#tests/helpers/app';
+import { addUser, createAgentUser, joinProject, setup, type Actor } from '../helpers';
// The instance user directory under god mode: listing every account on the instance,
// reading one with the projects it can reach, confirming an email address on the
@@ -10,6 +13,16 @@ import { addUser, createAgentUser, joinProject, setup } from '../helpers';
const ALL = { kind: 'all' as const, page: 1, pageSize: 50 };
+// Moves the person's team into the owner's workspace, so what they own there is outside
+// the workspaces they own.
+async function moveTeamTo(owner: Actor, person: Actor): Promise<void> {
+ const [own] = (await person.api.teams.get()).data!;
+ await db
+ .update(team)
+ .set({ workspaceId: await ownWorkspaceId(owner.api) })
+ .where(eq(team.id, own!.id));
+}
+
async function withoutDeadlock<T>(operation: Promise<T>): Promise<T> {
let timeout: ReturnType<typeof setTimeout> | undefined;
const timeoutResult = new Promise<never>((_resolve, reject) => {
@@ -45,7 +58,7 @@ describe('god users', () => {
describe('list — GET /god/users', () => {
it('reports the sign-in state and project count of each account', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const res = await god.api.god.users.get({ query: ALL });
@@ -67,7 +80,7 @@ describe('god users', () => {
it('lists people by default and agent bot users only when asked', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const agentUserId = await createAgentUser(god, 'MKT');
const humans = await god.api.god.users.get({
@@ -90,7 +103,7 @@ describe('god users', () => {
it('defaults to people when no kind is given', async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
await createAgentUser(god, 'MKT');
const res = await god.api.god.users.get({ query: {} });
@@ -146,7 +159,7 @@ describe('god users', () => {
it('resolves an owner membership to full permissions', async () => {
const { god } = await setup();
const alice = await addUser({ name: 'Alice', email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
const res = await god.api.god.users({ userId: alice.id }).get();
@@ -170,7 +183,7 @@ describe('god users', () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
const bob = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, bob, 'MKT', 'member');
const res = await god.api.god.users({ userId: bob.id }).get();
@@ -191,7 +204,7 @@ describe('god users', () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
const bob = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, bob, 'MKT', 'owner');
const res = await god.api.god.users({ userId: alice.id }).get();
@@ -261,7 +274,7 @@ describe('god users', () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
const bob = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, bob, 'MKT', 'owner');
const res = await god.api.god.users({ userId: alice.id }).delete();
@@ -276,7 +289,7 @@ describe('god users', () => {
it('removes private documents while public documents remain recoverable', async () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, god, 'MKT', 'owner');
const pages = alice.api.projects({ projectKey: 'MKT' }).documents;
const shared = (await pages.post({ title: 'Shared handbook' })).data!;
@@ -310,7 +323,7 @@ describe('god users', () => {
it('serializes a document upload with deletion of its uploader account', async () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, god, 'MKT', 'owner');
const pages = alice.api.projects({ projectKey: 'MKT' }).documents;
const privatePage = (await pages.post({ title: 'Private upload target', isPrivate: true }))
@@ -339,7 +352,7 @@ describe('god users', () => {
it('does not leave an ownerless private page during access change and account deletion', async () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, god, 'MKT', 'owner');
const pages = alice.api.projects({ projectKey: 'MKT' }).documents;
const page = (await pages.post({ title: 'Public draft' })).data!;
@@ -370,7 +383,7 @@ describe('god users', () => {
it('does not expose or orphan a private revision during account deletion', async () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, god, 'MKT', 'owner');
const pages = alice.api.projects({ projectKey: 'MKT' }).documents;
const privatePage = (
@@ -421,7 +434,7 @@ describe('god users', () => {
it("refuses to delete an agent's bot user", async () => {
const { god } = await setup();
- await god.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(god.api, { key: 'MKT', name: 'Marketing' });
const agentUserId = await createAgentUser(god, 'MKT');
const res = await god.api.god.users({ userId: agentUserId }).delete();
@@ -434,8 +447,9 @@ describe('god users', () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
const bob = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, bob, 'MKT', 'member');
+ await moveTeamTo(god, alice);
const res = await god.api.god.users({ userId: alice.id }).delete();
@@ -470,8 +484,9 @@ describe('god users', () => {
const { god } = await setup();
const alice = await addUser({ email: '[email protected]' });
const bob = await addUser({ email: '[email protected]' });
- await alice.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(alice.api, { key: 'MKT', name: 'Marketing' });
await joinProject(alice, bob, 'MKT', 'member');
+ await moveTeamTo(god, alice);
const res = await god.api.god
.users({ userId: alice.id })
@@ -490,7 +505,7 @@ describe('god users', () => {
const alice = await addUser({ email: '[email protected]' });
const bob = await addUser({ email: '[email protected]' });
// Bob owns OPS; Alice is only a member there, so it is not hers to take down.
- await bob.api.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(bob.api, { key: 'OPS', name: 'Operations' });
await joinProject(bob, alice, 'OPS', 'member');
const res = await god.api.god
diff --git a/apps/api/src/modules/god/index.ts b/apps/api/src/modules/god/index.ts
index 816ca052..feabf3bc 100644
--- a/apps/api/src/modules/god/index.ts
+++ b/apps/api/src/modules/god/index.ts
@@ -12,6 +12,9 @@ import {
hasConfiguredGoogle,
getOidcSettings,
setOidcSettings,
+ getScimSettings,
+ setScimSettings,
+ rotateScimToken,
hasConfiguredOidc,
} from '@repo/auth';
import { hasConfiguredEmailProvider, getStorageSettings } from '@repo/db';
@@ -23,6 +26,20 @@ import { accessErrors, commonErrors, errors } from '#shared/responses';
import { paginate } from '#shared/pagination';
import { noContent } from '#shared/http';
import { deleteProject } from '#modules/projects/service';
+import { SCIM_BASE_URL } from '#modules/scim/resource';
+import {
+ MappableProjectListResponse,
+ ScimGroupMappingsBody,
+ ProvisionedGroupResponse,
+ ScimSettingsBody,
+ ScimSettingsResponse,
+ ScimTokenResponse,
+} from '#modules/scim/model';
+import {
+ listMappableProjects,
+ listProvisionedGroups,
+ setGroupMappings,
+} from '#modules/scim/mappings';
import {
deleteInstanceUser,
getInstanceProject,
@@ -61,6 +78,7 @@ import {
deleteUserQuery,
listUsersQuery,
projectParams,
+ scimGroupParams,
searchPageQuery,
teamParams,
userParams,
@@ -87,9 +105,9 @@ import {
// God mode: instance-wide administration, open only to the "god" user (the first
// registered account). It covers how people may register, the mail provider that
-// sends authentication email, and the OAuth credentials. SCIM provisioning belongs to
-// a workspace and is set in its settings. Invites are per team (team_invite), managed in the team panel and in the project's Members
-// section — there is nothing instance-level to add here.
+// sends authentication email, the OAuth credentials, and the instance's SCIM
+// provisioning. Invites are per team (team_invite), managed in the team panel and in the
+// project's Members section — there is nothing instance-level to add here.
//
// The settings themselves are owned by @repo/auth, which reads them at sign-up and
// when sending mail; these routes only expose them over HTTP. Secrets are never
@@ -314,6 +332,80 @@ export const godRoutes = new Elysia({ name: 'god', detail: { tags: ['God'] } })
},
)
+ .get('/god/scim', async () => ({ ...(await getScimSettings(null)), baseUrl: SCIM_BASE_URL }), {
+ response: { 200: ScimSettingsResponse, ...errors(401, 403) },
+ detail: {
+ summary: 'Get SCIM provisioning settings',
+ description: 'Get whether SCIM provisioning is on and whether a token has been generated.',
+ },
+ })
+
+ .patch(
+ '/god/scim',
+ async ({ body }) => {
+ // Enabling it without a token would leave the endpoint answering 401 to
+ // everything, which reads as a broken integration rather than a missing step.
+ if (body.enabled && !(await getScimSettings(null)).hasToken) {
+ throw new HttpError(400, 'Generate a SCIM token first');
+ }
+ return { ...(await setScimSettings(null, body)), baseUrl: SCIM_BASE_URL };
+ },
+ {
+ body: ScimSettingsBody,
+ response: { 200: ScimSettingsResponse, ...errors(400, 401, 403) },
+ detail: {
+ summary: 'Update SCIM provisioning settings',
+ description: 'Turn SCIM provisioning on or off.',
+ },
+ },
+ )
+
+ .post('/god/scim/token', async () => ({ token: await rotateScimToken(null) }), {
+ response: { 200: ScimTokenResponse, ...errors(401, 403) },
+ detail: {
+ summary: 'Generate a SCIM token',
+ description:
+ 'Generate the bearer token an identity provider sends to /scim/v2, replacing any ' +
+ 'previous one. The value is returned once and cannot be read back.',
+ },
+ })
+
+ .get('/god/scim/groups', () => listProvisionedGroups(null), {
+ response: { 200: t.Array(ProvisionedGroupResponse), ...errors(401, 403) },
+ detail: {
+ summary: 'List provisioned groups',
+ description:
+ "The groups the instance's identity provider has pushed, with their member counts and " +
+ 'the projects they grant membership in.',
+ },
+ })
+
+ .put(
+ '/god/scim/groups/:groupId/mappings',
+ ({ params, body }) => setGroupMappings(null, params.groupId, body.mappings),
+ {
+ params: scimGroupParams,
+ body: ScimGroupMappingsBody,
+ response: { 200: ProvisionedGroupResponse, ...errors(400, 401, 403, 404) },
+ detail: {
+ summary: "Set a group's project mappings",
+ description:
+ 'Replace the projects a provisioned group grants membership in, then reconcile the ' +
+ 'membership of every project the change touched.',
+ },
+ },
+ )
+
+ .get('/god/scim/projects', () => listMappableProjects(null), {
+ response: { 200: MappableProjectListResponse, ...errors(401, 403) },
+ detail: {
+ summary: 'List mappable projects',
+ description:
+ 'Every project a provisioned group may grant, with the roles its team assigns, for ' +
+ 'the group mapping picker.',
+ },
+ })
+
.get('/god/storage-settings', () => getStorageSettings(), {
response: { 200: StorageSettingsSchema, ...errors(401, 403) },
detail: {
diff --git a/apps/api/src/modules/god/model.ts b/apps/api/src/modules/god/model.ts
index 4f79ea02..7a54ed1e 100644
--- a/apps/api/src/modules/god/model.ts
+++ b/apps/api/src/modules/god/model.ts
@@ -19,6 +19,8 @@ export const userParams = t.Object({ userId: t.String() });
export const projectParams = t.Object({ projectId: t.Numeric() });
+export const scimGroupParams = t.Object({ groupId: t.String() });
+
export const listUsersQuery = t.Object({
search: t.Optional(t.String()),
// Agent bot users are accounts too, but they are managed on a project's AI
diff --git a/apps/api/src/modules/import-export/__tests__/integration/import-export.test.ts b/apps/api/src/modules/import-export/__tests__/integration/import-export.test.ts
index 69094b90..9846caed 100644
--- a/apps/api/src/modules/import-export/__tests__/integration/import-export.test.ts
+++ b/apps/api/src/modules/import-export/__tests__/integration/import-export.test.ts
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from 'bun:test';
import { db, importJob } from '@repo/db';
import { eq } from 'drizzle-orm';
import { decryptSecret } from '@repo/crypto';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -12,7 +12,7 @@ type Client = ReturnType<typeof authedApi>;
async function setupOwnerProject(): Promise<{ api: Client; userId: string }> {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
return { api, userId: owner.userId };
}
diff --git a/apps/api/src/modules/imports/__tests__/integration/imports.test.ts b/apps/api/src/modules/imports/__tests__/integration/imports.test.ts
index dec611d7..de9f7d5c 100644
--- a/apps/api/src/modules/imports/__tests__/integration/imports.test.ts
+++ b/apps/api/src/modules/imports/__tests__/integration/imports.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import ExcelJS from 'exceljs';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { getProjectByRef } from '#modules/projects/service';
@@ -14,7 +14,7 @@ import { createMappedImport } from '../../service';
async function setup() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
@@ -146,7 +146,7 @@ describe('imports', () => {
it('refuses to map an attachment of another project', async () => {
const { asOwner } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const uploaded = await uploadWorkbook(asOwner, [['Task'], ['Only']]);
const ops = await getProjectByRef('OPS', '');
if (!ops) throw new Error('Test project was not created');
@@ -169,7 +169,7 @@ describe('imports', () => {
it('hides drafts of other projects', async () => {
const { asOwner } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const uploaded = await uploadWorkbook(asOwner, [['Task']]);
const draft = await mapImport(uploaded.data!.id, { title: 'Task' });
const wrong = await authedApi((await signUpTestUser()).cookie)
diff --git a/apps/api/src/modules/initiatives/__tests__/integration/initiative-attachments.test.ts b/apps/api/src/modules/initiatives/__tests__/integration/initiative-attachments.test.ts
index 4ba9ba12..4713bc37 100644
--- a/apps/api/src/modules/initiatives/__tests__/integration/initiative-attachments.test.ts
+++ b/apps/api/src/modules/initiatives/__tests__/integration/initiative-attachments.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { clearLimits, setLimits } from '#tests/helpers/limits';
@@ -11,7 +11,7 @@ import { clearLimits, setLimits } from '#tests/helpers/limits';
async function setupInitiative() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const created = await asOwner
.projects({ projectKey: 'MKT' })
.initiatives.post({ title: 'Q3 Launch' });
diff --git a/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts b/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts
index 60555f22..3f189e9a 100644
--- a/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts
+++ b/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -13,7 +13,7 @@ import { createRole } from '#tests/helpers/roles';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
const columnId = columns[0].id;
@@ -110,7 +110,7 @@ describe('initiatives', () => {
it('rejects an owner and labels from another project before creating', async () => {
const { asOwner } = await setup();
const outsider = await signUpTestUser({ name: 'Outsider' });
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreignLabel = (
await asOwner.projects({ projectKey: 'OPS' }).labels.post({ name: 'ops' })
).data!;
@@ -342,7 +342,7 @@ describe('initiatives', () => {
it('rejects linking an issue to an initiative from another project', async () => {
const { asOwner, columnId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const otherInitiative = (
await asOwner.projects({ projectKey: 'OPS' }).initiatives.post({ title: 'Other' })
).data!;
diff --git a/apps/api/src/modules/invites/__tests__/integration/invite-expiry.test.ts b/apps/api/src/modules/invites/__tests__/integration/invite-expiry.test.ts
index c9305850..7a04cc29 100644
--- a/apps/api/src/modules/invites/__tests__/integration/invite-expiry.test.ts
+++ b/apps/api/src/modules/invites/__tests__/integration/invite-expiry.test.ts
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from 'bun:test';
import { auth, setAuthSettings } from '@repo/auth';
import { db, teamInvite } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { createRole } from '#tests/helpers/roles';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -12,7 +12,7 @@ import { resetDb } from '#tests/helpers/db';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, teamId: project.data!.teamId };
}
@@ -289,7 +289,7 @@ describe('renewing an expired invite', () => {
it('does not renew from a project or a team the invite does not belong to', async () => {
const { asOwner, teamId } = await setup();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const elsewhere = await asOwner
.projects({ projectKey: 'OPS' })
.invites.post({ email: '[email protected]', role: 'member' });
@@ -299,7 +299,7 @@ describe('renewing an expired invite', () => {
const other = await signUpTestUser({ name: 'Other' });
const asOther = authedApi(other.cookie);
- const otherTeam = (await asOther.projects.post({ key: 'OTH', name: 'Other' })).data!.teamId;
+ const otherTeam = (await createProject(asOther, { key: 'OTH', name: 'Other' })).data!.teamId;
const foreign = await asOther
.teams({ teamId: otherTeam })
.invites.post({ email: '[email protected]', role: 'member' });
diff --git a/apps/api/src/modules/invites/__tests__/integration/invites.test.ts b/apps/api/src/modules/invites/__tests__/integration/invites.test.ts
index 8b269e4d..e9281b57 100644
--- a/apps/api/src/modules/invites/__tests__/integration/invites.test.ts
+++ b/apps/api/src/modules/invites/__tests__/integration/invites.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser, type TestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -20,7 +20,7 @@ async function setupOwner(): Promise<{
}> {
const user = await signUpTestUser();
const api = authedApi(user.cookie);
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
return { user, api, projectId: project.data!.id };
}
@@ -160,7 +160,7 @@ describe('invites', () => {
// Every project of a team shares its roles, so only a role of another team is
// out of reach here.
const stranger = authedApi((await signUpTestUser()).cookie);
- await stranger.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(stranger, { key: 'OPS', name: 'Operations' });
const foreign = await createRole(stranger, 'OPS', { name: 'Ops', permissions: {} });
const res = await owner.api
diff --git a/apps/api/src/modules/issue-templates/__tests__/integration/issue-templates.test.ts b/apps/api/src/modules/issue-templates/__tests__/integration/issue-templates.test.ts
index 05c3f0d0..39a34e85 100644
--- a/apps/api/src/modules/issue-templates/__tests__/integration/issue-templates.test.ts
+++ b/apps/api/src/modules/issue-templates/__tests__/integration/issue-templates.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -18,7 +18,7 @@ function templates(client: Api, projectKey = 'MKT') {
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const scaffold = (await asOwner.projects({ projectKey: 'MKT' }).get()).data!;
const label = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'bug' })).data!;
const type = (await asOwner.projects({ projectKey: 'MKT' })['issue-types'].post({ name: 'Bug' }))
@@ -103,7 +103,7 @@ describe('issue-templates', () => {
it('rejects a preset that belongs to another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const other = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!;
const created = await templates(asOwner).post({
@@ -136,7 +136,7 @@ describe('issue-templates', () => {
it('does not list a template of another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
await templates(asOwner).post({ name: 'Bug report' });
expect(await listTemplates(asOwner, 'OPS')).toEqual([]);
@@ -178,7 +178,7 @@ describe('issue-templates', () => {
it('answers 404 for a template of another project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const created = (await templates(asOwner).post({ name: 'Bug report' })).data!;
const updated = await templates(
diff --git a/apps/api/src/modules/issue-types/__tests__/integration/issue-types.test.ts b/apps/api/src/modules/issue-types/__tests__/integration/issue-types.test.ts
index 3d6b2f17..68392b83 100644
--- a/apps/api/src/modules/issue-types/__tests__/integration/issue-types.test.ts
+++ b/apps/api/src/modules/issue-types/__tests__/integration/issue-types.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -12,7 +12,7 @@ import { resetDb } from '#tests/helpers/db';
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
@@ -95,7 +95,7 @@ describe('issue-types', () => {
it('allows the same name in a different project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
await asOwner.projects({ projectKey: 'MKT' })['issue-types'].post({ name: 'Bug' });
const res = await asOwner
.projects({ projectKey: 'OPS' })
@@ -222,7 +222,7 @@ describe('issue-types', () => {
describe('cross-project isolation', () => {
async function twoProjects() {
const { asOwner: api } = await setupProject();
- await api.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(api, { key: 'OPS', name: 'Operations' });
const foreign = (
await api.projects({ projectKey: 'OPS' })['issue-types'].post({ name: 'Bug' })
).data!;
diff --git a/apps/api/src/modules/issues/__tests__/integration/activity.test.ts b/apps/api/src/modules/issues/__tests__/integration/activity.test.ts
index 686c9e55..b3e0fde0 100644
--- a/apps/api/src/modules/issues/__tests__/integration/activity.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/activity.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser, type TestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -19,7 +19,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnIds = view.data!.columns.map((c) => c.id);
return { asOwner, owner, columnId: columnIds[0], columnIds };
@@ -396,7 +396,7 @@ describe('issue activity', () => {
it("does not log the name of another project's label", async () => {
const { asOwner, columnId } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const foreign = (
await asOwner.projects({ projectKey: 'OPS' }).labels.post({ name: 'ops-secret' })
).data!;
diff --git a/apps/api/src/modules/issues/__tests__/integration/auto-archive.test.ts b/apps/api/src/modules/issues/__tests__/integration/auto-archive.test.ts
index 62b70166..b2bde7e9 100644
--- a/apps/api/src/modules/issues/__tests__/integration/auto-archive.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/auto-archive.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { db, issue } from '@repo/db';
import { eq, sql } from 'drizzle-orm';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { sweepStaleIssues } from '../../auto-archive';
@@ -13,7 +13,7 @@ import { sweepStaleIssues } from '../../auto-archive';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const api = authedApi(owner.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const columns = (await api.projects({ projectKey: 'MKT' }).get()).data!.columns;
const done = columns.find((c) => c.stateType === 'completed')!;
const todo = columns.find((c) => c.stateType === 'unstarted')!;
diff --git a/apps/api/src/modules/issues/__tests__/integration/checklists.test.ts b/apps/api/src/modules/issues/__tests__/integration/checklists.test.ts
index c3d36030..8a15671b 100644
--- a/apps/api/src/modules/issues/__tests__/integration/checklists.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/checklists.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { untaggedRoutes } from '#tests/helpers/mcp';
@@ -18,7 +18,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
return { asOwner, columnId: view.data!.columns[0].id };
}
diff --git a/apps/api/src/modules/issues/__tests__/integration/cycle-history.test.ts b/apps/api/src/modules/issues/__tests__/integration/cycle-history.test.ts
index 73f124ea..43d9b425 100644
--- a/apps/api/src/modules/issues/__tests__/integration/cycle-history.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/cycle-history.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -14,7 +14,7 @@ function day(offset: number): string {
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
return {
diff --git a/apps/api/src/modules/issues/__tests__/integration/issues.test.ts b/apps/api/src/modules/issues/__tests__/integration/issues.test.ts
index 75718c21..2a98770c 100644
--- a/apps/api/src/modules/issues/__tests__/integration/issues.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/issues.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -23,7 +23,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnIds = view.data!.columns.map((c) => c.id);
return { asOwner, ownerUserId: owner.userId, columnId: columnIds[0], columnIds };
@@ -35,7 +35,7 @@ function createIssue(client: Api, columnId: number, patch: Record<string, unknow
// A label of a second project, which no issue of the first one may carry.
async function foreignLabel(client: Api) {
- await client.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(client, { key: 'OPS', name: 'Operations' });
const res = await client.projects({ projectKey: 'OPS' }).labels.post({ name: 'ops-secret' });
return res.data!;
}
@@ -43,7 +43,7 @@ async function foreignLabel(client: Api) {
// A column and an issue type of a second project, which no issue of the first one
// may point at.
async function foreignProject(client: Api) {
- await client.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(client, { key: 'OPS', name: 'Operations' });
const view = await client.projects({ projectKey: 'OPS' }).get();
const type = await client
.projects({ projectKey: 'OPS' })
@@ -627,7 +627,7 @@ describe('issues', () => {
// A project-wide field (no issueTypeId) of a second project, which must stay
// invisible to the issues of the first one.
async function foreignField(client: Api) {
- await client.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(client, { key: 'OPS', name: 'Operations' });
const res = await client
.projects({ projectKey: 'OPS' })
['custom-fields'].post({ name: 'Source URL', fieldType: 'text' });
@@ -1211,7 +1211,7 @@ describe('issues', () => {
it('does not find issues from another project', async () => {
const { asOwner, columnId } = await setupProject();
await createIssue(asOwner, columnId, { title: 'Kestrel here' });
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const opsCols = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!.columns;
await asOwner
.projects({ projectKey: 'OPS' })
@@ -1432,7 +1432,7 @@ describe('issues', () => {
const mine = (await createIssue(asOwner, columnId)).data!;
// A second project owned by the same user; its issue must not be touched by a
// bulk action scoped to the first project.
- await asOwner.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const opsColumn = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!.columns[0].id;
const foreign = (
await asOwner
diff --git a/apps/api/src/modules/issues/__tests__/integration/links.test.ts b/apps/api/src/modules/issues/__tests__/integration/links.test.ts
index 8e537ff0..c205b730 100644
--- a/apps/api/src/modules/issues/__tests__/integration/links.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/links.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { type IssueLinkInputKind } from '../../links';
@@ -20,7 +20,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
return { asOwner, columnId: view.data!.columns[0].id };
}
@@ -52,7 +52,7 @@ function unlink(client: Api, issueId: number, linkId: number) {
// An issue of a second project, which no issue of the first one may link to.
async function foreignIssue(client: Api) {
- await client.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(client, { key: 'OPS', name: 'Operations' });
const view = await client.projects({ projectKey: 'OPS' }).get();
const res = await client
.projects({ projectKey: 'OPS' })
diff --git a/apps/api/src/modules/issues/__tests__/integration/move.test.ts b/apps/api/src/modules/issues/__tests__/integration/move.test.ts
index 3097a96c..6fa2516d 100644
--- a/apps/api/src/modules/issues/__tests__/integration/move.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/move.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -10,8 +10,8 @@ import { resetDb } from '#tests/helpers/db';
async function setup() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
- const ops = (await asOwner.projects.post({ key: 'OPS', name: 'Operations' })).data!;
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
+ const ops = (await createProject(asOwner, { key: 'OPS', name: 'Operations' })).data!;
const mkt = (await asOwner.projects({ projectKey: 'MKT' }).get()).data!;
const opsView = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!;
return { asOwner, ops, mktColumns: mkt.columns, opsColumns: opsView.columns };
@@ -160,7 +160,13 @@ describe('move issue', () => {
.move.post({ projectId: mkt.project.id });
expect(same.status).toBe(400);
- const team = (await asOwner.teams.post({ name: 'Second', slug: 'second' })).data!;
+ const team = (
+ await asOwner.teams.post({
+ name: 'Second',
+ slug: 'second',
+ workspaceId: await ownWorkspaceId(asOwner),
+ })
+ ).data!;
const other = (
await asOwner.teams({ teamId: team.id }).projects.post({ key: 'SEC', name: 'Second' })
).data!;
diff --git a/apps/api/src/modules/issues/__tests__/integration/status-history.test.ts b/apps/api/src/modules/issues/__tests__/integration/status-history.test.ts
index 0b7f5ea8..2729d9fc 100644
--- a/apps/api/src/modules/issues/__tests__/integration/status-history.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/status-history.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -11,7 +11,7 @@ import { resetDb } from '#tests/helpers/db';
async function setup() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
return {
diff --git a/apps/api/src/modules/issues/__tests__/integration/subtasks.test.ts b/apps/api/src/modules/issues/__tests__/integration/subtasks.test.ts
index 2a7e9534..aba88a3f 100644
--- a/apps/api/src/modules/issues/__tests__/integration/subtasks.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/subtasks.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -20,7 +20,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
const byState = (stateType: string) => columns.find((c) => c.stateType === stateType)!.id;
@@ -72,7 +72,7 @@ async function read(client: Api, issueId: number) {
// An issue of a second project, which no issue of the first one may hang under.
async function foreignIssue(client: Api) {
- await client.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(client, { key: 'OPS', name: 'Operations' });
const view = await client.projects({ projectKey: 'OPS' }).get();
const res = await client
.projects({ projectKey: 'OPS' })
diff --git a/apps/api/src/modules/issues/__tests__/integration/watchers.test.ts b/apps/api/src/modules/issues/__tests__/integration/watchers.test.ts
index 14d4f7f0..943e51b8 100644
--- a/apps/api/src/modules/issues/__tests__/integration/watchers.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/watchers.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { db, issueWatcher } from '@repo/db';
import { and, eq } from 'drizzle-orm';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -24,7 +24,7 @@ interface Member {
async function setup(): Promise<{ owner: Member; columnId: number }> {
const u = await signUpTestUser();
const api = authedApi(u.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const view = await api.projects({ projectKey: 'MKT' }).get();
return {
owner: { api, userId: u.userId, username: u.username },
diff --git a/apps/api/src/modules/issues/__tests__/integration/worklogs.test.ts b/apps/api/src/modules/issues/__tests__/integration/worklogs.test.ts
index 88fcfd04..c827c2c8 100644
--- a/apps/api/src/modules/issues/__tests__/integration/worklogs.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/worklogs.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { addProjectMember } from '#tests/helpers/members';
import { resetDb } from '#tests/helpers/db';
@@ -18,7 +18,7 @@ interface Setup {
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
return { asOwner, columnId: view.data!.columns[0].id };
}
diff --git a/apps/api/src/modules/labels/__tests__/integration/labels.test.ts b/apps/api/src/modules/labels/__tests__/integration/labels.test.ts
index 5eb032d1..48e2b948 100644
--- a/apps/api/src/modules/labels/__tests__/integration/labels.test.ts
+++ b/apps/api/src/modules/labels/__tests__/integration/labels.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -14,7 +14,7 @@ import { resetDb } from '#tests/helpers/db';
async function setupProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner };
}
@@ -100,7 +100,7 @@ describe('labels', () => {
it('allows the same name in a different project', async () => {
const { asOwner } = await setupProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'urgent' });
const res = await asOwner.projects({ projectKey: 'OPS' }).labels.post({ name: 'urgent' });
expect(res.status).toBe(201);
@@ -363,7 +363,7 @@ describe('labels', () => {
describe('cross-project isolation', () => {
async function twoProjects() {
const { asOwner: api } = await setupProject();
- await api.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(api, { key: 'OPS', name: 'Operations' });
const label = (await api.projects({ projectKey: 'OPS' }).labels.post({ name: 'urgent' }))
.data!;
const group = (
diff --git a/apps/api/src/modules/members/__tests__/integration/members.test.ts b/apps/api/src/modules/members/__tests__/integration/members.test.ts
index 07e7482a..4ec32f8f 100644
--- a/apps/api/src/modules/members/__tests__/integration/members.test.ts
+++ b/apps/api/src/modules/members/__tests__/integration/members.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser, type TestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole, listProjectRoles } from '#tests/helpers/roles';
@@ -19,7 +19,7 @@ type Actor = { user: TestUser; api: ReturnType<typeof authedApi> };
async function setupOwner(): Promise<Actor> {
const user = await signUpTestUser();
const api = authedApi(user.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
return { user, api };
}
@@ -28,7 +28,7 @@ async function setupOwner(): Promise<Actor> {
async function setupOwner2(): Promise<Actor> {
const user = await signUpTestUser();
const api = authedApi(user.cookie);
- await api.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(api, { key: 'OPS', name: 'Operations' });
return { user, api };
}
diff --git a/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts b/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts
index ef638ed7..e7f7af3c 100644
--- a/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts
+++ b/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -10,7 +10,7 @@ type Client = ReturnType<typeof authedApi>;
async function setupOwnerProject(): Promise<{ api: Client; userId: string }> {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
return { api, userId: owner.userId };
}
diff --git a/apps/api/src/modules/notifications/__tests__/integration/notifications.test.ts b/apps/api/src/modules/notifications/__tests__/integration/notifications.test.ts
index a9bf38e1..91513f96 100644
--- a/apps/api/src/modules/notifications/__tests__/integration/notifications.test.ts
+++ b/apps/api/src/modules/notifications/__tests__/integration/notifications.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -17,7 +17,7 @@ interface Member {
async function setup(): Promise<{ owner: Member; columnId: number; doneColumnId: number }> {
const u = await signUpTestUser();
const api = authedApi(u.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const view = await api.projects({ projectKey: 'MKT' }).get();
const columns = view.data!.columns;
const done = columns.find((c) => c.stateType === 'completed') ?? columns[columns.length - 1];
diff --git a/apps/api/src/modules/projects/__tests__/integration/discovery.test.ts b/apps/api/src/modules/projects/__tests__/integration/discovery.test.ts
index e5980b0a..db5b2767 100644
--- a/apps/api/src/modules/projects/__tests__/integration/discovery.test.ts
+++ b/apps/api/src/modules/projects/__tests__/integration/discovery.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it } from 'bun:test';
import { auth } from '@repo/auth';
-import { app, authedApi, type Api } from '#tests/helpers/app';
+import { app, authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -28,10 +28,10 @@ describe('project discovery', () => {
it('searches key, name, and description without treating SQL wildcards as patterns', async () => {
const { api } = await setup();
- await api.projects.post({ key: 'ALPHA', name: 'Research', description: 'Release readiness' });
- await api.projects.post({ key: 'PCT', name: '100% ready' });
- await api.projects.post({ key: 'UNDER', name: 'under_score' });
- await api.projects.post({ key: 'SLASH', name: 'back\\slash' });
+ await createProject(api, { key: 'ALPHA', name: 'Research', description: 'Release readiness' });
+ await createProject(api, { key: 'PCT', name: '100% ready' });
+ await createProject(api, { key: 'UNDER', name: 'under_score' });
+ await createProject(api, { key: 'SLASH', name: 'back\\slash' });
for (const [q, expected] of [
[' alpha ', ['ALPHA']],
@@ -52,9 +52,9 @@ describe('project discovery', () => {
it('sorts by name and newest creation, with stable key ordering for equal names', async () => {
const { api } = await setup();
- await api.projects.post({ key: 'Z', name: 'Alpha' });
- await api.projects.post({ key: 'B', name: 'alpha' });
- await api.projects.post({ key: 'A', name: 'Zulu' });
+ await createProject(api, { key: 'Z', name: 'Alpha' });
+ await createProject(api, { key: 'B', name: 'alpha' });
+ await createProject(api, { key: 'A', name: 'Zulu' });
const byName = await api.projects.get({ query: { sort: 'name' } });
expect(byName.status).toBe(200);
@@ -67,7 +67,7 @@ describe('project discovery', () => {
it('orders activity by work-item changes and comments, leaving empty projects last by key', async () => {
const { api } = await setup();
for (const key of ['ZEMPTY', 'B', 'A', 'AEMPTY']) {
- await api.projects.post({ key, name: key });
+ await createProject(api, { key, name: key });
}
const first = await createWorkItem(api, 'A');
await createWorkItem(api, 'B');
@@ -94,7 +94,7 @@ describe('project discovery', () => {
it('keeps private document changes out of the activity timestamp', async () => {
const { api } = await setup();
- await api.projects.post({ key: 'DOC', name: 'Documents' });
+ await createProject(api, { key: 'DOC', name: 'Documents' });
const member = await addProjectMember(api, 'DOC');
const created = await api.projects({ projectKey: 'DOC' }).documents.post({
title: 'Private planning',
@@ -108,7 +108,7 @@ describe('project discovery', () => {
it('does not expose or sort by activity when the member cannot read work items', async () => {
const { api } = await setup();
- for (const key of ['A', 'B']) await api.projects.post({ key, name: key });
+ for (const key of ['A', 'B']) await createProject(api, { key, name: key });
const role = await createRole(api, 'A', { name: 'Documents only', permissions: {} });
const user = await signUpTestUser();
const member = authedApi(user.cookie);
@@ -135,8 +135,14 @@ describe('project discovery', () => {
it('combines team and search filters without revealing projects to a non-member', async () => {
const { api } = await setup();
- const first = (await api.projects.post({ key: 'ONE', name: 'Shared name' })).data!;
- const team = (await api.teams.post({ name: 'Second team', slug: 'second-team' })).data!;
+ const first = (await createProject(api, { key: 'ONE', name: 'Shared name' })).data!;
+ const team = (
+ await api.teams.post({
+ name: 'Second team',
+ slug: 'second-team',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
const second = await api.teams({ teamId: team.id }).projects.post({
key: 'TWO',
name: 'Shared name',
@@ -164,9 +170,15 @@ describe('project discovery', () => {
it('exposes discovery arguments over MCP and preserves both MCP opt-in switches', async () => {
const { user, api } = await setup();
- const on = (await api.projects.post({ key: 'ON', name: 'Visible project' })).data!;
- const off = (await api.projects.post({ key: 'OFF', name: 'Visible disabled project' })).data!;
- const secondTeam = (await api.teams.post({ name: 'Closed team', slug: 'closed-team' })).data!;
+ const on = (await createProject(api, { key: 'ON', name: 'Visible project' })).data!;
+ const off = (await createProject(api, { key: 'OFF', name: 'Visible disabled project' })).data!;
+ const secondTeam = (
+ await api.teams.post({
+ name: 'Closed team',
+ slug: 'closed-team',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
await api
.teams({ teamId: secondTeam.id })
.projects.post({ key: 'TEAMOFF', name: 'Visible team' });
diff --git a/apps/api/src/modules/projects/__tests__/integration/personal-preferences.test.ts b/apps/api/src/modules/projects/__tests__/integration/personal-preferences.test.ts
index ad0fdb0e..dc3d4688 100644
--- a/apps/api/src/modules/projects/__tests__/integration/personal-preferences.test.ts
+++ b/apps/api/src/modules/projects/__tests__/integration/personal-preferences.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it } from 'bun:test';
import { auth } from '@repo/auth';
-import { app, authedApi } from '#tests/helpers/app';
+import { app, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -8,7 +8,7 @@ import { addProjectMember } from '#tests/helpers/members';
async function setup() {
const user = await signUpTestUser();
const api = authedApi(user.cookie);
- const created = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(api, { key: 'MKT', name: 'Marketing' });
expect(created.status).toBe(201);
return { user, api };
}
@@ -124,7 +124,7 @@ describe('personal project preferences', () => {
it('updates only the selected project', async () => {
const { api } = await setup();
- const other = await api.projects.post({ key: 'OPS', name: 'Operations' });
+ const other = await createProject(api, { key: 'OPS', name: 'Operations' });
expect(other.status).toBe(201);
const updated = await api
diff --git a/apps/api/src/modules/projects/__tests__/integration/project-key.test.ts b/apps/api/src/modules/projects/__tests__/integration/project-key.test.ts
index 7046c07d..a2a60434 100644
--- a/apps/api/src/modules/projects/__tests__/integration/project-key.test.ts
+++ b/apps/api/src/modules/projects/__tests__/integration/project-key.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'bun:test';
import { eq } from 'drizzle-orm';
import { db, project } from '@repo/db';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -11,7 +11,7 @@ import { resetDb } from '#tests/helpers/db';
async function ownerWithProject(key: string) {
const user = await signUpTestUser();
const api = authedApi(user.cookie);
- const created = (await api.projects.post({ key: 'TMP', name: 'Trader' })).data!;
+ const created = (await createProject(api, { key: 'TMP', name: 'Trader' })).data!;
await db.update(project).set({ key }).where(eq(project.id, created.id));
return { api, created };
}
@@ -47,7 +47,7 @@ describe('project key rename', () => {
it('accepts the unchanged valid key', async () => {
const user = await signUpTestUser();
const api = authedApi(user.cookie);
- const created = (await api.projects.post({ key: 'MKT', name: 'Marketing' })).data!;
+ const created = (await createProject(api, { key: 'MKT', name: 'Marketing' })).data!;
const res = await api.projects({ projectKey: created.ref }).patch({ key: 'MKT', name: 'Ads' });
expect(res.data).toMatchObject({ key: 'MKT', name: 'Ads' });
@@ -55,7 +55,7 @@ describe('project key rename', () => {
it('refuses a key another project of the team has', async () => {
const { api, created } = await ownerWithProject('7XTR');
- await api.projects.post({ key: 'XTR', name: 'Other' });
+ await createProject(api, { key: 'XTR', name: 'Other' });
const res = await api.projects({ projectKey: `${created.teamId}.7XTR` }).patch({ key: 'XTR' });
expect(res.status).toBe(409);
diff --git a/apps/api/src/modules/projects/__tests__/integration/project-ref.test.ts b/apps/api/src/modules/projects/__tests__/integration/project-ref.test.ts
index 8c779381..aec32bab 100644
--- a/apps/api/src/modules/projects/__tests__/integration/project-ref.test.ts
+++ b/apps/api/src/modules/projects/__tests__/integration/project-ref.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -16,8 +16,14 @@ async function signUpClient() {
async function twoTeamsWithMkt() {
const owner = await signUpClient();
const first = (await owner.api.teams.get()).data![0];
- const second = (await owner.api.teams.post({ name: 'Second', slug: 'second' })).data!;
- const a = (await owner.api.projects.post({ key: 'MKT', name: 'First marketing' })).data!;
+ const second = (
+ await owner.api.teams.post({
+ name: 'Second',
+ slug: 'second',
+ workspaceId: await ownWorkspaceId(owner.api),
+ })
+ ).data!;
+ const a = (await createProject(owner.api, { key: 'MKT', name: 'First marketing' })).data!;
const b = (
await owner.api.teams({ teamId: second.id }).projects.post({
key: 'MKT',
@@ -95,7 +101,7 @@ describe('project ref', () => {
it('resolves a bare key while the instance has one project with it', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'OPS', name: 'Ops' });
+ await createProject(owner.api, { key: 'OPS', name: 'Ops' });
expect((await owner.api.projects({ projectKey: 'OPS' }).get()).status).toBe(200);
});
@@ -104,8 +110,8 @@ describe('project ref', () => {
const { api } = await signUpClient();
for (const key of ['mkt', '1MKT', 'MK-T', 'M.KT', 'ABCDEFGHIJK']) {
- expect((await api.projects.post({ key, name: 'Marketing' })).status).toBe(400);
+ expect((await createProject(api, { key, name: 'Marketing' })).status).toBe(400);
}
- expect((await api.projects.post({ key: 'ABCDEFGHIJ', name: 'Marketing' })).status).toBe(201);
+ expect((await createProject(api, { key: 'ABCDEFGHIJ', name: 'Marketing' })).status).toBe(201);
});
});
diff --git a/apps/api/src/modules/projects/__tests__/integration/projects.test.ts b/apps/api/src/modules/projects/__tests__/integration/projects.test.ts
index a6c98791..c264d1e6 100644
--- a/apps/api/src/modules/projects/__tests__/integration/projects.test.ts
+++ b/apps/api/src/modules/projects/__tests__/integration/projects.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { authedApi, type Api, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -41,7 +41,7 @@ describe('projects', () => {
it('creates a project and lists it for its owner', async () => {
const { api } = await signUpClient();
- const created = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(api, { key: 'MKT', name: 'Marketing' });
expect(created.status).toBe(201);
expect(created.data).toMatchObject({ key: 'MKT', name: 'Marketing', description: '' });
expect(typeof created.data?.id).toBe('number');
@@ -53,27 +53,20 @@ describe('projects', () => {
expect(list.data?.[0]).toMatchObject({ key: 'MKT', name: 'Marketing', role: 'owner' });
});
- it('puts the project in the team the account owns', async () => {
- const { user, api } = await signUpClient();
- const other = await signUpClient();
-
- const created = await api.projects.post({ key: 'MKT', name: 'Marketing' });
- expect(created.data).toMatchObject({ teamName: user.username });
-
- const theirs = await other.api.projects.post({ key: 'OPS', name: 'Operations' });
- expect(theirs.data).toMatchObject({ teamName: other.user.username });
+ it('puts the project in the team it is created in', async () => {
+ const { api } = await signUpClient();
+ const workspaceId = await ownWorkspaceId(api);
+ const second = (await api.teams.post({ name: 'Second', slug: 'second', workspaceId })).data!;
- const list = await api.projects.get();
- expect(list.data?.[0]).toMatchObject({
- key: 'MKT',
- teamId: created.data?.teamId,
- teamName: user.username,
- });
+ const created = await api
+ .teams({ teamId: second.id })
+ .projects.post({ key: 'MKT', name: 'Marketing' });
+ expect(created.data).toMatchObject({ teamId: second.id, teamName: 'Second' });
});
it('stores a provided description', async () => {
const { api } = await signUpClient();
- const created = await api.projects.post({
+ const created = await createProject(api, {
key: 'MKT',
name: 'Marketing',
description: 'Growth work',
@@ -83,7 +76,7 @@ describe('projects', () => {
it('seeds the five default columns', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const view = await viewOf(api, 'MKT');
expect(view.status).toBe(200);
@@ -92,7 +85,7 @@ describe('projects', () => {
it('denies a project member whose rank in the team is member', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(owner.api, { key: 'SRC', name: 'Source' });
const role = await createRole(owner.api, 'SRC', {
name: 'Reader',
permissions: { work_items: { read: true } },
@@ -108,19 +101,19 @@ describe('projects', () => {
it('rejects an empty key', async () => {
const { api } = await signUpClient();
- const res = await api.projects.post({ key: '', name: 'Marketing' });
+ const res = await createProject(api, { key: '', name: 'Marketing' });
expect(res.status).toBe(400);
});
it('rejects an empty name', async () => {
const { api } = await signUpClient();
- const res = await api.projects.post({ key: 'MKT', name: '' });
+ const res = await createProject(api, { key: 'MKT', name: '' });
expect(res.status).toBe(400);
});
it('rejects a missing name', async () => {
const { api } = await signUpClient();
- const res = await api.projects.post({ key: 'MKT' } as unknown as {
+ const res = await createProject(api, { key: 'MKT' } as unknown as {
key: string;
name: string;
});
@@ -129,16 +122,16 @@ describe('projects', () => {
it('rejects a duplicate key with 409', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
- const dup = await api.projects.post({ key: 'MKT', name: 'Marketing Two' });
+ const dup = await createProject(api, { key: 'MKT', name: 'Marketing Two' });
expect(dup.status).toBe(409);
});
it('requires a session', async () => {
// The anonymous client carries no cookie, so the session gate rejects it.
const anon = authedApi('');
- const res = await anon.projects.post({ key: 'MKT', name: 'Marketing' });
+ const res = await anon.teams({ teamId: 1 }).projects.post({ key: 'MKT', name: 'Marketing' });
expect(res.status).toBe(401);
});
});
@@ -146,8 +139,8 @@ describe('projects', () => {
describe('list', () => {
it('returns only the projects the user is a member of, ordered by key', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'OPS', name: 'Operations' });
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'OPS', name: 'Operations' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const list = await api.projects.get();
expect(list.status).toBe(200);
@@ -156,7 +149,7 @@ describe('projects', () => {
it('does not show a project to a non-member', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const outsider = await signUpClient();
const list = await outsider.api.projects.get();
@@ -166,7 +159,7 @@ describe('projects', () => {
it('omits permissions by default and includes them with the flag', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const bare = await api.projects.get();
expect(bare.data?.[0].permissions).toBeUndefined();
@@ -184,7 +177,7 @@ describe('projects', () => {
describe('update', () => {
it("updates an owner's project name and description, leaving the key", async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await api
.projects({ projectKey: 'MKT' })
@@ -202,7 +195,7 @@ describe('projects', () => {
it('rejects a description over the limit', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await api
.projects({ projectKey: 'MKT' })
@@ -212,7 +205,7 @@ describe('projects', () => {
it('denies a non-member (owner-only)', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const outsider = await signUpClient();
const res = await outsider.api.projects({ projectKey: 'MKT' }).patch({ name: 'Hijacked' });
@@ -223,7 +216,7 @@ describe('projects', () => {
describe('view', () => {
it('returns the full work-items view for a member', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const view = await viewOf(api, 'MKT');
expect(view.status).toBe(200);
@@ -238,7 +231,7 @@ describe('projects', () => {
it('includes every custom field of the project, both scopes', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const type = (await api.projects({ projectKey: 'MKT' })['issue-types'].post({ name: 'Bug' }))
.data!;
const cf = api.projects({ projectKey: 'MKT' })['custom-fields'];
@@ -264,7 +257,7 @@ describe('projects', () => {
it('denies a non-member with 403', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const outsider = await signUpClient();
const res = await viewOf(outsider.api, 'MKT');
@@ -273,7 +266,7 @@ describe('projects', () => {
it('opens to a member whose role grants nothing, so any role can enter the project', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const role = await createRole(owner.api, 'MKT', {
name: 'Notes only',
permissions: { note_boards: { read: true } },
@@ -292,7 +285,7 @@ describe('projects', () => {
// Builds a source project with one label and one issue, so a copy can assert
// the structure is copied but the issues are not.
async function setupSource(api: Api) {
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
const backlog = (await viewOf(api, 'SRC')).data!.columns.find((c) => c.name === 'Backlog')!;
await api.projects({ projectKey: 'SRC' }).labels.post({ name: 'bug', color: '#ff0000' });
await api
@@ -355,7 +348,7 @@ describe('projects', () => {
it("copies the source project's issue types", async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await api.projects({ projectKey: 'SRC' })['issue-types'].post({ name: 'Bug' });
await api.projects({ projectKey: 'SRC' }).copy.post({ key: 'DST', name: 'Destination' });
@@ -368,7 +361,7 @@ describe('projects', () => {
it('copies which optional sections the source project shows', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await api
.projects({ projectKey: 'SRC' })
.settings.patch({ features: { documents: false, notes: false, dashboards: false } });
@@ -391,7 +384,7 @@ describe('projects', () => {
it('takes mcpEnabled from the instance default, not from the source project', async () => {
const { api } = await signUpClient();
const teamId = (await api.teams.get()).data![0].id;
- const source = (await api.projects.post({ key: 'SRC', name: 'Source' })).data!;
+ const source = (await createProject(api, { key: 'SRC', name: 'Source' })).data!;
await api
.teams({ teamId })
.mcp.patch({ projects: [{ projectId: source.id, enabled: false }] });
@@ -406,7 +399,7 @@ describe('projects', () => {
// carry a fixed value. The first account of a fresh database holds the god role.
it('copies a project with MCP off once the instance default is turned off', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await api.god['project-defaults'].put({ mcpEnabled: false });
await api.projects({ projectKey: 'SRC' }).copy.post({ key: 'DST', name: 'Destination' });
@@ -417,7 +410,7 @@ describe('projects', () => {
it('copies the estimate kinds and time logging the source project carries', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await api.projects({ projectKey: 'SRC' }).settings.estimates.patch({
points: true,
time: true,
@@ -436,7 +429,7 @@ describe('projects', () => {
it("remaps a saved view's filter ids to the copied project's entities", async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
const srcBacklog = (await viewOf(api, 'SRC')).data!.columns.find(
(c) => c.name === 'Backlog',
)!;
@@ -504,7 +497,7 @@ describe('projects', () => {
it('force-enables a dependency: copying views pulls in the referenced states', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
const review = (
await api
.projects({ projectKey: 'SRC' })
@@ -535,7 +528,7 @@ describe('projects', () => {
it("points a copied status schedule at the copy's own column", async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
const agent = (
await createAgent(api, 'SRC', { name: 'Bot', username: 'bot', kind: 'internal' })
).data!.agent;
@@ -570,7 +563,7 @@ describe('projects', () => {
it("draws on the target team's roles, which the source team's do not reach", async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await createRole(api, 'SRC', {
name: 'Editor',
permissions: { work_items: { create: true, edit: true, read: true, delete: false } },
@@ -588,7 +581,7 @@ describe('projects', () => {
// project — no second agent, no second bot user, no new key.
it("puts the source project's agents in a copy inside the team", async () => {
const { api, user } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await createAgent(api, 'SRC', {
name: 'Ext',
username: 'ext',
@@ -612,9 +605,15 @@ describe('projects', () => {
it('carries no agent into another team', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
await createAgent(api, 'SRC', { name: 'Ext', username: 'ext', kind: 'external' });
- const target = (await api.teams.post({ name: 'Other Team', slug: 'other-team' })).data!;
+ const target = (
+ await api.teams.post({
+ name: 'Other Team',
+ slug: 'other-team',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
const sourceId = await projectIdOf(api, 'SRC');
await api
@@ -631,8 +630,8 @@ describe('projects', () => {
it('rejects a duplicate key with 409 and no statement in the body', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
- await api.projects.post({ key: 'DST', name: 'Existing' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'DST', name: 'Existing' });
const res = await api.projects({ projectKey: 'SRC' }).copy.post({
key: 'DST',
@@ -653,7 +652,7 @@ describe('projects', () => {
it('denies a non-member with 403', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(owner.api, { key: 'SRC', name: 'Source' });
const outsider = await signUpClient();
const res = await outsider.api.projects({ projectKey: 'SRC' }).copy.post({
@@ -665,7 +664,7 @@ describe('projects', () => {
it('rejects an empty key', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(api, { key: 'SRC', name: 'Source' });
const res = await api
.projects({ projectKey: 'SRC' })
.copy.post({ key: '', name: 'Destination' });
@@ -676,7 +675,7 @@ describe('projects', () => {
describe('delete', () => {
it('deletes a project and its scoped entities for an owner', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const backlog = (await viewOf(api, 'MKT')).data!.columns.find((c) => c.name === 'Backlog')!;
await api
.projects({ projectKey: 'MKT' })
@@ -699,7 +698,7 @@ describe('projects', () => {
it('denies a non-member with 403', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const outsider = await signUpClient();
const res = await outsider.api.projects({ projectKey: 'MKT' }).delete();
@@ -721,7 +720,7 @@ describe('projects', () => {
it('defaults a new project to the instance project default (MCP on)', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const view = await viewOf(api, 'MKT');
expect(view.data?.project).toMatchObject({ mcpEnabled: true, teamMcpEnabled: true });
@@ -729,7 +728,7 @@ describe('projects', () => {
it('no longer takes the toggle on the project settings route', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
// The field is gone from the body schema, so an old client sending it changes
// nothing rather than reopening the project from outside the team's settings.
@@ -743,7 +742,7 @@ describe('projects', () => {
it('blocks an MCP call to a project the team no longer covers, but not a web call', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = await teamOf(api, 'MKT');
const projectId = (await viewOf(api, 'MKT')).data!.project.id;
await api.teams({ teamId }).mcp.patch({ projects: [{ projectId, enabled: false }] });
@@ -759,7 +758,7 @@ describe('projects', () => {
it("blocks an MCP call to every project once the team's switch is off", async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = await teamOf(api, 'MKT');
await api.teams({ teamId }).mcp.patch({ enabled: false });
@@ -773,7 +772,7 @@ describe('projects', () => {
it('blocks an MCP call on an entity-by-id route of a project out of reach', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = await teamOf(api, 'MKT');
const projectId = (await viewOf(api, 'MKT')).data!.project.id;
await api.teams({ teamId }).mcp.patch({ projects: [{ projectId, enabled: false }] });
@@ -790,8 +789,8 @@ describe('projects', () => {
it('hides projects out of reach from an MCP list_projects call', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'ON', name: 'Enabled' });
- await api.projects.post({ key: 'OFF', name: 'Disabled' });
+ await createProject(api, { key: 'ON', name: 'Enabled' });
+ await createProject(api, { key: 'OFF', name: 'Disabled' });
const teamId = await teamOf(api, 'OFF');
const projectId = (await viewOf(api, 'OFF')).data!.project.id;
await api.teams({ teamId }).mcp.patch({ projects: [{ projectId, enabled: false }] });
@@ -804,7 +803,7 @@ describe('projects', () => {
describe('settings', () => {
it('defaults a new project to the instance project default (MCP on)', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await api.projects({ projectKey: 'MKT' }).settings.get();
expect(res.status).toBe(200);
@@ -813,7 +812,7 @@ describe('projects', () => {
it('starts a new project with every optional section enabled', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await api.projects({ projectKey: 'MKT' }).settings.get();
expect(res.data?.features).toMatchObject({
@@ -838,7 +837,7 @@ describe('projects', () => {
it('lets an owner turn a section off and back on, leaving the others', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const off = await api
.projects({ projectKey: 'MKT' })
@@ -861,7 +860,7 @@ describe('projects', () => {
it('lets an owner turn off the sections of an issue', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const off = await api
.projects({ projectKey: 'MKT' })
@@ -881,7 +880,7 @@ describe('projects', () => {
it('closes the routes and the fields of a section that is turned off', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const columnId = (await viewOf(api, 'MKT')).data!.columns[0].id;
const parent = await api.projects({ projectKey: 'MKT' }).issues.post({
columnId,
@@ -904,7 +903,7 @@ describe('projects', () => {
it('reports a section the team cannot use as off and refuses to turn it on', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
setLimits({ blockedFeatures: ['initiatives'] });
const settings = await api.projects({ projectKey: 'MKT' }).settings.get();
@@ -928,7 +927,7 @@ describe('projects', () => {
it('denies turning a section off to a non-owner (owner-only)', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const outsider = await signUpClient();
const res = await outsider.api
@@ -939,7 +938,7 @@ describe('projects', () => {
it('changes only the supplied field, leaving the other', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
await api.projects({ projectKey: 'MKT' }).settings.patch({ features: { notes: false } });
const res = await api
@@ -950,7 +949,7 @@ describe('projects', () => {
it('denies writing settings to someone outside the project and its team', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const outsider = await signUpClient();
const res = await outsider.api
@@ -961,7 +960,7 @@ describe('projects', () => {
it('denies writing settings to a plain member of the project', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addProjectMember(owner.api, 'MKT');
const res = await member
@@ -972,7 +971,7 @@ describe('projects', () => {
it("lets the team's owner write settings on a project they left", async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
// Hand MKT to someone else and leave it. The team still owns the project, so
// its owner keeps the settings without a membership of their own.
@@ -1000,7 +999,7 @@ describe('projects', () => {
it('defaults a new project to the default thresholds', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await autoArchive(api).get();
expect(res.status).toBe(200);
@@ -1009,7 +1008,7 @@ describe('projects', () => {
it('lets an owner set and read back the thresholds', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const patch = await autoArchive(api).patch({ completedDays: 14, canceledDays: 3 });
expect(patch.status).toBe(200);
@@ -1023,7 +1022,7 @@ describe('projects', () => {
it('stores null to disable a state group', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await autoArchive(api).patch({ completedDays: 30, canceledDays: null });
expect(res.status).toBe(200);
@@ -1032,7 +1031,7 @@ describe('projects', () => {
it('rejects a day count below 1', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await autoArchive(api).patch({ completedDays: 0, canceledDays: 7 });
expect(res.status).toBe(400);
@@ -1042,7 +1041,7 @@ describe('projects', () => {
// day count no interval can carry fails that statement for the whole instance.
it('rejects a day count no interval can carry', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await autoArchive(api).patch({ completedDays: 3_000_000, canceledDays: 7 });
expect(res.status).toBe(400);
@@ -1050,7 +1049,7 @@ describe('projects', () => {
it('holds the default member role out of the section', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addProjectMember(owner.api, 'MKT');
expect((await autoArchive(member).get()).status).toBe(403);
@@ -1061,7 +1060,7 @@ describe('projects', () => {
it('lets a granted role read the thresholds but not change them without edit', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const role = await createRole(owner.api, 'MKT', {
name: 'Reader',
permissions: { workflow_config: { read: true } },
@@ -1076,7 +1075,7 @@ describe('projects', () => {
it('lets a role with edit change the thresholds', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const role = await createRole(owner.api, 'MKT', {
name: 'Archivist',
permissions: { workflow_config: { read: true, edit: true } },
@@ -1094,7 +1093,7 @@ describe('projects', () => {
it('defaults a new project to both kinds and time logging off', async () => {
const { api } = await signUpClient();
- const created = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(api, { key: 'MKT', name: 'Marketing' });
expect(created.data).toMatchObject({
pointsEstimateEnabled: false,
@@ -1105,7 +1104,7 @@ describe('projects', () => {
it('lets an owner turn a kind on and reads it back with the project', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const patch = await estimates(api).patch({ points: true, time: false, logging: true });
expect(patch.status).toBe(200);
@@ -1121,7 +1120,7 @@ describe('projects', () => {
it('keeps the estimates on the issues when a kind is turned off', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const view = await viewOf(api, 'MKT');
await estimates(api).patch({ points: true, time: true, logging: false });
const issue = await api
@@ -1136,7 +1135,7 @@ describe('projects', () => {
it('holds the default member role out of the section', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addProjectMember(owner.api, 'MKT');
expect(
@@ -1146,7 +1145,7 @@ describe('projects', () => {
it('lets a role with edit change the kinds', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const role = await createRole(owner.api, 'MKT', {
name: 'Planner',
permissions: { workflow_config: { read: true, edit: true } },
@@ -1164,7 +1163,7 @@ describe('projects', () => {
it('defaults a new project to both automations off', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const res = await subtasks(api).get();
expect(res.status).toBe(200);
@@ -1173,7 +1172,7 @@ describe('projects', () => {
it('lets an owner set and read back the automations', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const patch = await subtasks(api).patch({ completeParent: true, closeSubtasks: false });
expect(patch.status).toBe(200);
@@ -1187,7 +1186,7 @@ describe('projects', () => {
it('holds the default member role out of the section', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addProjectMember(owner.api, 'MKT');
expect((await subtasks(member).get()).status).toBe(403);
@@ -1198,7 +1197,7 @@ describe('projects', () => {
it('lets a granted role read the automations but not change them without edit', async () => {
const owner = await signUpClient();
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const role = await createRole(owner.api, 'MKT', {
name: 'Reader',
permissions: { workflow_config: { read: true } },
diff --git a/apps/api/src/modules/projects/copy.ts b/apps/api/src/modules/projects/copy.ts
index 6627519a..2b616b7e 100644
--- a/apps/api/src/modules/projects/copy.ts
+++ b/apps/api/src/modules/projects/copy.ts
@@ -233,8 +233,8 @@ export async function copyProject(
sourceProjectId: number,
input: { key: string; name: string; description?: string },
ownerId: string,
+ teamId: number,
rawInclude?: Partial<CopyProjectInclude>,
- teamId?: number,
): Promise<ProjectRow> {
const inc = normalizeInclude(rawInclude);
diff --git a/apps/api/src/modules/projects/index.ts b/apps/api/src/modules/projects/index.ts
index 77c58693..445d0711 100644
--- a/apps/api/src/modules/projects/index.ts
+++ b/apps/api/src/modules/projects/index.ts
@@ -23,7 +23,6 @@ import {
ProjectSettingsResponse,
SubtaskAutomationResponse,
copyProjectBody,
- createProjectBody,
listProjectsQuery,
updateAutoArchiveBody,
updateEstimatesBody,
@@ -33,7 +32,6 @@ import {
} from './model';
import {
listProjects,
- createProject,
updateProject,
deleteProject,
projectFeatures,
@@ -75,32 +73,12 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
},
)
- .post(
- '/projects',
- async ({ body, user, set }) => {
- set.status = 201;
- return createProject(body, requireUser(user).id);
- },
- {
- body: createProjectBody,
- response: { 201: ProjectResponse, ...errors(400, 401) },
- detail: {
- summary: 'Create a project',
- description:
- 'Create a project you own. `key` is the immutable prefix for issue ids, unique within the team ' +
- "(e.g. 'MKT' -> 'MKT-1'). Seeds the default columns and the issue types of the " +
- 'chosen `preset`.',
- ...mcpTool('create_project'),
- },
- },
- )
-
.post(
'/projects/:projectKey/copy',
async ({ project, body, user, set }) => {
const { include, ...meta } = body;
set.status = 201;
- return await copyProject(project.id, meta, requireUser(user).id, include);
+ return await copyProject(project.id, meta, requireUser(user).id, project.teamId, include);
},
{
body: copyProjectBody,
@@ -109,8 +87,8 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
detail: {
summary: 'Copy a project',
description:
- "Copy a project's configuration into a new project you own, without its issues. " +
- 'Only an owner or a manager of the team that owns the source project may copy it. ' +
+ "Copy a project's configuration into a new project you own in the same team, without " +
+ 'its issues. Only an owner or a manager of that team may copy it. ' +
'By default the structure (states, issue types, labels, custom fields, views, ' +
'dashboards, documents, actions) is copied. Pass `include` to choose sections; the API ' +
'force-enables dependencies (e.g. a view pulls in the states it references).',
diff --git a/apps/api/src/modules/projects/service.ts b/apps/api/src/modules/projects/service.ts
index bb9d8352..358081df 100644
--- a/apps/api/src/modules/projects/service.ts
+++ b/apps/api/src/modules/projects/service.ts
@@ -347,10 +347,8 @@ export async function getProjectTeamId(projectId: number): Promise<number> {
return rows[0].teamId;
}
-// The team a new project belongs to. `teamId` names it explicitly (the caller's
-// rank in it is checked by the route); without one it is the team the caller owns.
-export async function targetTeam(userId: string, teamId?: number): Promise<TargetTeam> {
- if (teamId == null) return ownedTeam(userId);
+// The team a new project belongs to. The caller's rank in it is checked by the route.
+export async function targetTeam(userId: string, teamId: number): Promise<TargetTeam> {
const [row] = await db
.select({
id: team.id,
@@ -386,25 +384,6 @@ export interface TargetTeam {
defaultAgentIds: number[];
}
-// The first team the caller owns. An account has none until it creates one.
-async function ownedTeam(userId: string): Promise<TargetTeam> {
- const [row] = await db
- .select({
- id: team.id,
- name: team.name,
- slug: team.slug,
- mcpEnabled: team.mcpEnabled,
- defaultAgentIds: team.defaultAgentIds,
- })
- .from(teamMember)
- .innerJoin(team, eq(team.id, teamMember.teamId))
- .where(and(eq(teamMember.userId, userId), eq(teamMember.role, 'owner')))
- .orderBy(team.id)
- .limit(1);
- if (!row) throw new HttpError(400, 'You do not own a team to create a project in');
- return row;
-}
-
// Every new project starts with one column per state type, so it's usable (has
// somewhere to put an issue) without a trip to Settings first.
export const DEFAULT_COLUMNS: { name: string; stateType: string; color: string }[] = [
@@ -492,7 +471,7 @@ export async function createProject(
preset?: string;
},
ownerId: string,
- teamId?: number,
+ teamId: number,
): Promise<ProjectRow> {
const ownerTeam = await targetTeam(ownerId, teamId);
// What a new project starts with, set instance-wide in god mode. Read before the
diff --git a/apps/api/src/modules/roles/__tests__/integration/roles.test.ts b/apps/api/src/modules/roles/__tests__/integration/roles.test.ts
index 155589d7..3de1c507 100644
--- a/apps/api/src/modules/roles/__tests__/integration/roles.test.ts
+++ b/apps/api/src/modules/roles/__tests__/integration/roles.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser, type TestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { PERMISSION_RESOURCES, PERMISSION_ACTIONS, resourceActions } from '#shared/permissions';
@@ -22,7 +22,7 @@ type Actor = { user: TestUser; api: ReturnType<typeof authedApi>; teamId: number
async function setupOwner(projectKey = 'MKT'): Promise<Actor> {
const user = await signUpTestUser();
const client = authedApi(user.cookie);
- await client.projects.post({ key: projectKey, name: 'Marketing' });
+ await createProject(client, { key: projectKey, name: 'Marketing' });
const teams = await client.teams.get();
return { user, api: client, teamId: teams.data![0].id };
}
diff --git a/apps/api/src/modules/scim/__tests__/helpers.ts b/apps/api/src/modules/scim/__tests__/helpers.ts
index 58ed6a05..368240d4 100644
--- a/apps/api/src/modules/scim/__tests__/helpers.ts
+++ b/apps/api/src/modules/scim/__tests__/helpers.ts
@@ -1,42 +1,46 @@
import { eq } from 'drizzle-orm';
import { rotateScimToken, setScimSettings } from '@repo/auth';
import { createWorkspace, db, team } from '@repo/db';
-import { scimApi } from '#tests/helpers/app';
+import { scimApi, type Api } from '#tests/helpers/app';
import { addUser, type Actor } from '#modules/god/__tests__/helpers';
-// Turns SCIM provisioning of the instance workspace on and hands back a client that
-// authenticates with the generated token, the way an identity provider does. `god`
-// owns the workspace, and `settings` is its SCIM section.
+// Turns the instance's SCIM provisioning on in god mode and hands back a client that
+// authenticates with the generated token, the way an identity provider does.
export interface ScimSetup {
god: Actor;
- workspaceId: number;
- settings: ReturnType<typeof workspaceScim>;
+ settings: Api['god']['scim'];
token: string;
scim: ReturnType<typeof scimApi>;
}
-function workspaceScim(owner: Actor, workspaceId: number) {
- return owner.api.workspaces({ workspaceId }).scim;
-}
-
export async function setupScim(): Promise<ScimSetup> {
const god = await addUser({ name: 'Root', email: '[email protected]' });
- const [workspace] = (await god.api.workspaces.get()).data!;
- const workspaceId = workspace!.id;
- const settings = workspaceScim(god, workspaceId);
+ const settings = god.api.god.scim;
const created = await settings.token.post();
const token = created.data!.token;
await settings.patch({ enabled: true });
- return { god, workspaceId, settings, token, scim: scimApi(token) };
+ return { god, settings, token, scim: scimApi(token) };
+}
+
+export interface WorkspaceScimSetup {
+ workspaceId: number;
+ settings: ReturnType<typeof workspaceScim>;
+ token: string;
+ scim: ReturnType<typeof scimApi>;
+}
+
+function workspaceScim(owner: Actor, workspaceId: number) {
+ return owner.api.workspaces({ workspaceId }).scim;
}
-// A second workspace owned by `owner`, with provisioning on, holding `teamIds`. Its
-// provisioning is set up directly, since through the api only the instance owner may.
+// A second workspace owned by `owner`, with SCIM of its own on, holding `teamIds`, for a
+// build that sets SCIM up per workspace (setWorkspaceScim). Its provisioning is set up
+// directly, so it works with the switch off as well.
export async function setupOtherWorkspace(
owner: Actor,
teamIds: number[] = [],
-): Promise<Omit<ScimSetup, 'god'>> {
+): Promise<WorkspaceScimSetup> {
const workspaceId = await createWorkspace(db, 'Other', owner.id);
for (const teamId of teamIds) {
await db.update(team).set({ workspaceId }).where(eq(team.id, teamId));
diff --git a/apps/api/src/modules/scim/__tests__/integration/scim-discovery.test.ts b/apps/api/src/modules/scim/__tests__/integration/scim-discovery.test.ts
index d49a71d4..7795a757 100644
--- a/apps/api/src/modules/scim/__tests__/integration/scim-discovery.test.ts
+++ b/apps/api/src/modules/scim/__tests__/integration/scim-discovery.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it, beforeEach } from 'bun:test';
-import { api, scimApi } from '#tests/helpers/app';
+import { setWorkspaceScim } from '@repo/auth';
+import { api, ownWorkspaceId, scimApi } from '#tests/helpers/app';
import { writeSecret } from '@repo/db';
import { resetDb } from '#tests/helpers/db';
import { addUser } from '#modules/god/__tests__/helpers';
@@ -52,12 +53,19 @@ describe('SCIM discovery and authentication', () => {
});
});
- describe('workspace settings', () => {
- it('refuses an admin of the workspace', async () => {
- const { god, workspaceId } = await setupScim();
- const admin = await addUser({ email: '[email protected]' });
- await god.api.workspaces({ workspaceId }).managers.post({ userId: admin.id });
- const scim = admin.api.workspaces({ workspaceId }).scim;
+ describe('settings', () => {
+ it('refuses anyone but the instance owner', async () => {
+ await setupScim();
+ const someone = await addUser({ email: '[email protected]' });
+ const scim = someone.api.god.scim;
+
+ expect((await scim.get()).status).toBe(403);
+ expect((await scim.token.post()).status).toBe(403);
+ });
+
+ it("refuses a workspace's own while SCIM is the instance's", async () => {
+ const { god } = await setupScim();
+ const scim = god.api.workspaces({ workspaceId: await ownWorkspaceId(god.api) }).scim;
expect((await scim.get()).status).toBe(403);
expect((await scim.token.post()).status).toBe(403);
@@ -65,18 +73,15 @@ describe('SCIM discovery and authentication', () => {
it('refuses to enable provisioning before a token exists', async () => {
const god = await addUser({ email: '[email protected]' });
- const [workspace] = (await god.api.workspaces.get()).data!;
- const res = await god.api.workspaces({ workspaceId: workspace!.id }).scim.patch({
- enabled: true,
- });
+ const res = await god.api.god.scim.patch({ enabled: true });
expect(res.status).toBe(400);
expect(res.error!.value).toMatchObject({ error: 'Generate a SCIM token first' });
});
it('reports the token prefix and the base URL, never the token', async () => {
- const { settings, token, workspaceId } = await setupScim();
+ const { settings, token } = await setupScim();
const res = await settings.get();
@@ -85,31 +90,37 @@ describe('SCIM discovery and authentication', () => {
hasToken: true,
baseUrl: 'http://localhost:3000/scim/v2',
});
- expect(token.startsWith(`scim_${workspaceId}_`)).toBe(true);
+ expect(token).toMatch(/^scim_[0-9a-f]{48}$/);
expect(res.data!.tokenPrefix.length).toBeLessThan(token.length);
expect(token.startsWith(res.data!.tokenPrefix)).toBe(true);
});
- // A token generated before workspaces existed carries no workspace id, and the
- // identity providers already configured with one keep working.
- it('accepts a token without a workspace id for the instance workspace', async () => {
- const { workspaceId } = await setupScim();
- const legacy = 'scim_' + 'ab'.repeat(24);
- await writeSecret(`workspace.${workspaceId}.scim`, { enabled: true, token: legacy }, {});
+ // The instance's token was the first workspace's until SCIM became the instance's,
+ // and the identity providers already configured with it keep working.
+ it("accepts a token that carries the first workspace's id", async () => {
+ await setupScim();
+ const kept = 'scim_1_' + 'ab'.repeat(24);
+ await writeSecret('auth.scim', { enabled: true, token: kept }, {});
- const res = await scimApi(legacy).scim.v2.ServiceProviderConfig.get();
+ const res = await scimApi(kept).scim.v2.ServiceProviderConfig.get();
expect(res.status).toBe(200);
});
it("refuses one workspace's token under another workspace's id", async () => {
- const { god, token } = await setupScim();
- const other = await setupOtherWorkspace(god);
- const forged = token.replace(/^scim_\d+_/, `scim_${other.workspaceId}_`);
-
- const res = await scimApi(forged).scim.v2.ServiceProviderConfig.get();
-
- expect(res.status).toBe(401);
+ setWorkspaceScim();
+ try {
+ const god = await addUser({ email: '[email protected]' });
+ const first = await setupOtherWorkspace(god);
+ const other = await setupOtherWorkspace(god);
+ const forged = first.token.replace(/^scim_\d+_/, `scim_${other.workspaceId}_`);
+
+ const res = await scimApi(forged).scim.v2.ServiceProviderConfig.get();
+
+ expect(res.status).toBe(401);
+ } finally {
+ setWorkspaceScim(false);
+ }
});
});
diff --git a/apps/api/src/modules/scim/__tests__/integration/scim-groups.test.ts b/apps/api/src/modules/scim/__tests__/integration/scim-groups.test.ts
index de39ec84..64efdf5a 100644
--- a/apps/api/src/modules/scim/__tests__/integration/scim-groups.test.ts
+++ b/apps/api/src/modules/scim/__tests__/integration/scim-groups.test.ts
@@ -258,7 +258,8 @@ describe('SCIM groups', () => {
afterEach(() => setWorkspaceScim(false));
it("keeps one workspace's groups away from another's provider", async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
+ const { scim } = await setupOtherWorkspace(god);
const other = await setupOtherWorkspace(god);
const created = await scim.scim.v2.Groups.post(groupBody());
@@ -271,7 +272,7 @@ describe('SCIM groups', () => {
});
it('refuses a member the workspace does not see', async () => {
- const { god } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const other = await setupOtherWorkspace(god);
const outsider = await addUser({ email: '[email protected]' });
@@ -283,12 +284,13 @@ describe('SCIM groups', () => {
});
it('keeps accepting changes to a group holding a member the workspace no longer sees', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const outsider = await addUser({ email: '[email protected]' });
+ const [outsiderTeam] = (await outsider.api.teams.get()).data!;
+ const { scim } = await setupOtherWorkspace(god, [outsiderTeam!.id]);
const created = await scim.scim.v2.Groups.post(
groupBody({ members: [{ value: outsider.id }] }),
);
- const [outsiderTeam] = (await outsider.api.teams.get()).data!;
await setupOtherWorkspace(god, [outsiderTeam!.id]);
const ada = await scim.scim.v2.Users.post(scimUserBody());
diff --git a/apps/api/src/modules/scim/__tests__/integration/scim-reconcile.test.ts b/apps/api/src/modules/scim/__tests__/integration/scim-reconcile.test.ts
index 79b09f64..6e36d886 100644
--- a/apps/api/src/modules/scim/__tests__/integration/scim-reconcile.test.ts
+++ b/apps/api/src/modules/scim/__tests__/integration/scim-reconcile.test.ts
@@ -1,19 +1,20 @@
import { describe, expect, it, afterEach, beforeEach } from 'bun:test';
import { eq, inArray } from 'drizzle-orm';
-import { setInstanceScimBeside, setWorkspaceScim } from '@repo/auth';
+import { setWorkspaceScim } from '@repo/auth';
import { createWorkspace, db, team } from '@repo/db';
import { resetDb } from '#tests/helpers/db';
import { addUser, joinProject, type Actor } from '#modules/god/__tests__/helpers';
import { createRole, teamIdOf } from '#tests/helpers/roles';
+import { createProject as createOwnProject, ownWorkspaceId } from '#tests/helpers/app';
import { patchOps, scimUserBody, setupOtherWorkspace, setupScim, type ScimSetup } from '../helpers';
import { clearLimits, setLimits } from '#tests/helpers/limits';
-// What a provisioned group grants: the mappings the workspace owner declares turn
+// What a provisioned group grants: the mappings god or a workspace owner declares turn
// group membership into project membership. Only the rows the sync owns
// are ever touched, so a membership somebody set up through an invite survives.
async function createProject(owner: Actor, name: string, key: string) {
- const created = await owner.api.projects.post({ name, key });
+ const created = await createOwnProject(owner.api, { name, key });
return created.data!;
}
@@ -27,7 +28,11 @@ async function teamMemberIds(owner: Actor, teamId: number) {
return res.data!.items.map((m) => m.userId);
}
-async function provisionGroup(setup: ScimSetup, displayName: string, memberIds: string[]) {
+async function provisionGroup(
+ setup: Pick<ScimSetup, 'scim'>,
+ displayName: string,
+ memberIds: string[],
+) {
const created = await setup.scim.scim.v2.Groups.post({
schemas: ['urn:ietf:params:scim:schemas:core:2.0:Group'],
displayName,
@@ -355,7 +360,11 @@ describe('SCIM group reconciliation', () => {
it('refuses a role that belongs to another team', async () => {
const setup = await setupScim();
const marketing = await createProject(setup.god, 'Marketing', 'MKT');
- const otherTeam = await setup.god.api.teams.post({ name: 'Design', slug: 'design' });
+ const otherTeam = await setup.god.api.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(setup.god.api),
+ });
await setup.god.api.teams({ teamId: otherTeam.data!.id }).projects.post({
key: 'DSN',
name: 'Design',
@@ -388,14 +397,11 @@ describe('SCIM group reconciliation', () => {
expect(res.status).toBe(400);
});
- it('refuses an admin of the workspace', async () => {
+ it('refuses anyone but the instance owner', async () => {
const setup = await setupScim();
- const admin = await addUser({ email: '[email protected]' });
- await setup.god.api
- .workspaces({ workspaceId: setup.workspaceId })
- .managers.post({ userId: admin.id });
+ const someone = await addUser({ email: '[email protected]' });
const groupId = await provisionGroup(setup, 'Engineering', []);
- const scim = admin.api.workspaces({ workspaceId: setup.workspaceId }).scim;
+ const scim = someone.api.god.scim;
expect((await scim.groups.get()).status).toBe(403);
expect((await scim.groups({ groupId }).mappings.put({ mappings: [] })).status).toBe(403);
@@ -436,68 +442,56 @@ describe('SCIM group reconciliation', () => {
});
expect(res.status).toBe(200);
- const options = (
- await setup.god.api.workspaces({ workspaceId: setup.workspaceId }).projects.options.get()
- ).data!;
+ const options = (await setup.settings.projects.get()).data!;
expect(options.map((o) => o.key)).toContain('SAL');
});
- // Set up per workspace, as in a hosted build, a group grants projects of its own
- // workspace only, and nothing to a person its provider deactivated.
+ // Set up per workspace, as in a hosted build, a workspace's group grants projects of
+ // its own workspace only, and nothing to a person its provider deactivated. The
+ // instance's provider still grants projects of every workspace, except one that set up
+ // SCIM of its own: its provider decides there.
describe('set up per workspace', () => {
beforeEach(() => setWorkspaceScim());
afterEach(() => setWorkspaceScim(false));
it('grants a deactivated member nothing, and grants it again once they are back', async () => {
- const setup = await setupScim();
- const project = await createProject(setup.god, 'Marketing', 'MKT');
- const ada = await setup.scim.scim.v2.Users.post(scimUserBody());
- const groupId = await provisionGroup(setup, 'Engineering', [ada.data!.id]);
- await setup.settings.groups({ groupId }).mappings.put({
+ const god = await addUser({ email: '[email protected]' });
+ const project = await createProject(god, 'Marketing', 'MKT');
+ const own = await setupOtherWorkspace(god, [project.teamId]);
+ const ada = await own.scim.scim.v2.Users.post(scimUserBody());
+ const groupId = await provisionGroup(own, 'Engineering', [ada.data!.id]);
+ await own.settings.groups({ groupId }).mappings.put({
mappings: [{ projectId: project.id, role: 'member', roleId: null }],
});
const setActive = (value: boolean) =>
- setup.scim.scim.v2
+ own.scim.scim.v2
.Users({ id: ada.data!.id })
.patch(patchOps([{ op: 'replace', path: 'active', value }]));
await setActive(false);
// A group change reconciles the project again; the deactivated member stays out.
- await setup.scim.scim.v2
+ await own.scim.scim.v2
.Groups({ id: groupId })
.patch(patchOps([{ op: 'replace', path: 'displayName', value: 'Engineers' }]));
- expect((await membersOf(setup.god, 'MKT')).map((m) => m.userId)).not.toContain(ada.data!.id);
+ expect((await membersOf(god, 'MKT')).map((m) => m.userId)).not.toContain(ada.data!.id);
await setActive(true);
- expect((await membersOf(setup.god, 'MKT')).map((m) => m.userId)).toContain(ada.data!.id);
+ expect((await membersOf(god, 'MKT')).map((m) => m.userId)).toContain(ada.data!.id);
});
it('refuses a project of another workspace', async () => {
- const setup = await setupScim();
- const project = await createProject(setup.god, 'Marketing', 'MKT');
- const groupId = await provisionGroup(setup, 'Engineering', []);
- await setupOtherWorkspace(setup.god, [project.teamId]);
+ const god = await addUser({ email: '[email protected]' });
+ const project = await createProject(god, 'Marketing', 'MKT');
+ const own = await setupOtherWorkspace(god);
+ const groupId = await provisionGroup(own, 'Engineering', []);
- const res = await setup.settings.groups({ groupId }).mappings.put({
+ const res = await own.settings.groups({ groupId }).mappings.put({
mappings: [{ projectId: project.id, role: 'member', roleId: null }],
});
expect(res.status).toBe(400);
expect(res.error!.value).toMatchObject({ error: 'Unknown project' });
});
- });
-
- // Beside the workspaces' own, the instance's provider still grants projects of every
- // workspace, except one that set up SCIM of its own: its provider decides there.
- describe("beside the workspaces' own", () => {
- beforeEach(() => {
- setWorkspaceScim();
- setInstanceScimBeside();
- });
- afterEach(() => {
- setWorkspaceScim(false);
- setInstanceScimBeside(false);
- });
it("takes the instance's groups out of a workspace with its own, and lets them back", async () => {
const setup = await setupScim();
@@ -511,10 +505,7 @@ describe('SCIM group reconciliation', () => {
mappings: [{ projectId: project.id, role: 'member', roleId: null }],
});
const memberIds = async () => (await membersOf(outsider, 'SAL')).map((m) => m.userId);
- const options = async () =>
- (
- await setup.god.api.workspaces({ workspaceId: setup.workspaceId }).projects.options.get()
- ).data!.map((o) => o.key);
+ const options = async () => (await setup.settings.projects.get()).data!.map((o) => o.key);
expect(await memberIds()).toContain(ada.data!.id);
const own = outsider.api.workspaces({ workspaceId }).scim;
@@ -562,32 +553,6 @@ describe('SCIM group reconciliation', () => {
await own.patch({ enabled: false });
expect(await memberIds()).toContain(ada.data!.id);
});
-
- it('grants nothing to a person deactivated while SCIM was per workspace', async () => {
- setInstanceScimBeside(false);
- const setup = await setupScim();
- const project = await createProject(setup.god, 'Marketing', 'MKT');
- const ada = await setup.scim.scim.v2.Users.post(scimUserBody());
- const groupId = await provisionGroup(setup, 'Engineering', [ada.data!.id]);
- await setup.settings.groups({ groupId }).mappings.put({
- mappings: [{ projectId: project.id, role: 'member', roleId: null }],
- });
- const setActive = (value: boolean) =>
- setup.scim.scim.v2
- .Users({ id: ada.data!.id })
- .patch(patchOps([{ op: 'replace', path: 'active', value }]));
- const memberIds = async () => (await membersOf(setup.god, 'MKT')).map((m) => m.userId);
- await setActive(false);
-
- setInstanceScimBeside();
- await setup.scim.scim.v2
- .Groups({ id: groupId })
- .patch(patchOps([{ op: 'replace', path: 'displayName', value: 'Engineers' }]));
- expect(await memberIds()).not.toContain(ada.data!.id);
-
- await setActive(true);
- expect(await memberIds()).toContain(ada.data!.id);
- });
});
// A directory that never calls POST /Groups still grants access this way: it
diff --git a/apps/api/src/modules/scim/__tests__/integration/scim-users.test.ts b/apps/api/src/modules/scim/__tests__/integration/scim-users.test.ts
index c4274f37..2b9e3c40 100644
--- a/apps/api/src/modules/scim/__tests__/integration/scim-users.test.ts
+++ b/apps/api/src/modules/scim/__tests__/integration/scim-users.test.ts
@@ -1,8 +1,8 @@
import { afterEach, describe, expect, it, beforeEach } from 'bun:test';
-import { setInstanceScimBeside, setWorkspaceScim } from '@repo/auth';
+import { setWorkspaceScim } from '@repo/auth';
import { createWorkspace, db, notificationDelivery, team, teamMember } from '@repo/db';
import { eq } from 'drizzle-orm';
-import { app, authedApi } from '#tests/helpers/app';
+import { app, authedApi, ownWorkspaceId, createProject } from '#tests/helpers/app';
import { resetDb } from '#tests/helpers/db';
import { signUpTestUser } from '#tests/helpers/auth';
import { addUser, createAgentUser, joinProject, type Actor } from '#modules/god/__tests__/helpers';
@@ -276,7 +276,7 @@ describe('SCIM users', () => {
// it, which stops the agent without a trace.
it('leaves them out of the list, and 404s every route that names one', async () => {
const { god, scim } = await setupScim();
- const project = await god.api.projects.post({ name: 'Agents', key: 'AGT' });
+ const project = await createProject(god.api, { name: 'Agents', key: 'AGT' });
const agentUserId = await createAgentUser(god, project.data!.key);
const list = await scim.scim.v2.Users.get({ query: {} });
@@ -404,7 +404,7 @@ describe('SCIM users', () => {
it('leaves a deactivated account its teams and projects', async () => {
const { god, scim } = await setupScim();
const member = await addUser({ email: '[email protected]' });
- await god.api.projects.post({ name: 'Marketing', key: 'MKT' });
+ await createProject(god.api, { name: 'Marketing', key: 'MKT' });
await joinProject(god, member, 'MKT', 'member');
await scim.scim.v2
@@ -417,7 +417,7 @@ describe('SCIM users', () => {
it('sends a deactivated account no notifications', async () => {
const { god, scim } = await setupScim();
const member = await addUser({ email: '[email protected]' });
- const project = (await god.api.projects.post({ name: 'Marketing', key: 'MKT' })).data!;
+ const project = (await createProject(god.api, { name: 'Marketing', key: 'MKT' })).data!;
await joinProject(god, member, 'MKT', 'member');
await god.api.teams({ teamId: project.teamId })['notification-settings'].put({
smtp: {
@@ -574,7 +574,7 @@ describe('SCIM users', () => {
it("does not see an AI agent's account", async () => {
const { god, scim } = await setupScim();
- const project = await god.api.projects.post({ name: 'Agents', key: 'AGT' });
+ const project = await createProject(god.api, { name: 'Agents', key: 'AGT' });
const agentUserId = await createAgentUser(god, project.data!.key);
const res = await scim.scim.v2.Users({ id: agentUserId }).delete();
@@ -597,10 +597,15 @@ describe('SCIM users', () => {
expect(members).toEqual([expect.objectContaining({ userId: god.id, role: 'owner' })]);
});
- it('refuses the only owner of a project', async () => {
+ it('refuses the only owner of a project outside their own workspace', async () => {
const { god, scim } = await setupScim();
const owner = await addUser({ email: '[email protected]' });
- await owner.api.projects.post({ name: 'Solo', key: 'SOL' });
+ const [ownerTeam] = await teamsOf(owner);
+ await createProject(owner.api, { name: 'Solo', key: 'SOL' });
+ await db
+ .update(team)
+ .set({ workspaceId: await ownWorkspaceId(god.api) })
+ .where(eq(team.id, ownerTeam!.id));
expect(god.id).not.toBe(owner.id);
const res = await scim.scim.v2.Users({ id: owner.id }).delete();
@@ -643,17 +648,18 @@ describe('SCIM users', () => {
// Set up per workspace, as in a hosted build, a workspace's provider sees the accounts
// it wrote and the people in its teams. Nothing else on the instance is visible to it,
- // and what it writes stays its own.
+ // and what it writes stays its own. The instance's provider still acts on the whole
+ // instance.
describe('set up per workspace', () => {
beforeEach(() => setWorkspaceScim());
afterEach(() => setWorkspaceScim(false));
it('sees nobody outside its own teams', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const member = await addUser({ email: '[email protected]' });
const outsider = await addUser({ email: '[email protected]' });
- const [outsiderTeam] = (await outsider.api.teams.get()).data!;
- await setupOtherWorkspace(god, [outsiderTeam!.id]);
+ const [memberTeam] = await teamsOf(member);
+ const { scim } = await setupOtherWorkspace(god, [memberTeam!.id]);
const list = await scim.scim.v2.Users.get({ query: {} });
const ids = list.data!.Resources.map((u) => u.id);
@@ -667,7 +673,8 @@ describe('SCIM users', () => {
});
it('links the same person in two workspaces, each with its own id', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
+ const { scim } = await setupOtherWorkspace(god);
const other = await setupOtherWorkspace(god);
const ada = await scim.scim.v2.Users.post(scimUserBody({ externalId: 'first-1' }));
expect((await other.scim.scim.v2.Users({ id: ada.data!.id }).get()).status).toBe(404);
@@ -682,14 +689,16 @@ describe('SCIM users', () => {
});
it('deactivates a person in its own workspace only', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const owner = await addUser({ email: '[email protected]' });
const person = await addUser({ email: '[email protected]' });
- await god.api.projects.post({ name: 'Marketing', key: 'MKT' });
+ const [godTeam] = await teamsOf(god);
+ await createProject(god.api, { name: 'Marketing', key: 'MKT' });
await joinProject(god, person, 'MKT', 'member');
const [ownerTeam] = await teamsOf(owner);
- await owner.api.projects.post({ name: 'Sales', key: 'SAL' });
+ await createProject(owner.api, { name: 'Sales', key: 'SAL' });
await joinProject(owner, person, 'SAL', 'member');
+ const { scim } = await setupOtherWorkspace(god, [godTeam!.id]);
const other = await setupOtherWorkspace(owner, [ownerTeam!.id]);
const res = await other.scim.scim.v2
@@ -704,7 +713,8 @@ describe('SCIM users', () => {
});
it("writes the provider's id and keeps the name and address the account holds", async () => {
- const { scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
+ const { scim } = await setupOtherWorkspace(god);
const created = await scim.scim.v2.Users.post(scimUserBody({ externalId: 'idp-1' }));
const res = await scim.scim.v2.Users({ id: created.data!.id }).put(
@@ -724,10 +734,12 @@ describe('SCIM users', () => {
});
it('takes a deactivated person out of the workspace and leaves the account', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const member = await addUser({ email: '[email protected]' });
- await god.api.projects.post({ name: 'Marketing', key: 'MKT' });
+ const [godTeam] = await teamsOf(god);
+ await createProject(god.api, { name: 'Marketing', key: 'MKT' });
await joinProject(god, member, 'MKT', 'member');
+ const { scim } = await setupOtherWorkspace(god, [godTeam!.id]);
const res = await scim.scim.v2
.Users({ id: member.id })
@@ -736,7 +748,7 @@ describe('SCIM users', () => {
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ active: false });
expect(await memberIdsOf(god, 'MKT')).not.toContain(member.id);
- expect(await teamsOf(member)).toHaveLength(0);
+ expect((await teamsOf(member)).map((t) => t.id)).not.toContain(godTeam!.id);
expect((await member.api.me.get()).data).toMatchObject({ authenticated: true });
const signIn = await app.handle(
new Request('http://localhost/api/auth/sign-in/email', {
@@ -749,10 +761,11 @@ describe('SCIM users', () => {
});
it('passes a team and a project the person owned alone to the workspace owner', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const member = await addUser({ email: '[email protected]' });
const [ownTeam] = await teamsOf(member);
- await member.api.projects.post({ name: 'Solo', key: 'SOL' });
+ await createProject(member.api, { name: 'Solo', key: 'SOL' });
+ const { scim } = await setupOtherWorkspace(god, [ownTeam!.id]);
await scim.scim.v2
.Users({ id: member.id })
@@ -765,7 +778,7 @@ describe('SCIM users', () => {
});
it('refuses to deactivate the workspace owner', async () => {
- const { god } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const owner = await addUser({ email: '[email protected]' });
const [ownerTeam] = await teamsOf(owner);
const other = await setupOtherWorkspace(owner, [ownerTeam!.id]);
@@ -783,7 +796,8 @@ describe('SCIM users', () => {
});
it('accepts the path-less replace some providers send', async () => {
- const { scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
+ const { scim } = await setupOtherWorkspace(god);
const created = await scim.scim.v2.Users.post(scimUserBody());
const res = await scim.scim.v2
@@ -795,7 +809,8 @@ describe('SCIM users', () => {
});
it('accepts a name and an address and leaves the account its own', async () => {
- const { scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
+ const { scim } = await setupOtherWorkspace(god);
const created = await scim.scim.v2.Users.post(scimUserBody());
const res = await scim.scim.v2.Users({ id: created.data!.id }).patch(
@@ -814,11 +829,14 @@ describe('SCIM users', () => {
});
it('takes the person out of the workspace and keeps the account', async () => {
- const { god, scim } = await setupScim();
+ const god = await addUser({ email: '[email protected]' });
const member = await addUser({ email: '[email protected]' });
- await god.api.projects.post({ name: 'Marketing', key: 'MKT' });
+ const [godTeam] = await teamsOf(god);
+ const [memberTeam] = await teamsOf(member);
+ await createProject(god.api, { name: 'Marketing', key: 'MKT' });
await joinProject(god, member, 'MKT', 'member');
- await member.api.projects.post({ name: 'Solo', key: 'SOL' });
+ await createProject(member.api, { name: 'Solo', key: 'SOL' });
+ const { scim } = await setupOtherWorkspace(god, [godTeam!.id, memberTeam!.id]);
const res = await scim.scim.v2.Users({ id: member.id }).delete();
@@ -828,19 +846,6 @@ describe('SCIM users', () => {
expect(await memberIdsOf(god, 'SOL')).toEqual([god.id]);
expect((await god.api.god.users({ userId: member.id }).get()).status).toBe(200);
});
- });
-
- // Beside the workspaces' own, the instance's provider still acts on the whole instance,
- // and every other workspace's on its own workspace.
- describe("beside the workspaces' own", () => {
- beforeEach(() => {
- setWorkspaceScim();
- setInstanceScimBeside();
- });
- afterEach(() => {
- setWorkspaceScim(false);
- setInstanceScimBeside(false);
- });
it("lets the instance's provider deactivate an account in any workspace", async () => {
const { god, scim } = await setupScim();
diff --git a/apps/api/src/modules/scim/email-policy.ts b/apps/api/src/modules/scim/email-policy.ts
index 797dfcb6..a4e83846 100644
--- a/apps/api/src/modules/scim/email-policy.ts
+++ b/apps/api/src/modules/scim/email-policy.ts
@@ -1,16 +1,16 @@
-export type ScimEmailPolicy = (workspaceId: number, email: string) => Promise<boolean>;
+export type ScimEmailPolicy = (workspaceId: number | null, email: string) => Promise<boolean>;
const allowAny: ScimEmailPolicy = async () => true;
-// Whether a workspace's identity provider may provision an address. A self-hosted
-// instance takes any address, since only its owner sets up provisioning; a hosted build
-// installs a check against the domains the workspace has verified.
+// Whether an identity provider may provision an address: a workspace's, or the
+// instance's for null. By default any address, since only god sets up the instance's
+// provider; a hosted build installs a check against the domains a workspace verified.
let policy: ScimEmailPolicy = allowAny;
export function setScimEmailPolicy(next: ScimEmailPolicy = allowAny): void {
policy = next;
}
-export function isScimEmailAllowed(workspaceId: number, email: string): Promise<boolean> {
+export function isScimEmailAllowed(workspaceId: number | null, email: string): Promise<boolean> {
return policy(workspaceId, email);
}
diff --git a/apps/api/src/modules/scim/index.ts b/apps/api/src/modules/scim/index.ts
index b99facde..0dec849e 100644
--- a/apps/api/src/modules/scim/index.ts
+++ b/apps/api/src/modules/scim/index.ts
@@ -38,7 +38,6 @@ import {
import {
GROUP_FILTER_ATTRIBUTES,
USER_FILTER_ATTRIBUTES,
- actsOnInstance,
createScimGroup,
createScimUser,
deleteScimGroup,
@@ -53,8 +52,8 @@ import {
} from './service';
// SCIM 2.0 provisioning (RFC 7643 / 7644). An identity provider pushes users and
-// groups here with a workspace's SCIM bearer token, and every request acts for that
-// workspace.
+// groups here with a SCIM bearer token, and every request acts for the provider it
+// opens: the instance's (`workspaceId` null) or a workspace's.
function extractToken(authorization: string | undefined): string | null {
return authorization?.match(/^Bearer\s+(.+)$/i)?.[1] ?? null;
@@ -66,9 +65,9 @@ function extractToken(authorization: string | undefined): string | null {
// which raises SCIM errors rather than the planner's validation error.
const anyBody = { body: t.Any() };
-// The name and address of the account. While SCIM is the instance's, the provider keeps
-// them in step. Set up per workspace, they are the person's own, not the workspace's, so
-// a provider that sends them on every sync gets them accepted and left as they are.
+// The name and address of the account. The instance's provider keeps them in step. For a
+// workspace's they are the person's own, not the workspace's, so a provider that sends
+// them on every sync gets them accepted and left as they are.
const ACCOUNT_ATTRIBUTE = /^(username|displayname|name(\..+)?|emails(\[.*])?(\..+)?)$/;
// What one PATCH operation on an account attribute sets. `name` is the name before it,
@@ -122,9 +121,9 @@ const scimHandlers = new Elysia({
const token = extractToken(headers.authorization);
// One answer for "off", "no token" and "wrong token": whether provisioning is
// configured is not something an unauthenticated caller should learn.
- const workspaceId = token ? await verifyScimToken(token) : null;
- if (workspaceId === null) throw new ScimError(401, 'Invalid or missing SCIM bearer token');
- return { workspaceId };
+ const provider = token ? await verifyScimToken(token) : null;
+ if (!provider) throw new ScimError(401, 'Invalid or missing SCIM bearer token');
+ return { workspaceId: provider.workspaceId };
})
// ── Discovery ───────────────────────────────────────────────────────────────
@@ -227,15 +226,16 @@ const scimHandlers = new Elysia({
'/Users/:id',
async ({ workspaceId, params, body }) => {
const doc = asDoc(body);
- const account = (await actsOnInstance(workspaceId))
- ? {
- email: readAccountEmail(doc),
- name: joinName(
- doc.name as never,
- (doc.displayName as string) || (await requireUser(workspaceId, params.id)).name,
- ),
- }
- : {};
+ const account =
+ workspaceId === null
+ ? {
+ email: readAccountEmail(doc),
+ name: joinName(
+ doc.name as never,
+ (doc.displayName as string) || (await requireUser(workspaceId, params.id)).name,
+ ),
+ }
+ : {};
const updated = await updateScimUser(workspaceId, params.id, {
...account,
active: doc.active === undefined ? true : asBoolean(doc.active),
@@ -261,7 +261,6 @@ const scimHandlers = new Elysia({
const ops = parsePatch(body);
// The address comes from `emails` when the request carries it, as on a create.
const sendsEmails = ops.some((op) => op.path!.toLowerCase().startsWith('emails'));
- const instanceWide = await actsOnInstance(workspaceId);
for (const op of ops) {
const path = op.path!.toLowerCase();
if (op.op === 'remove') {
@@ -277,7 +276,7 @@ const scimHandlers = new Elysia({
else if (path === 'externalid') patch.externalId = asString(op.value, 'externalId');
else if (!ACCOUNT_ATTRIBUTE.test(path)) {
throw new ScimError(400, `Attribute '${op.path}' is not writable`, 'invalidPath');
- } else if (instanceWide && !(path === 'username' && sendsEmails)) {
+ } else if (workspaceId === null && !(path === 'username' && sendsEmails)) {
const name = patch.name ?? (await requireUser(workspaceId, params.id)).name;
Object.assign(patch, accountOp(path, op.value, name));
}
@@ -463,13 +462,13 @@ function requireUpdated<T>(record: T | null, resource: string, id: string): T {
return record;
}
-async function requireUser(workspaceId: number, id: string) {
+async function requireUser(workspaceId: number | null, id: string) {
const record = await getScimUser(workspaceId, id);
if (!record) throw new ScimError(404, `User '${id}' not found`);
return record;
}
-async function requireGroup(workspaceId: number, id: string) {
+async function requireGroup(workspaceId: number | null, id: string) {
const record = await getScimGroup(workspaceId, id);
if (!record) throw new ScimError(404, `Group '${id}' not found`);
return record;
diff --git a/apps/api/src/modules/workspaces/scim.ts b/apps/api/src/modules/scim/mappings.ts
similarity index 78%
rename from apps/api/src/modules/workspaces/scim.ts
rename to apps/api/src/modules/scim/mappings.ts
index fac1ae4e..772ceb6d 100644
--- a/apps/api/src/modules/workspaces/scim.ts
+++ b/apps/api/src/modules/scim/mappings.ts
@@ -8,16 +8,17 @@ import {
teamRole,
} from '@repo/db';
import { and, asc, eq, inArray, notInArray, or, sql } from 'drizzle-orm';
-import { instanceScimWorkspace, workspacesWithOwnScim } from '@repo/auth';
+import { workspacesWithOwnScim } from '@repo/auth';
import { HttpError } from '#shared/lib';
-import { mappedProjectIds, reconcileProjects } from '#modules/scim/reconcile';
+import { mappedProjectIds, reconcileProjects } from './reconcile';
+import { ofProvider } from './service';
-// The groups a workspace's identity provider has pushed, and what each one grants.
-// The group and its members belong to the provider and are read-only here; the
-// mappings are the workspace owner's, and are what turns group membership into
-// project access. A group grants projects of its own workspace when SCIM is set up per
-// workspace, and any project while it is the instance's.
-export interface WorkspaceScimGroupMapping {
+// The groups an identity provider has pushed, and what each one grants: the instance's
+// for `workspaceId` null, set up by god, or a workspace's, set up by its owner. The group
+// and its members belong to the provider and are read-only here; the mappings are what
+// turns group membership into project access. The instance's groups grant any project
+// outside a workspace with SCIM of its own, a workspace's the projects of that workspace.
+export interface ProvisionedGroupMapping {
projectId: number;
projectKey: string;
projectName: string;
@@ -25,26 +26,25 @@ export interface WorkspaceScimGroupMapping {
roleId: number | null;
}
-export interface WorkspaceScimGroup {
+export interface ProvisionedGroup {
id: string;
displayName: string;
externalId: string | null;
memberCount: number;
- mappings: WorkspaceScimGroupMapping[];
+ mappings: ProvisionedGroupMapping[];
}
-export async function listWorkspaceScimGroups(workspaceId: number): Promise<WorkspaceScimGroup[]> {
+export async function listProvisionedGroups(
+ workspaceId: number | null,
+): Promise<ProvisionedGroup[]> {
+ const own = ofProvider(scimGroup.workspaceId, workspaceId);
const [groups, counts, mappings] = await Promise.all([
- db
- .select()
- .from(scimGroup)
- .where(eq(scimGroup.workspaceId, workspaceId))
- .orderBy(scimGroup.displayName),
+ db.select().from(scimGroup).where(own).orderBy(scimGroup.displayName),
db
.select({ groupId: scimGroupMember.groupId, count: sql<number>`count(*)::int` })
.from(scimGroupMember)
.innerJoin(scimGroup, eq(scimGroup.id, scimGroupMember.groupId))
- .where(eq(scimGroup.workspaceId, workspaceId))
+ .where(own)
.groupBy(scimGroupMember.groupId),
db
.select({
@@ -58,7 +58,7 @@ export async function listWorkspaceScimGroups(workspaceId: number): Promise<Work
.from(scimGroupMapping)
.innerJoin(scimGroup, eq(scimGroup.id, scimGroupMapping.groupId))
.innerJoin(project, eq(project.id, scimGroupMapping.projectId))
- .where(eq(scimGroup.workspaceId, workspaceId))
+ .where(own)
.orderBy(project.name),
]);
@@ -83,15 +83,15 @@ export async function listWorkspaceScimGroups(workspaceId: number): Promise<Work
// Replaces what a group grants, then reconciles every project the change touched —
// the ones it granted before as well as the ones it grants now, so a project it was
// unmapped from loses the memberships that came from it.
-export async function setWorkspaceScimGroupMappings(
- workspaceId: number,
+export async function setGroupMappings(
+ workspaceId: number | null,
groupId: string,
mappings: { projectId: number; role: 'owner' | 'member'; roleId: number | null }[],
-): Promise<WorkspaceScimGroup> {
+): Promise<ProvisionedGroup> {
const found = await db
.select({ id: scimGroup.id })
.from(scimGroup)
- .where(and(eq(scimGroup.id, groupId), eq(scimGroup.workspaceId, workspaceId)));
+ .where(and(eq(scimGroup.id, groupId), ofProvider(scimGroup.workspaceId, workspaceId)));
if (!found[0]) throw new HttpError(404, 'Group not found');
const projectIds = mappings.map((m) => m.projectId);
@@ -144,13 +144,13 @@ export async function setWorkspaceScimGroupMappings(
});
await reconcileProjects([...before, ...projectIds]);
- const groups = await listWorkspaceScimGroups(workspaceId);
+ const groups = await listProvisionedGroups(workspaceId);
return groups.find((g) => g.id === groupId)!;
}
// Every project a group may grant, with the roles of the team that owns it. What the
// group mapping form fills its project and role selects from.
-export async function listWorkspaceProjectOptions(workspaceId: number) {
+export async function listMappableProjects(workspaceId: number | null) {
const where = await grantable(workspaceId);
const [projects, roles] = await Promise.all([
db
@@ -172,10 +172,11 @@ export async function listWorkspaceProjectOptions(workspaceId: number) {
}));
}
-// The teams whose projects a workspace's groups may grant, as a condition on `team`: its
-// own, or for the instance's provider every team outside a workspace with SCIM of its own.
-async function grantable(workspaceId: number) {
- if (workspaceId !== (await instanceScimWorkspace())) return eq(team.workspaceId, workspaceId);
+// The teams whose projects a provider's groups may grant, as a condition on `team`: a
+// workspace's own, or for the instance's provider every team outside a workspace with
+// SCIM of its own.
+async function grantable(workspaceId: number | null) {
+ if (workspaceId !== null) return eq(team.workspaceId, workspaceId);
const own = await workspacesWithOwnScim();
return own.length > 0 ? notInArray(team.workspaceId, own) : undefined;
}
diff --git a/apps/api/src/modules/scim/model.ts b/apps/api/src/modules/scim/model.ts
index a0a7ed8f..561fd93f 100644
--- a/apps/api/src/modules/scim/model.ts
+++ b/apps/api/src/modules/scim/model.ts
@@ -92,3 +92,56 @@ export const scimErrors = <const C extends readonly number[]>(...codes: C) =>
Object.fromEntries(codes.map((code) => [code, ScimErrorResponse])) as {
[K in C[number]]: typeof ScimErrorResponse;
};
+
+// ── Settings ──────────────────────────────────────────────────────────────────
+// The routes god mode and a workspace's settings set a provider up with.
+
+export const ScimSettingsResponse = t.Object({
+ enabled: t.Boolean(),
+ hasToken: t.Boolean(),
+ tokenPrefix: t.String(),
+ // Where to point the identity provider. Derived from the API origin, so the UI
+ // shows it rather than asking the owner to assemble it.
+ baseUrl: t.String(),
+});
+
+export const ScimSettingsBody = t.Object({
+ enabled: t.Optional(t.Boolean()),
+});
+
+// The generated token, returned once. It is not stored anywhere it can be read
+// back, so a lost token is replaced rather than recovered.
+export const ScimTokenResponse = t.Object({
+ token: t.String(),
+});
+
+const scimGroupMapping = t.Object({
+ projectId: t.Integer(),
+ role: t.UnionEnum(['owner', 'member']),
+ // Which team_role a member joins on. Null for an owner (owners bypass the
+ // permission matrix) or to fall back to the team's default role.
+ roleId: t.Nullable(t.Integer()),
+});
+
+export const ProvisionedGroupResponse = t.Object({
+ id: t.String(),
+ displayName: t.String(),
+ externalId: t.Nullable(t.String()),
+ memberCount: t.Integer(),
+ mappings: t.Array(
+ t.Intersect([scimGroupMapping, t.Object({ projectKey: t.String(), projectName: t.String() })]),
+ ),
+});
+
+export const ScimGroupMappingsBody = t.Object({
+ mappings: t.Array(scimGroupMapping, { maxItems: 100 }),
+});
+
+export const MappableProjectListResponse = t.Array(
+ t.Object({
+ id: t.Number(),
+ key: t.String(),
+ name: t.String(),
+ roles: t.Array(t.Object({ id: t.Number(), name: t.String() })),
+ }),
+);
diff --git a/apps/api/src/modules/scim/oidc-sync.ts b/apps/api/src/modules/scim/oidc-sync.ts
index 149e94e2..71107a2a 100644
--- a/apps/api/src/modules/scim/oidc-sync.ts
+++ b/apps/api/src/modules/scim/oidc-sync.ts
@@ -1,5 +1,5 @@
import { and, desc, eq } from 'drizzle-orm';
-import { db, account, instanceWorkspaceId } from '@repo/db';
+import { db, account } from '@repo/db';
import { auth, OIDC_PROVIDER_ID } from '@repo/auth';
import { groupDisplayNames } from './resource';
import { syncEmbeddedGroups } from './service';
@@ -7,9 +7,9 @@ import { syncEmbeddedGroups } from './service';
// Folds an OIDC sign-in's `groups` claim into the same scim_group /
// scim_group_member tables a SCIM sync writes to, so a group mapped to a project
// grants access in a workspace that uses OIDC, SCIM, or both. The provider is the
-// instance's, set in god mode, and its groups go to the instance workspace. Runs
-// after every successful callback, not just the first one, so membership follows the
-// provider going forward.
+// instance's, set in god mode, so its groups are the instance's SCIM groups. Runs after
+// every successful callback, not just the first one, so membership follows the provider
+// going forward.
//
// The claim lives in the ID token, not necessarily the userinfo response some
// providers keep small — better-auth stores the raw token on the linked `account`
@@ -57,7 +57,7 @@ export async function syncOidcGroupsAfterCallback(response: Response): Promise<v
const claims = decodeJwtPayload(idToken);
const names = groupDisplayNames(claims?.groups);
- await syncEmbeddedGroups(await instanceWorkspaceId(db), session.user.id, names);
+ await syncEmbeddedGroups(null, session.user.id, names);
} catch (error) {
console.error('[scim] OIDC group sync failed:', error);
}
diff --git a/apps/api/src/modules/scim/reconcile.ts b/apps/api/src/modules/scim/reconcile.ts
index cd98141f..1c446a9d 100644
--- a/apps/api/src/modules/scim/reconcile.ts
+++ b/apps/api/src/modules/scim/reconcile.ts
@@ -10,8 +10,8 @@ import {
teamWorkspaceId,
user,
} from '@repo/db';
-import { and, eq, isNull, ne, or } from 'drizzle-orm';
-import { instanceScimWorkspace, workspacesWithOwnScim } from '@repo/auth';
+import { and, eq, isNotNull, isNull, or, sql } from 'drizzle-orm';
+import { workspacesWithOwnScim } from '@repo/auth';
import { removeMember, setMembership, type MemberRole } from '#modules/members/service';
import { listSeatHolderIds } from '#modules/teams/service';
import { getLimits } from '#shared/limits';
@@ -38,18 +38,14 @@ export async function reconcileProjects(projectIds: number[]): Promise<void> {
// The group members whose mappings grant a project of this workspace, as a condition on
// `scimGroup`, `scimUser` and `user`. A person a workspace's provider deactivated is
// granted nothing by its groups. An account the instance's provider deactivated keeps
-// what it had: it cannot sign in, and is back where it was once reactivated. A person it
-// deactivated in `scim_user` alone, as it did while it ran per workspace, can still sign
-// in, so its groups grant them nothing. The instance's groups grant nothing in a
-// workspace that set up SCIM of its own.
+// what it had: it cannot sign in, and is back where it was once reactivated. The
+// instance's groups grant nothing in a workspace that set up SCIM of its own.
async function grantingMembers(workspaceId: number) {
const active = or(isNull(scimUser.active), eq(scimUser.active, true));
- const instanceId = await instanceScimWorkspace();
- if (instanceId === null) return active;
if ((await workspacesWithOwnScim()).includes(workspaceId)) {
- return and(ne(scimGroup.workspaceId, instanceId), active);
+ return and(isNotNull(scimGroup.workspaceId), active);
}
- return or(active, and(eq(scimGroup.workspaceId, instanceId), eq(user.active, false)));
+ return or(active, and(isNull(scimGroup.workspaceId), eq(user.active, false)));
}
// Who the mappings say should be a member of this project. A user reachable
@@ -73,7 +69,7 @@ async function desiredMembers(
.leftJoin(
scimUser,
and(
- eq(scimUser.workspaceId, scimGroup.workspaceId),
+ sql`${scimUser.workspaceId} IS NOT DISTINCT FROM ${scimGroup.workspaceId}`,
eq(scimUser.userId, scimGroupMember.userId),
),
)
diff --git a/apps/api/src/modules/scim/service.ts b/apps/api/src/modules/scim/service.ts
index e6c01fc1..92cd5c68 100644
--- a/apps/api/src/modules/scim/service.ts
+++ b/apps/api/src/modules/scim/service.ts
@@ -12,8 +12,19 @@ import {
user,
workspaceManager,
} from '@repo/db';
-import { and, eq, exists, inArray, isNotNull, notExists, or, sql } from 'drizzle-orm';
-import { generateUsername, instanceScimWorkspace } from '@repo/auth';
+import {
+ and,
+ eq,
+ exists,
+ inArray,
+ isNotNull,
+ isNull,
+ notExists,
+ or,
+ sql,
+ type Column,
+} from 'drizzle-orm';
+import { generateUsername } from '@repo/auth';
import { iso } from '#shared/lib';
import { deleteAccount } from '#shared/account-deletion';
import { countOwners } from '#modules/members/service';
@@ -22,18 +33,18 @@ import { ScimError, type ScimFilter, type ScimGroupRecord, type ScimUserRecord }
import { isScimEmailAllowed } from './email-policy';
import { mappedProjectIds, reconcileProjects } from './reconcile';
-// Data access for the SCIM endpoints. Every call acts for the one workspace the
-// bearer token opened, and what its provider says about a person — its own id for
-// them and whether they are active — is kept per workspace in `scim_user`.
+// Data access for the SCIM endpoints. Every call acts for the one provider the bearer
+// token opened: a workspace's, or the instance's when `workspaceId` is null. What a
+// provider says about a person — its own id for them and whether they are active — is
+// kept per provider in `scim_user`.
//
-// How far a provider reaches depends on its workspace (`instanceScimWorkspace()` in
-// @repo/auth). The instance workspace's, on a self-hosted instance and wherever it stays
-// beside the workspaces', is the instance owner's and acts on the whole instance: it
-// sees every account, keeps names and addresses in step, a deactivated account cannot
-// sign in, and a delete removes the account. Any other workspace's, as in a hosted
-// build, decides who has the workspace, not who has an account: it sees the accounts it
-// linked and the people in the workspace's teams, deactivating or deleting someone takes
-// them out of those teams, and their name, address and sign-in stay as they are.
+// The instance's provider is set up by god in god mode and acts on the whole instance:
+// it sees every account, keeps names and addresses in step, a deactivated account
+// cannot sign in, and a delete removes the account. A workspace's, where a hosted build
+// sets SCIM up per workspace, decides who has the workspace, not who has an account: it
+// sees the accounts it linked and the people in the workspace's teams, deactivating or
+// deleting someone takes them out of those teams, and their name, address and sign-in
+// stay as they are.
//
// A create for an address that has no account inserts the `user` row directly rather
// than going through better-auth's sign-up — the same way an agent's bot user is
@@ -58,21 +69,35 @@ const notAnAgent = notExists(
.where(eq(aiAgent.userId, user.id)),
);
-// The join of an account to what this workspace's provider says about it. Every user
-// query here left-joins it: a person in the workspace's teams the provider never
-// wrote has no row.
-function linkOf(workspaceId: number) {
- return and(eq(scimUser.userId, user.id), eq(scimUser.workspaceId, workspaceId));
+// A row of this provider, on a `workspace_id` column.
+export function ofProvider(column: Column, workspaceId: number | null) {
+ return workspaceId === null ? isNull(column) : eq(column, workspaceId);
+}
+
+// The unique key a provider's row conflicts on. The instance's rows have no workspace,
+// so they are unique on a partial index of their own (see schema/scim.ts in @repo/db).
+function scimUserConflict(workspaceId: number | null) {
+ return workspaceId === null
+ ? { target: scimUser.userId, targetWhere: isNull(scimUser.workspaceId) }
+ : { target: [scimUser.workspaceId, scimUser.userId] };
+}
+
+function scimGroupConflict(workspaceId: number | null) {
+ return workspaceId === null
+ ? { target: scimGroup.displayName, where: isNull(scimGroup.workspaceId) }
+ : { target: [scimGroup.workspaceId, scimGroup.displayName] };
}
-export async function actsOnInstance(workspaceId: number): Promise<boolean> {
- return workspaceId === (await instanceScimWorkspace());
+// The join of an account to what this provider says about it. Every user query here
+// left-joins it: a person in the workspace's teams the provider never wrote has no row.
+function linkOf(workspaceId: number | null) {
+ return and(eq(scimUser.userId, user.id), ofProvider(scimUser.workspaceId, workspaceId));
}
// The accounts a workspace's provider sees: the ones it wrote, and the people in the
// workspace's teams. The instance's provider, every account.
-async function inWorkspace(workspaceId: number) {
- if (await actsOnInstance(workspaceId)) return notAnAgent;
+function inWorkspace(workspaceId: number | null) {
+ if (workspaceId === null) return notAnAgent;
return and(
notAnAgent,
or(
@@ -132,18 +157,18 @@ const userColumns = {
// ── Users ─────────────────────────────────────────────────────────────────────
-async function userWhere(workspaceId: number, filter: ScimFilter | null) {
- const seen = await inWorkspace(workspaceId);
+function userWhere(workspaceId: number | null, filter: ScimFilter | null) {
+ const seen = inWorkspace(workspaceId);
if (!filter) return seen;
if (filter.attribute === 'externalid') return and(seen, eq(scimUser.externalId, filter.value));
return and(seen, emailEq(filter.value));
}
export async function listScimUsers(
- workspaceId: number,
+ workspaceId: number | null,
options: { filter: ScimFilter | null; startIndex: number; count: number },
): Promise<{ records: ScimUserRecord[]; total: number }> {
- const where = await userWhere(workspaceId, options.filter);
+ const where = userWhere(workspaceId, options.filter);
const [rows, totals] = await Promise.all([
db
.select(userColumns)
@@ -162,12 +187,15 @@ export async function listScimUsers(
return { records: rows.map(toUserRecord), total: totals[0]?.count ?? 0 };
}
-export async function getScimUser(workspaceId: number, id: string): Promise<ScimUserRecord | null> {
+export async function getScimUser(
+ workspaceId: number | null,
+ id: string,
+): Promise<ScimUserRecord | null> {
const rows = await db
.select(userColumns)
.from(user)
.leftJoin(scimUser, linkOf(workspaceId))
- .where(and(eq(user.id, id), await inWorkspace(workspaceId)));
+ .where(and(eq(user.id, id), inWorkspace(workspaceId)));
return rows[0] ? toUserRecord(rows[0]) : null;
}
@@ -182,8 +210,8 @@ function assertNotGod(role: string | null, action: string): void {
// person owned alone, so the workspace's own provider cannot take it from them. The
// instance's provider answers to the instance owner, whom assertNotGod covers, and
// nothing is handed over.
-async function assertNotWorkspaceOwner(workspaceId: number, userId: string): Promise<void> {
- if (await actsOnInstance(workspaceId)) return;
+async function assertNotWorkspaceOwner(workspaceId: number | null, userId: string): Promise<void> {
+ if (workspaceId === null) return;
const [owner] = await db
.select({ userId: workspaceManager.userId })
.from(workspaceManager)
@@ -200,14 +228,14 @@ async function assertNotWorkspaceOwner(workspaceId: number, userId: string): Pro
}
export async function createScimUser(
- workspaceId: number,
+ workspaceId: number | null,
input: { email: string; name: string; active: boolean; externalId: string | null },
): Promise<ScimUserRecord> {
const email = input.email.trim().toLowerCase();
if (!(await isScimEmailAllowed(workspaceId, email))) {
throw new ScimError(
400,
- `The address '${input.email}' is not in a domain of this workspace`,
+ `The address '${input.email}' is not in an allowed domain`,
'invalidValue',
);
}
@@ -235,7 +263,7 @@ export async function createScimUser(
// creating a second one, and leaves its name and username as the person set them.
// For the instance's provider, `active` is the account's own: it decides whether the
// account signs in at all.
- const instanceWide = await actsOnInstance(workspaceId);
+ const instanceWide = workspaceId === null;
const userId = await db.transaction(async (tx) => {
let id = existing?.id;
if (id && instanceWide) {
@@ -262,7 +290,7 @@ export async function createScimUser(
.insert(scimUser)
.values({ workspaceId, userId: id, externalId: input.externalId, active: input.active })
.onConflictDoUpdate({
- target: [scimUser.workspaceId, scimUser.userId],
+ ...scimUserConflict(workspaceId),
set: { externalId: input.externalId, active: input.active },
});
return id;
@@ -277,7 +305,7 @@ export async function createScimUser(
// those are the person's own, and a PUT or PATCH that carries them leaves them as they
// are.
export async function updateScimUser(
- workspaceId: number,
+ workspaceId: number | null,
id: string,
patch: { email?: string; name?: string; active?: boolean; externalId?: string | null },
): Promise<ScimUserRecord | null> {
@@ -285,20 +313,20 @@ export async function updateScimUser(
.select({ role: user.role, active: scimUser.active })
.from(user)
.leftJoin(scimUser, linkOf(workspaceId))
- .where(and(eq(user.id, id), await inWorkspace(workspaceId)));
+ .where(and(eq(user.id, id), inWorkspace(workspaceId)));
if (!target) return null;
assertNotGod(target.role, 'updated');
const wasActive = target.active !== false;
const active = patch.active ?? wasActive;
if (wasActive && !active) await assertNotWorkspaceOwner(workspaceId, id);
- const instanceWide = await actsOnInstance(workspaceId);
+ const instanceWide = workspaceId === null;
if (instanceWide) await updateAccount(id, { ...patch, active });
await db
.insert(scimUser)
.values({ workspaceId, userId: id, externalId: patch.externalId ?? null, active })
.onConflictDoUpdate({
- target: [scimUser.workspaceId, scimUser.userId],
+ ...scimUserConflict(workspaceId),
set: { active, ...(patch.externalId !== undefined ? { externalId: patch.externalId } : {}) },
});
if (wasActive && !active && !instanceWide) await dropWorkspaceMemberships(workspaceId, id);
@@ -339,14 +367,14 @@ async function updateAccount(
.where(eq(user.id, id));
}
-// The projects the workspace's groups grant this person.
-async function groupProjectIds(workspaceId: number, userId: string): Promise<number[]> {
+// The projects the provider's groups grant this person.
+async function groupProjectIds(workspaceId: number | null, userId: string): Promise<number[]> {
const rows = await db
.select({ projectId: scimGroupMapping.projectId })
.from(scimGroupMapping)
.innerJoin(scimGroupMember, eq(scimGroupMember.groupId, scimGroupMapping.groupId))
.innerJoin(scimGroup, eq(scimGroup.id, scimGroupMapping.groupId))
- .where(and(eq(scimGroup.workspaceId, workspaceId), eq(scimGroupMember.userId, userId)));
+ .where(and(ofProvider(scimGroup.workspaceId, workspaceId), eq(scimGroupMember.userId, userId)));
return rows.map((row) => row.projectId);
}
@@ -364,7 +392,7 @@ async function groupProjectIds(workspaceId: number, userId: string): Promise<num
// there is nothing to compare against without one of the two mechanisms winning
// over the other by accident.
export async function syncEmbeddedGroups(
- workspaceId: number,
+ workspaceId: number | null,
userId: string,
displayNames: string[],
): Promise<void> {
@@ -374,7 +402,7 @@ export async function syncEmbeddedGroups(
const created = await db
.insert(scimGroup)
.values({ workspaceId, displayName })
- .onConflictDoNothing({ target: [scimGroup.workspaceId, scimGroup.displayName] })
+ .onConflictDoNothing(scimGroupConflict(workspaceId))
.returning({ id: scimGroup.id });
if (created[0]) {
groupIds.push(created[0].id);
@@ -383,7 +411,9 @@ export async function syncEmbeddedGroups(
const existing = await db
.select({ id: scimGroup.id })
.from(scimGroup)
- .where(and(eq(scimGroup.workspaceId, workspaceId), eq(scimGroup.displayName, displayName)));
+ .where(
+ and(ofProvider(scimGroup.workspaceId, workspaceId), eq(scimGroup.displayName, displayName)),
+ );
groupIds.push(existing[0]!.id);
}
await db
@@ -398,17 +428,17 @@ export async function syncEmbeddedGroups(
// workspace: its teams, its projects and its groups. The account stays. The instance's
// provider removes the account, the way god mode does; deprovisioning normally arrives
// as `active: false` instead.
-export async function deleteScimUser(workspaceId: number, id: string): Promise<void> {
+export async function deleteScimUser(workspaceId: number | null, id: string): Promise<void> {
const [target] = await db
.select({ role: user.role })
.from(user)
.leftJoin(scimUser, linkOf(workspaceId))
- .where(and(eq(user.id, id), await inWorkspace(workspaceId)));
+ .where(and(eq(user.id, id), inWorkspace(workspaceId)));
// An agent's bot user and an account outside the workspace are not part of its
// SCIM user surface at all, so they answer the same way an unknown id does.
if (!target) throw new ScimError(404, `User '${id}' not found`);
assertNotGod(target.role, 'deleted');
- if (await actsOnInstance(workspaceId)) {
+ if (workspaceId === null) {
if (await ownsProjectAlone(id)) {
throw new ScimError(
409,
@@ -478,23 +508,23 @@ async function ownsProjectAlone(userId: string): Promise<boolean> {
// ── Groups ────────────────────────────────────────────────────────────────────
-function groupWhere(workspaceId: number, filter: ScimFilter | null) {
- const inWorkspace = eq(scimGroup.workspaceId, workspaceId);
- if (!filter) return inWorkspace;
+function groupWhere(workspaceId: number | null, filter: ScimFilter | null) {
+ const own = ofProvider(scimGroup.workspaceId, workspaceId);
+ if (!filter) return own;
if (filter.attribute === 'externalid') {
- return and(inWorkspace, eq(scimGroup.externalId, filter.value));
+ return and(own, eq(scimGroup.externalId, filter.value));
}
- return and(inWorkspace, eq(scimGroup.displayName, filter.value));
+ return and(own, eq(scimGroup.displayName, filter.value));
}
-// Refuses a member id that names no account the workspace's provider sees.
-async function assertKnownMembers(workspaceId: number, ids: string[]): Promise<void> {
+// Refuses a member id that names no account the provider sees.
+async function assertKnownMembers(workspaceId: number | null, ids: string[]): Promise<void> {
if (ids.length === 0) return;
const known = await db
.select({ id: user.id })
.from(user)
.leftJoin(scimUser, linkOf(workspaceId))
- .where(and(inArray(user.id, ids), await inWorkspace(workspaceId)));
+ .where(and(inArray(user.id, ids), inWorkspace(workspaceId)));
const knownIds = new Set(known.map((row) => row.id));
const missing = ids.filter((id) => !knownIds.has(id));
if (missing.length > 0) {
@@ -542,7 +572,7 @@ async function toGroupRecords(
}
export async function listScimGroups(
- workspaceId: number,
+ workspaceId: number | null,
options: { filter: ScimFilter | null; startIndex: number; count: number },
): Promise<{ records: ScimGroupRecord[]; total: number }> {
const where = groupWhere(workspaceId, options.filter);
@@ -563,19 +593,19 @@ export async function listScimGroups(
}
export async function getScimGroup(
- workspaceId: number,
+ workspaceId: number | null,
id: string,
): Promise<ScimGroupRecord | null> {
const rows = await db
.select()
.from(scimGroup)
- .where(and(eq(scimGroup.id, id), eq(scimGroup.workspaceId, workspaceId)));
+ .where(and(eq(scimGroup.id, id), ofProvider(scimGroup.workspaceId, workspaceId)));
if (!rows[0]) return null;
return (await toGroupRecords(rows))[0]!;
}
export async function createScimGroup(
- workspaceId: number,
+ workspaceId: number | null,
input: { displayName: string; externalId: string | null; members: string[] },
): Promise<ScimGroupRecord> {
const members = [...new Set(input.members)];
@@ -605,7 +635,7 @@ export async function createScimGroup(
}
export async function updateScimGroup(
- workspaceId: number,
+ workspaceId: number | null,
id: string,
patch: { displayName?: string; externalId?: string | null; members?: string[] },
): Promise<ScimGroupRecord | null> {
@@ -627,7 +657,7 @@ export async function updateScimGroup(
const found = await tx
.select({ id: scimGroup.id })
.from(scimGroup)
- .where(and(eq(scimGroup.id, id), eq(scimGroup.workspaceId, workspaceId)));
+ .where(and(eq(scimGroup.id, id), ofProvider(scimGroup.workspaceId, workspaceId)));
if (!found[0]) return false;
if (patch.displayName) {
const clash = await tx
@@ -663,13 +693,13 @@ export async function updateScimGroup(
return getScimGroup(workspaceId, id);
}
-export async function deleteScimGroup(workspaceId: number, id: string): Promise<boolean> {
+export async function deleteScimGroup(workspaceId: number | null, id: string): Promise<boolean> {
// Read the mappings before the cascade removes them, so the projects the group
// granted membership in are reconciled after it is gone.
const projects = await mappedProjectIds(id);
const deleted = await db
.delete(scimGroup)
- .where(and(eq(scimGroup.id, id), eq(scimGroup.workspaceId, workspaceId)))
+ .where(and(eq(scimGroup.id, id), ofProvider(scimGroup.workspaceId, workspaceId)))
.returning({ id: scimGroup.id });
if (deleted.length === 0) return false;
await reconcileProjects(projects);
diff --git a/apps/api/src/modules/share/__tests__/integration/share.test.ts b/apps/api/src/modules/share/__tests__/integration/share.test.ts
index 6611c51a..1a3988f8 100644
--- a/apps/api/src/modules/share/__tests__/integration/share.test.ts
+++ b/apps/api/src/modules/share/__tests__/integration/share.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -12,7 +12,7 @@ import { resetDb } from '#tests/helpers/db';
async function setup() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const board = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnId = board.data!.columns[0].id;
const issue = await asOwner
@@ -314,7 +314,7 @@ describe('share', () => {
it('refuses to open an issue from another project via a board token', async () => {
const { asOwner, token } = await sharedView();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const opsBoard = await asOwner.projects({ projectKey: 'OPS' }).get();
const other = await asOwner
.projects({ projectKey: 'OPS' })
diff --git a/apps/api/src/modules/sync/__tests__/integration/sync.test.ts b/apps/api/src/modules/sync/__tests__/integration/sync.test.ts
index 6f533bee..2942a897 100644
--- a/apps/api/src/modules/sync/__tests__/integration/sync.test.ts
+++ b/apps/api/src/modules/sync/__tests__/integration/sync.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { api, authedApi, type Api } from '#tests/helpers/app';
+import { api, authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -19,7 +19,7 @@ interface Setup {
async function setup(key = 'MKT'): Promise<Setup> {
const u = await signUpTestUser();
const asOwner = authedApi(u.cookie);
- await asOwner.projects.post({ key, name: 'Marketing' });
+ await createProject(asOwner, { key, name: 'Marketing' });
const view = await asOwner.projects({ projectKey: key }).get();
return {
asOwner,
@@ -395,7 +395,7 @@ describe('sync', () => {
// A fresh project with the same key gets fresh markers: the caller is a member
// again, so a leftover row would show up here.
- await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
expect(await rev(asOwner, `board:${view.data!.project.id}`)).toBe('0');
expect(await rev(asOwner, `issue:${issue.id}`)).toBe('0');
diff --git a/apps/api/src/modules/teams/__tests__/integration/teams.test.ts b/apps/api/src/modules/teams/__tests__/integration/teams.test.ts
index 8dcc80cf..21dee2d3 100644
--- a/apps/api/src/modules/teams/__tests__/integration/teams.test.ts
+++ b/apps/api/src/modules/teams/__tests__/integration/teams.test.ts
@@ -1,5 +1,12 @@
import { describe, it, expect, afterEach, beforeEach } from 'bun:test';
-import { api as anonApi, apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import {
+ api as anonApi,
+ apiKeyApi,
+ authedApi,
+ type Api,
+ ownWorkspaceId,
+ createProject,
+} from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { addProjectMember } from '#tests/helpers/members';
@@ -45,7 +52,7 @@ describe('teams', () => {
it('attaches selected team agents only to new projects', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- await owner.api.projects.post({ key: 'SRC', name: 'Source' });
+ await createProject(owner.api, { key: 'SRC', name: 'Source' });
const created = await createAgent(owner.api, 'SRC', {
name: 'Triage',
username: 'triage',
@@ -74,8 +81,8 @@ describe('teams', () => {
it('keeps the source agents when copying a project', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- await owner.api.projects.post({ key: 'SRC', name: 'Source' });
- await owner.api.projects.post({ key: 'OTHER', name: 'Other' });
+ await createProject(owner.api, { key: 'SRC', name: 'Source' });
+ await createProject(owner.api, { key: 'OTHER', name: 'Other' });
const sourceAgent = await createAgent(owner.api, 'SRC', {
name: 'Source agent',
username: 'source-agent',
@@ -134,11 +141,14 @@ describe('teams', () => {
describe('list', () => {
it('gives a new account no team, so it has nowhere to create a project', async () => {
+ const other = await signUpClient();
+ const teamId = (await other.api.teams.get()).data![0]!.id;
const user = await signUpTestUser({ team: false });
const api = authedApi(user.cookie);
expect((await api.teams.get()).data).toEqual([]);
- expect((await api.projects.post({ key: 'MKT', name: 'Marketing' })).status).toBe(400);
+ const created = await api.teams({ teamId }).projects.post({ key: 'MKT', name: 'Marketing' });
+ expect(created.status).toBe(404);
});
it('lists the team the account owns', async () => {
@@ -158,7 +168,7 @@ describe('teams', () => {
it('counts the projects the team owns', async () => {
const { api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const list = await api.teams.get();
expect(list.data?.[0]).toMatchObject({ projectCount: 1 });
@@ -167,7 +177,15 @@ describe('teams', () => {
it("lists only the caller's own teams", async () => {
const owner = await signUpClient();
const { api } = await signUpClient();
- expect((await owner.api.teams.post({ name: 'Design', slug: 'design' })).status).toBe(201);
+ expect(
+ (
+ await owner.api.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(owner.api),
+ })
+ ).status,
+ ).toBe(201);
const list = await api.teams.get();
expect(list.data?.map((t) => t.name)).not.toContain('Design');
@@ -183,7 +201,11 @@ describe('teams', () => {
it('creates a team with the caller as its owner', async () => {
const { api } = await signUpClient();
- const created = await api.teams.post({ name: 'Design', slug: 'design' });
+ const created = await api.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(api),
+ });
expect(created.status).toBe(201);
expect(created.data).toMatchObject({ name: 'Design', role: 'owner' });
@@ -192,34 +214,75 @@ describe('teams', () => {
expect(list.data?.map((t) => t.name)).toContain('Design');
});
+ it('requires the workspace', async () => {
+ const { api } = await signUpClient();
+
+ // @ts-expect-error the request names the workspace that holds the team
+ expect((await api.teams.post({ name: 'Design', slug: 'design' })).status).toBe(400);
+ });
+
it('trims the name', async () => {
const { api } = await signUpClient();
- const created = await api.teams.post({ name: ' Design ', slug: 'design' });
+ const created = await api.teams.post({
+ name: ' Design ',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(api),
+ });
expect(created.data).toMatchObject({ name: 'Design' });
});
it('rejects an empty or blank name', async () => {
const { api } = await signUpClient();
- expect((await api.teams.post({ name: '', slug: 'team' })).status).toBe(400);
- expect((await api.teams.post({ name: ' ', slug: 'team' })).status).toBe(400);
+ expect(
+ (await api.teams.post({ name: '', slug: 'team', workspaceId: await ownWorkspaceId(api) }))
+ .status,
+ ).toBe(400);
+ expect(
+ (
+ await api.teams.post({
+ name: ' ',
+ slug: 'team',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).status,
+ ).toBe(400);
});
it('rejects a name longer than 60 characters', async () => {
const { api } = await signUpClient();
- expect((await api.teams.post({ name: 'a'.repeat(60), slug: 'long' })).status).toBe(201);
- expect((await api.teams.post({ name: 'a'.repeat(61), slug: 'longer' })).status).toBe(400);
+ expect(
+ (
+ await api.teams.post({
+ name: 'a'.repeat(60),
+ slug: 'long',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).status,
+ ).toBe(201);
+ expect(
+ (
+ await api.teams.post({
+ name: 'a'.repeat(61),
+ slug: 'longer',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).status,
+ ).toBe(400);
});
it('refuses one more team than the workspace limits allow', async () => {
- const { api } = await signUpClient({ team: false });
- // The other account's team already fills the workspace.
- await signUpClient();
+ // Its own team already fills the workspace.
+ const { api } = await signUpClient();
setLimits({ maxTeams: 1 });
- const created = await api.teams.post({ name: 'Design', slug: 'design' });
+ const created = await api.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(api),
+ });
expect(created.status).toBe(409);
const names = (await api.teams.get()).data!.map((team) => team.name);
expect(names).not.toContain('Design');
@@ -228,23 +291,55 @@ describe('teams', () => {
it('creates the team under the slug it is given', async () => {
const { api } = await signUpClient();
- const created = await api.teams.post({ name: 'Design', slug: 'design' });
+ const created = await api.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(api),
+ });
expect(created.status).toBe(201);
expect(created.data).toMatchObject({ slug: 'design', ref: 'design' });
});
it('refuses a slug that is malformed, reserved or taken', async () => {
const { api } = await signUpClient();
- await api.teams.post({ name: 'Design', slug: 'design' });
+ await api.teams.post({
+ name: 'Design',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(api),
+ });
- expect((await api.teams.post({ name: 'Bad', slug: 'Bad Slug' })).status).toBe(400);
- expect((await api.teams.post({ name: 'Settings', slug: 'settings' })).status).toBe(400);
- expect((await api.teams.post({ name: 'Design 2', slug: 'design' })).status).toBe(409);
+ expect(
+ (
+ await api.teams.post({
+ name: 'Bad',
+ slug: 'Bad Slug',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).status,
+ ).toBe(400);
+ expect(
+ (
+ await api.teams.post({
+ name: 'Settings',
+ slug: 'settings',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).status,
+ ).toBe(400);
+ expect(
+ (
+ await api.teams.post({
+ name: 'Design 2',
+ slug: 'design',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).status,
+ ).toBe(409);
expect(await api.teams.get().then((list) => list.data)).toHaveLength(2);
});
it('rejects a request without a session', async () => {
- const created = await anonApi.teams.post({ name: 'Design', slug: 'design' });
+ const created = await anonApi.teams.post({ name: 'Design', slug: 'design', workspaceId: 1 });
expect(created.status).toBe(401);
});
});
@@ -252,7 +347,7 @@ describe('teams', () => {
describe('detail', () => {
it('returns the team with what it holds and what the caller may do', async () => {
const { user, api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = (await api.teams.get()).data![0].id;
const detail = await api.teams({ teamId }).get();
@@ -270,7 +365,7 @@ describe('teams', () => {
it('lists the members and the projects of the team by their own routes', async () => {
const { user, api } = await signUpClient();
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = (await api.teams.get()).data![0].id;
const members = await api.teams({ teamId }).members.get();
@@ -406,7 +501,6 @@ describe('teams', () => {
});
it('hides the members and the projects of a team the caller is not in', async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
const otherTeamId = (await other.api.teams.get()).data![0].id;
@@ -416,7 +510,6 @@ describe('teams', () => {
});
it('hides a team the caller is not a member of', async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
const otherTeamId = (await other.api.teams.get()).data![0].id;
@@ -435,7 +528,7 @@ describe('teams', () => {
describe('project detail', () => {
it("returns the reader's own access to a project the team owns", async () => {
const { api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = (await api.teams.get()).data![0].id;
const detail = await api.teams({ teamId }).projects({ projectId: project.data!.id }).get();
@@ -446,7 +539,7 @@ describe('teams', () => {
it('counts the open issues of the project and reports its last activity', async () => {
const { api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = (await api.teams.get()).data![0].id;
const empty = await api.teams({ teamId }).projects({ projectId: project.data!.id }).get();
@@ -462,10 +555,9 @@ describe('teams', () => {
});
it("404s for a project of another account's team", async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
- const otherProject = await other.api.projects.post({ key: 'OTH', name: 'Other' });
+ const otherProject = await createProject(other.api, { key: 'OTH', name: 'Other' });
const teamId = (await api.teams.get()).data![0].id;
const detail = await api
@@ -476,10 +568,9 @@ describe('teams', () => {
});
it('404s for a team the caller is not a member of', async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
- const otherProject = await other.api.projects.post({ key: 'OTH', name: 'Other' });
+ const otherProject = await createProject(other.api, { key: 'OTH', name: 'Other' });
const otherTeamId = (await other.api.teams.get()).data![0].id;
const detail = await api
@@ -493,7 +584,7 @@ describe('teams', () => {
describe('project members', () => {
it('lists the owners of the project before its members', async () => {
const { user, api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
const promoted = await addProjectMember(api, 'MKT');
const promotedUserId = (
await api.projects({ projectKey: 'MKT' }).members.get()
@@ -522,7 +613,7 @@ describe('teams', () => {
it('windows the list and reports how many there are in total', async () => {
const { user, api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
await addProjectMember(api, 'MKT');
await addProjectMember(api, 'MKT');
const teamId = (await api.teams.get()).data![0].id;
@@ -543,7 +634,7 @@ describe('teams', () => {
it('narrows the list to the people or to the AI agents', async () => {
const { api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
await addProjectMember(api, 'MKT');
const teamId = (await api.teams.get()).data![0].id;
const members = api.teams({ teamId }).projects({ projectId: project.data!.id }).members;
@@ -557,7 +648,7 @@ describe('teams', () => {
it('searches by name, address and handle', async () => {
const { user, api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
await addProjectMember(api, 'MKT');
const teamId = (await api.teams.get()).data![0].id;
const members = api.teams({ teamId }).projects({ projectId: project.data!.id }).members;
@@ -575,7 +666,7 @@ describe('teams', () => {
it('404s for a member of the team who is not in the project', async () => {
const { api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = (await api.teams.get()).data![0].id;
const outsider = await addTeamMember({ api }, teamId);
@@ -588,7 +679,7 @@ describe('teams', () => {
it('lets a manager of the team read a project they are not in', async () => {
const { api } = await signUpClient();
- const project = await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(api, { key: 'MKT', name: 'Marketing' });
const teamId = (await api.teams.get()).data![0].id;
const manager = await addTeamMember({ api }, teamId, 'manager');
@@ -632,7 +723,6 @@ describe('teams', () => {
});
it("404s for another account's team", async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
const otherTeamId = await ownTeamId(other.api);
@@ -668,7 +758,7 @@ describe('teams', () => {
it("404s for a project of another account's team", async () => {
const { api } = await signUpClient();
const other = await signUpClient();
- const otherProject = await other.api.projects.post({ key: 'OTH', name: 'Other' });
+ const otherProject = await createProject(other.api, { key: 'OTH', name: 'Other' });
const teamId = await ownTeamId(api);
const copied = await api
@@ -703,7 +793,7 @@ describe('teams', () => {
it("404s for a project of another account's team", async () => {
const { api } = await signUpClient();
const other = await signUpClient();
- const otherProject = await other.api.projects.post({ key: 'OTH', name: 'Other' });
+ const otherProject = await createProject(other.api, { key: 'OTH', name: 'Other' });
const teamId = await ownTeamId(api);
const updated = await api
@@ -749,7 +839,7 @@ describe('teams', () => {
it('404s for a project of another team, leaving it in place', async () => {
const { api } = await signUpClient();
const other = await signUpClient();
- const otherProject = await other.api.projects.post({ key: 'OTH', name: 'Other' });
+ const otherProject = await createProject(other.api, { key: 'OTH', name: 'Other' });
const teamId = await ownTeamId(api);
const deleted = await api
@@ -845,7 +935,7 @@ describe('teams', () => {
it('404s for a project of another team', async () => {
const { api } = await signUpClient();
const other = await signUpClient();
- const otherProject = await other.api.projects.post({ key: 'OTH', name: 'Other' });
+ const otherProject = await createProject(other.api, { key: 'OTH', name: 'Other' });
const teamId = await ownTeamId(api);
const archived = await api
@@ -866,7 +956,7 @@ describe('teams', () => {
it('starts with MCP on and every project covered', async () => {
const { api } = await signUpClient();
const teamId = (await api.teams.get()).data![0].id;
- const project = (await api.projects.post({ key: 'MKT', name: 'Marketing' })).data!;
+ const project = (await createProject(api, { key: 'MKT', name: 'Marketing' })).data!;
expect((await api.teams.get()).data?.[0]).toMatchObject({ mcpEnabled: true });
expect((await api.teams({ teamId }).projects.get()).data?.items).toMatchObject([
@@ -877,8 +967,8 @@ describe('teams', () => {
it('sets the switch and the covered projects in one call', async () => {
const { api } = await signUpClient();
const teamId = (await api.teams.get()).data![0].id;
- const on = (await api.projects.post({ key: 'ON', name: 'On' })).data!;
- const off = (await api.projects.post({ key: 'OFF', name: 'Off' })).data!;
+ const on = (await createProject(api, { key: 'ON', name: 'On' })).data!;
+ const off = (await createProject(api, { key: 'OFF', name: 'Off' })).data!;
const res = await api.teams({ teamId }).mcp.patch({
enabled: false,
@@ -903,7 +993,7 @@ describe('teams', () => {
const { api } = await signUpClient();
const teamId = (await api.teams.get()).data![0].id;
const other = await signUpClient();
- const foreign = (await other.api.projects.post({ key: 'OTH', name: 'Other' })).data!;
+ const foreign = (await createProject(other.api, { key: 'OTH', name: 'Other' })).data!;
const res = await api.teams({ teamId }).mcp.patch({
projects: [{ projectId: foreign.id, enabled: false }],
@@ -921,7 +1011,7 @@ describe('teams', () => {
it('lets a manager write the settings', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- const project = (await owner.api.projects.post({ key: 'MKT', name: 'Marketing' })).data!;
+ const project = (await createProject(owner.api, { key: 'MKT', name: 'Marketing' })).data!;
const manager = await addTeamMember(owner, teamId, 'manager');
const res = await manager.api.teams({ teamId }).mcp.patch({
@@ -935,7 +1025,7 @@ describe('teams', () => {
it('lets a member read the state but not write it', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addProjectMember(owner.api, 'MKT');
expect((await member.teams({ teamId }).projects.get()).data?.items).toMatchObject([
@@ -963,7 +1053,13 @@ describe('teams', () => {
it('hides a team with MCP off from an MCP list_teams call', async () => {
const { api } = await signUpClient();
const teamId = (await api.teams.get()).data![0].id;
- const second = (await api.teams.post({ name: 'Growth', slug: 'growth' })).data!;
+ const second = (
+ await api.teams.post({
+ name: 'Growth',
+ slug: 'growth',
+ workspaceId: await ownWorkspaceId(api),
+ })
+ ).data!;
await api.teams({ teamId }).mcp.patch({ enabled: false });
expect((await api.teams.get()).data?.map((t) => t.id).sort()).toEqual(
@@ -995,7 +1091,6 @@ describe('teams', () => {
});
it("rejects a rename of another account's team", async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
const otherTeamId = (await other.api.teams.get()).data![0].id;
@@ -1146,7 +1241,7 @@ describe('teams', () => {
it('drops the member and their access to the projects of the team', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addTeamMember(owner, teamId);
await owner.api
.projects({ projectKey: 'MKT' })
@@ -1202,7 +1297,7 @@ describe('teams', () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
const member = await addTeamMember(owner, teamId);
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
await owner.api
.projects({ projectKey: 'MKT' })
.members.post({ userId: member.user.userId, role: 'owner' });
@@ -1285,8 +1380,7 @@ describe('teams', () => {
});
describe('delete', () => {
- // The first account owns the instance workspace, which reaches every team in it, so
- // the team owner is the second.
+ // The team owner is a plain account, not the instance owner.
async function teamOwner() {
await signUpTestUser();
const owner = await signUpClient();
@@ -1363,7 +1457,7 @@ describe('teams', () => {
it('takes the projects of the team with it', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const member = await addTeamMember(owner, teamId);
await owner.api
.projects({ projectKey: 'MKT' })
@@ -1374,7 +1468,6 @@ describe('teams', () => {
});
it('404s for a team the caller is not a member of', async () => {
- // The first account owns the instance workspace, which reaches every team in it.
const other = await signUpClient();
const { api } = await signUpClient();
const otherTeamId = (await other.api.teams.get()).data![0].id;
@@ -1403,7 +1496,7 @@ describe('teams', () => {
it('rejects an agent leaving with its own key', async () => {
const owner = await signUpClient();
const teamId = (await owner.api.teams.get()).data![0].id;
- await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(owner.api, { key: 'MKT', name: 'Marketing' });
const created = await createAgent(owner.api, 'MKT', {
name: 'Runner',
username: 'runner',
diff --git a/apps/api/src/modules/teams/__tests__/integration/workspace.test.ts b/apps/api/src/modules/teams/__tests__/integration/workspace.test.ts
index 022affbc..4012fe9c 100644
--- a/apps/api/src/modules/teams/__tests__/integration/workspace.test.ts
+++ b/apps/api/src/modules/teams/__tests__/integration/workspace.test.ts
@@ -1,43 +1,66 @@
import { beforeEach, describe, expect, it } from 'bun:test';
-import { db, instanceWorkspaceId, team, workspace, workspaceManager } from '@repo/db';
-import { eq } from 'drizzle-orm';
+import { setAuthSettings } from '@repo/auth';
+import { db, team, workspace, workspaceManager } from '@repo/db';
import { signUpTestUser } from '#tests/helpers/auth';
import { authedApi } from '#tests/helpers/app';
import { resetDb } from '#tests/helpers/db';
-describe('instance workspace', () => {
+describe('the workspace of a team', () => {
beforeEach(resetDb);
- it('makes the first account its owner and nobody else a manager', async () => {
+ it('gives every account, the instance owner included, a workspace of its own', async () => {
const first = await signUpTestUser({ team: false });
- await signUpTestUser({ team: false });
-
- const managers = await db
- .select()
- .from(workspaceManager)
- .where(eq(workspaceManager.workspaceId, await instanceWorkspaceId(db)));
- expect(managers).toHaveLength(1);
- expect(managers[0]).toMatchObject({ userId: first.userId, role: 'owner' });
+ const second = await signUpTestUser({ team: false });
+
+ const managers = await db.select().from(workspaceManager);
+ expect(managers).toHaveLength(2);
+ expect(managers).toContainEqual(
+ expect.objectContaining({ userId: first.userId, role: 'owner' }),
+ );
+ expect(managers).toContainEqual(
+ expect.objectContaining({ userId: second.userId, role: 'owner' }),
+ );
+ expect(first.workspaceId).not.toBe(second.workspaceId);
});
- it('puts every new team in it', async () => {
- await signUpTestUser();
- await signUpTestUser();
- const [managed] = await db.select().from(workspaceManager);
+ it('gives the instance owner one while personal workspaces are off', async () => {
+ await setAuthSettings({ personalWorkspaces: false });
+
+ const first = await signUpTestUser({ team: false });
+ const second = await signUpTestUser({ team: false });
+
+ expect(first.workspaceId).not.toBeNull();
+ expect(second.workspaceId).toBeNull();
+ });
+
+ it("puts each person's team in their own workspace", async () => {
+ const first = await signUpTestUser();
+ const second = await signUpTestUser();
const teams = await db.select({ workspaceId: team.workspaceId }).from(team);
- expect(teams).toEqual([
- { workspaceId: managed!.workspaceId },
- { workspaceId: managed!.workspaceId },
- ]);
+ expect(teams.map((row) => row.workspaceId).sort()).toEqual(
+ [first.workspaceId!, second.workspaceId!].sort(),
+ );
+ });
+
+ it('refuses a team that names no workspace', async () => {
+ const owner = await signUpTestUser({ team: false });
+
+ const refused = await authedApi(owner.cookie).teams.post({
+ name: 'Design',
+ slug: 'design',
+ } as never);
+
+ expect(refused.status).toBe(400);
});
it('lets only the workspace owner create a team', async () => {
const owner = await signUpTestUser({ team: false });
const member = await signUpTestUser({ team: false });
+ const body = { name: 'Design', slug: 'design', workspaceId: owner.workspaceId! };
- const refused = await authedApi(member.cookie).teams.post({ name: 'Design', slug: 'design' });
- const created = await authedApi(owner.cookie).teams.post({ name: 'Design', slug: 'design' });
+ const refused = await authedApi(member.cookie).teams.post(body);
+ const created = await authedApi(owner.cookie).teams.post(body);
expect(refused.status).toBe(403);
expect(created.status).toBe(201);
diff --git a/apps/api/src/modules/teams/index.ts b/apps/api/src/modules/teams/index.ts
index 06cdd0af..2d6e8114 100644
--- a/apps/api/src/modules/teams/index.ts
+++ b/apps/api/src/modules/teams/index.ts
@@ -344,12 +344,14 @@ export const teamRoutes = new Elysia({ name: 'teams', detail: { tags: ['Teams']
body: createProjectBody,
response: { 201: ProjectResponse, ...errors(400, 401, 403, 404, 409) },
detail: {
- summary: 'Create a project in a team',
+ summary: 'Create a project',
description:
- 'Create a project in a team you own or manage and become its owner. Takes the ' +
- 'same fields as create_project. Over MCP, uses the team from your key when ' +
- 'there is one; otherwise call list_teams and pass teamId.',
- ...mcpTool('create_team_project'),
+ 'Create a project in a team you own or manage and become its owner. `key` is the ' +
+ "immutable prefix for issue ids, unique within the team (e.g. 'MKT' -> 'MKT-1'). " +
+ 'Seeds the default columns and the issue types of the chosen `preset`. Over MCP, ' +
+ 'uses the team from your key when there is one; otherwise call list_teams and pass ' +
+ 'teamId.',
+ ...mcpTool('create_project'),
},
},
)
@@ -360,7 +362,7 @@ export const teamRoutes = new Elysia({ name: 'teams', detail: { tags: ['Teams']
await requireTeamProject(membership.teamId, params.projectId);
const { include, ...meta } = body;
set.status = 201;
- return copyProject(params.projectId, meta, membership.userId, include, membership.teamId);
+ return copyProject(params.projectId, meta, membership.userId, membership.teamId, include);
},
{
teamManager: true,
diff --git a/apps/api/src/modules/teams/model.ts b/apps/api/src/modules/teams/model.ts
index fd1a2b79..53b07757 100644
--- a/apps/api/src/modules/teams/model.ts
+++ b/apps/api/src/modules/teams/model.ts
@@ -31,13 +31,7 @@ const teamSlug = t.String({
export const createTeamBody = t.Object({
name: teamName,
slug: teamSlug,
- workspaceId: t.Optional(
- t.Integer({
- minimum: 1,
- description:
- 'The workspace that holds the team. A self-hosted instance has one, which is the default.',
- }),
- ),
+ workspaceId: t.Integer({ minimum: 1, description: 'The workspace that holds the team.' }),
});
// A team made before slugs were required has none, and takes no change until one is set.
diff --git a/apps/api/src/modules/teams/service.ts b/apps/api/src/modules/teams/service.ts
index 16762f6b..6e9fc773 100644
--- a/apps/api/src/modules/teams/service.ts
+++ b/apps/api/src/modules/teams/service.ts
@@ -3,7 +3,6 @@ import {
agentTool,
aiAgent,
db,
- instanceWorkspaceId,
teamWorkspaceId,
integrationCredential,
issue,
@@ -827,9 +826,8 @@ export async function createTeam(
name: string,
slug: string,
ownerId: string,
- requestedWorkspaceId?: number,
+ workspaceId: number,
): Promise<TeamRow> {
- const workspaceId = requestedWorkspaceId ?? (await instanceWorkspaceId(db));
await assertMayCreateTeam(workspaceId, ownerId);
const { maxTeams } = await getLimits(workspaceId);
if (maxTeams > 0 && (await db.$count(team, eq(team.workspaceId, workspaceId))) >= maxTeams) {
@@ -1131,15 +1129,12 @@ export async function releaseOwnedWorkspaces(userId: string): Promise<void> {
.where(and(eq(workspaceManager.userId, userId), eq(workspaceManager.role, 'owner')));
if (owned.length === 0) return;
const [instanceOwner] = await db
- .select({ userId: workspaceManager.userId })
- .from(workspaceManager)
- .where(
- and(
- eq(workspaceManager.workspaceId, await instanceWorkspaceId(db)),
- eq(workspaceManager.role, 'owner'),
- ),
- );
- const successor = instanceOwner?.userId;
+ .select({ id: user.id })
+ .from(user)
+ .where(eq(user.role, 'god'))
+ .orderBy(user.createdAt)
+ .limit(1);
+ const successor = instanceOwner?.id;
for (const { workspaceId } of owned) {
if (!(await workspaceHoldsWork(workspaceId))) {
await db.delete(workspace).where(eq(workspace.id, workspaceId));
diff --git a/apps/api/src/modules/user-preferences/__tests__/integration/user-preferences.test.ts b/apps/api/src/modules/user-preferences/__tests__/integration/user-preferences.test.ts
index dbfb1976..0b7a915a 100644
--- a/apps/api/src/modules/user-preferences/__tests__/integration/user-preferences.test.ts
+++ b/apps/api/src/modules/user-preferences/__tests__/integration/user-preferences.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { api, authedApi } from '#tests/helpers/app';
+import { api, authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
@@ -163,7 +163,7 @@ describe('user preferences', () => {
it('remembers a project the user belongs to', async () => {
const u = await signUpTestUser();
const client = authedApi(u.cookie);
- const created = await client.projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(client, { key: 'MKT', name: 'Marketing' });
const projectId = created.data!.id;
const res = await client.account.preferences.patch({ lastProjectId: projectId });
@@ -176,7 +176,7 @@ describe('user preferences', () => {
it('rejects a project the user is not a member of', async () => {
const owner = await signUpTestUser();
const outsider = await signUpTestUser();
- const created = await authedApi(owner.cookie).projects.post({ key: 'MKT', name: 'Marketing' });
+ const created = await createProject(authedApi(owner.cookie), { key: 'MKT', name: 'Marketing' });
const res = await authedApi(outsider.cookie).account.preferences.patch({
lastProjectId: created.data!.id,
diff --git a/apps/api/src/modules/views/__tests__/integration/views.test.ts b/apps/api/src/modules/views/__tests__/integration/views.test.ts
index 5e39ff4f..180f6147 100644
--- a/apps/api/src/modules/views/__tests__/integration/views.test.ts
+++ b/apps/api/src/modules/views/__tests__/integration/views.test.ts
@@ -1,12 +1,12 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '#tests/helpers/app';
+import { authedApi, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
async function setupOwnerProject() {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
return { asOwner, projectId: project.data!.id };
}
@@ -167,7 +167,7 @@ describe('views', () => {
it('ignores ids that belong to another project', async () => {
const { asOwner } = await setupOwnerProject();
- await asOwner.projects.post({ key: 'OPS', name: 'Operations' });
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
const mkt = (await asOwner.projects({ projectKey: 'MKT' }).views.post({ name: 'Mine' }))
.data!;
// The OPS view sits at position 0; the reorder below places its id at index
diff --git a/apps/api/src/modules/webhooks/__tests__/integration/webhooks.test.ts b/apps/api/src/modules/webhooks/__tests__/integration/webhooks.test.ts
index 5b627be0..85ef7452 100644
--- a/apps/api/src/modules/webhooks/__tests__/integration/webhooks.test.ts
+++ b/apps/api/src/modules/webhooks/__tests__/integration/webhooks.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { apiKeyApi, authedApi, type Api } from '#tests/helpers/app';
+import { apiKeyApi, authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
@@ -9,7 +9,7 @@ import { onProjectEvent, type ProjectEvent } from '../../emit';
async function setupOwnerProject() {
const owner = await signUpTestUser({ name: 'Owner' });
const asOwner = authedApi(owner.cookie);
- const project = await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
+ const project = await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
// createProject seeds five default columns; the first is the target for issues.
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
return {
diff --git a/apps/api/src/modules/workspaces/__tests__/integration/workspace-access.test.ts b/apps/api/src/modules/workspaces/__tests__/integration/workspace-access.test.ts
index e3730642..68c78481 100644
--- a/apps/api/src/modules/workspaces/__tests__/integration/workspace-access.test.ts
+++ b/apps/api/src/modules/workspaces/__tests__/integration/workspace-access.test.ts
@@ -1,5 +1,7 @@
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
-import { authedApi, type Api } from '#tests/helpers/app';
+import { db, team } from '@repo/db';
+import { inArray } from 'drizzle-orm';
+import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { readOnlyPermissions, setWorkspaceRoleGrant } from '#shared/workspace-roles';
@@ -15,9 +17,16 @@ async function setup() {
const asOwner = authedApi(owner.cookie);
const asLead = authedApi(lead.cookie);
- await asLead.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(asLead, { key: 'MKT', name: 'Marketing' });
const scaffold = (await asLead.projects({ projectKey: 'MKT' }).get()).data!;
- const workspaceId = (await asOwner.workspaces.get()).data!.find((w) => w.role === 'owner')!.id;
+ const workspaceId = owner.workspaceId!;
+ // The lead's and the admin's teams are in the owner's workspace; the owner is in
+ // neither, and the admin is not in the lead's.
+ const [adminTeam] = (await authedApi(admin.cookie).teams.get()).data!;
+ await db
+ .update(team)
+ .set({ workspaceId })
+ .where(inArray(team.id, [scaffold.project.teamId, adminTeam!.id]));
await asOwner.workspaces({ workspaceId }).managers.post({ userId: admin.userId });
return {
diff --git a/apps/api/src/modules/workspaces/__tests__/integration/workspaces.test.ts b/apps/api/src/modules/workspaces/__tests__/integration/workspaces.test.ts
index a94f0faf..68e09aaf 100644
--- a/apps/api/src/modules/workspaces/__tests__/integration/workspaces.test.ts
+++ b/apps/api/src/modules/workspaces/__tests__/integration/workspaces.test.ts
@@ -4,19 +4,34 @@ import { setAuthSettings, setWorkspaceScim } from '@repo/auth';
import { db, workspace } from '@repo/db';
import { deleteAccount } from '#shared/account-deletion';
import { setOwnedWorkspaceLimit } from '#shared/limits';
-import { apiKeyApi, app, authedApi } from '#tests/helpers/app';
+import { apiKeyApi, app, authedApi, createProject } from '#tests/helpers/app';
import { createAgent } from '#tests/helpers/agents';
import { signUpTestUser, type TestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createOwnWorkspace, transferWorkspace } from '../../service';
-// The first account is the owner of the instance workspace; every account signed up
-// with a team is a person in it.
+// The first account, the instance owner, and its own workspace with its team.
async function setup() {
- const owner = await signUpTestUser();
+ const owner = await signUpTestUser({ name: 'Root' });
const ownerApi = authedApi(owner.cookie);
- const [workspace] = (await ownerApi.workspaces.get()).data!;
- return { owner, ownerApi, workspaceId: workspace!.id };
+ const [team] = (await ownerApi.teams.get()).data!;
+ return { owner, ownerApi, workspaceId: owner.workspaceId!, teamId: team!.id };
+}
+
+async function joinTeam(api: ReturnType<typeof authedApi>, teamId: number, person: TestUser) {
+ const invite = await api.teams({ teamId }).invites.post({ email: person.email, role: 'member' });
+ await authedApi(person.cookie).invites({ token: invite.data!.token }).accept.post();
+}
+
+// Somebody in a team of the workspace, through an invite to the owner's team.
+async function addPerson(
+ ownerApi: ReturnType<typeof authedApi>,
+ teamId: number,
+ overrides: { name?: string } = {},
+) {
+ const person = await signUpTestUser({ ...overrides, team: false });
+ await joinTeam(ownerApi, teamId, person);
+ return person;
}
async function makeAdmin(
@@ -33,16 +48,16 @@ describe('workspaces', () => {
describe('GET /workspaces', () => {
it('lists the workspace with the standing of each reader', async () => {
- const { ownerApi, workspaceId } = await setup();
+ const { ownerApi, workspaceId, teamId } = await setup();
await setAuthSettings({ personalWorkspaces: false });
- const member = await signUpTestUser();
+ const member = await addPerson(ownerApi, teamId);
const outsider = await signUpTestUser({ team: false });
expect((await ownerApi.workspaces.get()).data).toEqual([
- { id: workspaceId, name: 'Workspace', role: 'owner', color: null, canCreateTeam: true },
+ { id: workspaceId, name: 'Root', role: 'owner', color: null, canCreateTeam: true },
]);
expect((await authedApi(member.cookie).workspaces.get()).data).toEqual([
- { id: workspaceId, name: 'Workspace', role: null, color: null, canCreateTeam: false },
+ { id: workspaceId, name: 'Root', role: null, color: null, canCreateTeam: false },
]);
expect((await authedApi(outsider.cookie).workspaces.get()).data).toEqual([]);
});
@@ -59,8 +74,8 @@ describe('workspaces', () => {
});
it('answers 404 to somebody who does not manage it', async () => {
- const { workspaceId } = await setup();
- const member = await signUpTestUser();
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const member = await addPerson(ownerApi, teamId);
expect((await authedApi(member.cookie).workspaces({ workspaceId }).get()).status).toBe(404);
});
@@ -68,8 +83,8 @@ describe('workspaces', () => {
describe('PATCH /workspaces/:workspaceId', () => {
it('renames it for an admin', async () => {
- const { ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
const res = await authedApi(admin.cookie).workspaces({ workspaceId }).patch({ name: 'Acme' });
@@ -92,8 +107,8 @@ describe('workspaces', () => {
describe('settings', () => {
it('lets a manager recolour it, and refuses a colour that is not #rrggbb', async () => {
- const { ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
const ws = authedApi(admin.cookie).workspaces({ workspaceId });
@@ -103,9 +118,9 @@ describe('workspaces', () => {
});
it('leaves who creates teams to the owner, and applies it to POST /teams', async () => {
- const { ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
- const member = await signUpTestUser();
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
+ const member = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
const adminApi = authedApi(admin.cookie);
const memberApi = authedApi(member.cookie);
@@ -131,13 +146,6 @@ describe('workspaces', () => {
});
describe('transferWorkspace', () => {
- async function joinTeam(api: ReturnType<typeof authedApi>, teamId: number, person: TestUser) {
- const invite = await api
- .teams({ teamId })
- .invites.post({ email: person.email, role: 'member' });
- await authedApi(person.cookie).invites({ token: invite.data!.token }).accept.post();
- }
-
// A person's own workspace with a team, and an admin of it who owns no workspace.
async function withAdmin() {
await setup();
@@ -178,22 +186,12 @@ describe('workspaces', () => {
await personApi.workspaces({ workspaceId }).managers.post({ userId: other.userId });
await expect(transfer()).rejects.toThrow('already owns as many workspaces');
});
-
- it('keeps the instance workspace with the instance owner', async () => {
- const { owner, ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
- await makeAdmin(ownerApi, workspaceId, admin);
-
- await expect(transferWorkspace(workspaceId, owner.userId, admin.userId)).rejects.toThrow(
- 'The instance workspace stays with the instance owner',
- );
- });
});
describe('managers', () => {
it('lists the owner first, then the admins', async () => {
- const { owner, ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
+ const { owner, ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
const res = await ownerApi.workspaces({ workspaceId }).managers.get();
@@ -204,8 +202,8 @@ describe('workspaces', () => {
});
it('offers the people of its teams who do not manage it yet', async () => {
- const { ownerApi, workspaceId } = await setup();
- const member = await signUpTestUser({ name: 'Grace Hopper' });
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const member = await addPerson(ownerApi, teamId, { name: 'Grace Hopper' });
await signUpTestUser({ name: 'Ada Lovelace', team: false });
const all = await ownerApi.workspaces({ workspaceId }).managers.candidates.get();
@@ -226,9 +224,9 @@ describe('workspaces', () => {
});
it('lets only the owner appoint and remove admins', async () => {
- const { ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
- const other = await signUpTestUser();
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
+ const other = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
const adminManagers = authedApi(admin.cookie).workspaces({ workspaceId }).managers;
@@ -237,8 +235,8 @@ describe('workspaces', () => {
});
it('removes an admin but never the owner', async () => {
- const { owner, ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
+ const { owner, ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
const managers = ownerApi.workspaces({ workspaceId }).managers;
@@ -252,7 +250,7 @@ describe('workspaces', () => {
describe('personal workspaces', () => {
afterEach(() => setWorkspaceScim(false));
- it('gives every account after the first one a workspace only it sees', async () => {
+ it('gives every account a workspace only it sees', async () => {
const { ownerApi, workspaceId } = await setup();
const person = await signUpTestUser({ name: 'Jane Doe', team: false });
@@ -260,11 +258,11 @@ describe('workspaces', () => {
expect(own).toMatchObject({ name: 'Jane Doe', role: 'owner' });
expect(own!.id).not.toBe(workspaceId);
expect((await ownerApi.workspaces.get()).data).toEqual([
- { id: workspaceId, name: 'Workspace', role: 'owner', color: null, canCreateTeam: true },
+ { id: workspaceId, name: 'Root', role: 'owner', color: null, canCreateTeam: true },
]);
});
- it('leaves SCIM provisioning to the instance owner', async () => {
+ it('leaves SCIM provisioning to god mode unless a build sets it up per workspace', async () => {
await setup();
const person = authedApi((await signUpTestUser({ team: false })).cookie);
const [own] = (await person.workspaces.get()).data!;
@@ -313,7 +311,7 @@ describe('workspaces', () => {
it('makes none for an AI agent, and no route creates one', async () => {
const { owner, ownerApi } = await setup();
- await ownerApi.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(ownerApi, { key: 'MKT', name: 'Marketing' });
const created = await createAgent(ownerApi, 'MKT', {
name: 'Bot',
username: 'bot',
@@ -395,16 +393,20 @@ describe('workspaces', () => {
expect((await ws.delete()).status).toBe(409);
});
- it('keeps the instance workspace, and leaves deleting to the owner', async () => {
- const { ownerApi, workspaceId } = await setup();
- const admin = await signUpTestUser();
+ it('leaves deleting to the owner, and gives the instance owner a fresh one', async () => {
+ const { ownerApi, workspaceId, teamId } = await setup();
+ const admin = await addPerson(ownerApi, teamId);
await makeAdmin(ownerApi, workspaceId, admin);
+ await setAuthSettings({ personalWorkspaces: false });
expect((await ownerApi.workspaces({ workspaceId }).get()).data).toMatchObject({
- deletion: 'instance',
+ deletion: 'allowed',
});
- expect((await ownerApi.workspaces({ workspaceId }).delete()).status).toBe(409);
expect((await authedApi(admin.cookie).workspaces({ workspaceId }).delete()).status).toBe(403);
+ expect((await ownerApi.workspaces({ workspaceId }).delete()).status).toBe(204);
+ const [fresh] = (await ownerApi.workspaces.get()).data!;
+ expect(fresh).toMatchObject({ role: 'owner' });
+ expect(fresh!.id).not.toBe(workspaceId);
});
});
diff --git a/apps/api/src/modules/workspaces/index.ts b/apps/api/src/modules/workspaces/index.ts
index 590513f7..3e8f3c43 100644
--- a/apps/api/src/modules/workspaces/index.ts
+++ b/apps/api/src/modules/workspaces/index.ts
@@ -8,15 +8,23 @@ import { HttpError } from '#shared/lib';
import { errors } from '#shared/responses';
import { SCIM_BASE_URL } from '#modules/scim/resource';
import {
+ MappableProjectListResponse,
ScimGroupMappingsBody,
- ScimGroupResponse,
+ ProvisionedGroupResponse,
ScimSettingsBody,
ScimSettingsResponse,
ScimTokenResponse,
+} from '#modules/scim/model';
+import {
+ listMappableProjects,
+ listProvisionedGroups,
+ reconcileWorkspaceGrants,
+ setGroupMappings,
+} from '#modules/scim/mappings';
+import {
WorkspaceCandidateListResponse,
WorkspaceListResponse,
WorkspaceManagerListResponse,
- WorkspaceProjectOptionListResponse,
WorkspaceResponse,
addManagerBody,
scimGroupParams,
@@ -35,18 +43,13 @@ import {
removeAdmin,
updateWorkspace,
} from './service';
-import {
- listWorkspaceProjectOptions,
- listWorkspaceScimGroups,
- reconcileWorkspaceGrants,
- setWorkspaceScimGroupMappings,
-} from './scim';
// A workspace owns teams. Only its owner and admins manage it; everyone else sees it
// through the teams they are in. No route creates one: sign-up and sign-in make each
// person's own (@repo/auth), and an edition that lets a person own more mounts its route
-// on createOwnWorkspace. SCIM provisioning is set up only by the instance owner, in a
-// workspace they own: the identity provider decides who has access to the workspace.
+// on createOwnWorkspace. SCIM of its own is there only where a build sets SCIM up per
+// workspace (setWorkspaceScim in @repo/auth): its owner sets it up, and the identity
+// provider decides who has access to the workspace. The instance's is set up in god mode.
export const workspaceRoutes = new Elysia({ name: 'workspaces', detail: { tags: ['Workspaces'] } })
.use(authContext)
.use(guards)
@@ -103,8 +106,8 @@ export const workspaceRoutes = new Elysia({ name: 'workspaces', detail: { tags:
detail: {
summary: 'Delete a workspace',
description:
- 'Delete a workspace you own, with its teams. The instance workspace stays, and one ' +
- 'whose teams hold a project or an AI agent is refused until those are gone.',
+ 'Delete a workspace you own, with its teams. One whose teams hold a project or an ' +
+ 'AI agent is refused until those are gone.',
},
},
)
@@ -182,7 +185,7 @@ export const workspaceRoutes = new Elysia({ name: 'workspaces', detail: { tags:
summary: 'Get SCIM provisioning settings',
description:
'Whether SCIM provisioning is on and whether a token has been generated. ' +
- 'Instance owner only.',
+ 'Workspace owner only.',
},
},
)
@@ -208,7 +211,7 @@ export const workspaceRoutes = new Elysia({ name: 'workspaces', detail: { tags:
response: { 200: ScimSettingsResponse, ...errors(400, 401, 403, 404) },
detail: {
summary: 'Update SCIM provisioning settings',
- description: 'Turn SCIM provisioning on or off. Instance owner only.',
+ description: 'Turn SCIM provisioning on or off. Workspace owner only.',
},
},
)
@@ -224,23 +227,23 @@ export const workspaceRoutes = new Elysia({ name: 'workspaces', detail: { tags:
summary: 'Generate a SCIM token',
description:
'Generate the bearer token an identity provider sends to /scim/v2, replacing any ' +
- 'previous one. The value is returned once and cannot be read back. Instance owner only.',
+ 'previous one. The value is returned once and cannot be read back. Workspace owner only.',
},
},
)
.get(
'/workspaces/:workspaceId/scim/groups',
- ({ standing }) => listWorkspaceScimGroups(standing.workspaceId),
+ ({ standing }) => listProvisionedGroups(standing.workspaceId),
{
workspaceScim: true,
params: workspaceParams,
- response: { 200: t.Array(ScimGroupResponse), ...errors(401, 403, 404) },
+ response: { 200: t.Array(ProvisionedGroupResponse), ...errors(401, 403, 404) },
detail: {
summary: 'List provisioned groups',
description:
"The groups the workspace's identity provider has pushed, with their member counts " +
- 'and the projects they grant membership in. Instance owner only.',
+ 'and the projects they grant membership in. Workspace owner only.',
},
},
)
@@ -248,33 +251,33 @@ export const workspaceRoutes = new Elysia({ name: 'workspaces', detail: { tags:
.put(
'/workspaces/:workspaceId/scim/groups/:groupId/mappings',
({ standing, params, body }) =>
- setWorkspaceScimGroupMappings(standing.workspaceId, params.groupId, body.mappings),
+ setGroupMappings(standing.workspaceId, params.groupId, body.mappings),
{
workspaceScim: true,
params: scimGroupParams,
body: ScimGroupMappingsBody,
- response: { 200: ScimGroupResponse, ...errors(400, 401, 403, 404) },
+ response: { 200: ProvisionedGroupResponse, ...errors(400, 401, 403, 404) },
detail: {
summary: "Set a group's project mappings",
description:
'Replace the projects of the workspace a provisioned group grants membership in, ' +
- 'then reconcile the membership of every project the change touched. Instance owner only.',
+ 'then reconcile the membership of every project the change touched. Workspace owner only.',
},
},
)
.get(
- '/workspaces/:workspaceId/projects/options',
- ({ standing }) => listWorkspaceProjectOptions(standing.workspaceId),
+ '/workspaces/:workspaceId/scim/projects',
+ ({ standing }) => listMappableProjects(standing.workspaceId),
{
workspaceScim: true,
params: workspaceParams,
- response: { 200: WorkspaceProjectOptionListResponse, ...errors(401, 403, 404) },
+ response: { 200: MappableProjectListResponse, ...errors(401, 403, 404) },
detail: {
summary: 'List workspace projects',
description:
'Every project of the workspace with the roles its team assigns, for the group ' +
- 'mapping picker. Instance owner only.',
+ 'mapping picker. Workspace owner only.',
},
},
);
diff --git a/apps/api/src/modules/workspaces/model.ts b/apps/api/src/modules/workspaces/model.ts
index 58b26e42..c55a951e 100644
--- a/apps/api/src/modules/workspaces/model.ts
+++ b/apps/api/src/modules/workspaces/model.ts
@@ -47,10 +47,9 @@ export const WorkspaceResponse = t.Object({
managerCount: t.Number(),
color: t.Nullable(t.String()),
teamCreation: t.UnionEnum([...TEAM_CREATION]),
- deletion: t.UnionEnum(['allowed', 'instance', 'work'], {
+ deletion: t.UnionEnum(['allowed', 'work'], {
description:
- 'Whether the owner may delete it: instance for the instance workspace, which stays; ' +
- 'work while a team of it holds a project or an AI agent.',
+ 'Whether the owner may delete it: work while a team of it holds a project or an AI agent.',
}),
});
@@ -65,54 +64,4 @@ export const WorkspaceManagerListResponse = t.Array(t.Object({ ...person, role:
export const WorkspaceCandidateListResponse = t.Array(t.Object(person));
-export const ScimSettingsResponse = t.Object({
- enabled: t.Boolean(),
- hasToken: t.Boolean(),
- tokenPrefix: t.String(),
- // Where to point the identity provider. Derived from the API origin, so the UI
- // shows it rather than asking the owner to assemble it.
- baseUrl: t.String(),
-});
-
-export const ScimSettingsBody = t.Object({
- enabled: t.Optional(t.Boolean()),
-});
-
-// The generated token, returned once. It is not stored anywhere it can be read
-// back, so a lost token is replaced rather than recovered.
-export const ScimTokenResponse = t.Object({
- token: t.String(),
-});
-
-const scimGroupMapping = t.Object({
- projectId: t.Integer(),
- role: t.UnionEnum(['owner', 'member']),
- // Which team_role a member joins on. Null for an owner (owners bypass the
- // permission matrix) or to fall back to the team's default role.
- roleId: t.Nullable(t.Integer()),
-});
-
-export const ScimGroupResponse = t.Object({
- id: t.String(),
- displayName: t.String(),
- externalId: t.Nullable(t.String()),
- memberCount: t.Integer(),
- mappings: t.Array(
- t.Intersect([scimGroupMapping, t.Object({ projectKey: t.String(), projectName: t.String() })]),
- ),
-});
-
-export const ScimGroupMappingsBody = t.Object({
- mappings: t.Array(scimGroupMapping, { maxItems: 100 }),
-});
-
export const scimGroupParams = t.Object({ workspaceId: t.Numeric(), groupId: t.String() });
-
-export const WorkspaceProjectOptionListResponse = t.Array(
- t.Object({
- id: t.Number(),
- key: t.String(),
- name: t.String(),
- roles: t.Array(t.Object({ id: t.Number(), name: t.String() })),
- }),
-);
diff --git a/apps/api/src/modules/workspaces/service.ts b/apps/api/src/modules/workspaces/service.ts
index 5b210606..7c606451 100644
--- a/apps/api/src/modules/workspaces/service.ts
+++ b/apps/api/src/modules/workspaces/service.ts
@@ -3,7 +3,6 @@ import {
aiAgent,
createWorkspace,
db,
- instanceWorkspaceId,
project,
team,
teamMember,
@@ -225,24 +224,19 @@ export async function workspaceHoldsWork(workspaceId: number): Promise<boolean>
return row !== undefined;
}
-export type WorkspaceDeletion = 'allowed' | 'instance' | 'work';
+export type WorkspaceDeletion = 'allowed' | 'work';
-// Whether the owner may delete the workspace, and if not, why. The instance workspace
-// stays: teams created without a workspace and SCIM on a self-hosted instance land in
-// it. One whose teams hold work keeps it until its projects and AI agents are gone.
+// Whether the owner may delete the workspace, and if not, why: one whose teams hold work
+// keeps it until its projects and AI agents are gone.
export async function workspaceDeletion(workspaceId: number): Promise<WorkspaceDeletion> {
- if (workspaceId === (await instanceWorkspaceId(db))) return 'instance';
return (await workspaceHoldsWork(workspaceId)) ? 'work' : 'allowed';
}
// Its teams go with it; their people keep their accounts and their other teams. An owner
-// left with no workspace gets a fresh personal one while personal workspaces are on.
+// left with no workspace gets a fresh personal one: the instance owner always, anyone
+// else while personal workspaces are on.
export async function deleteWorkspace(workspaceId: number, ownerId: string): Promise<void> {
- const deletion = await workspaceDeletion(workspaceId);
- if (deletion === 'instance') {
- throw new HttpError(409, 'The instance workspace cannot be deleted');
- }
- if (deletion === 'work') {
+ if ((await workspaceDeletion(workspaceId)) === 'work') {
throw new HttpError(409, 'Delete the projects and AI agents of its teams first');
}
await db.delete(workspace).where(eq(workspace.id, workspaceId));
@@ -302,19 +296,16 @@ export async function updateWorkspace(
}
// Hands the workspace to one of its admins; the owner stays on as an admin. No core route
-// calls it: an edition that offers handing a workspace over mounts its route here. The instance
-// workspace stays with the instance owner. Nobody takes on more workspaces than one person
-// may own, so handing over is no way around the limit; the instance owner is the
-// exception, as deleted accounts' workspaces pass to them anyway. An owner left with no
-// workspace gets a fresh personal one while personal workspaces are on.
+// calls it: an edition that offers handing a workspace over mounts its route here. Nobody
+// takes on more workspaces than one person may own, so handing over is no way around the
+// limit; the instance owner is the exception, as deleted accounts' workspaces pass to
+// them anyway. An owner left with no workspace gets a fresh personal one: the instance
+// owner always, anyone else while personal workspaces are on.
export async function transferWorkspace(
workspaceId: number,
ownerId: string,
toUserId: string,
): Promise<void> {
- if (workspaceId === (await instanceWorkspaceId(db))) {
- throw new HttpError(409, 'The instance workspace stays with the instance owner');
- }
if ((await getWorkspaceRole(workspaceId, toUserId)) !== 'admin') {
throw new HttpError(404, 'This person is not an admin of the workspace');
}
diff --git a/apps/api/src/shared/__tests__/integration/access.test.ts b/apps/api/src/shared/__tests__/integration/access.test.ts
index 2296b09c..97021bc5 100644
--- a/apps/api/src/shared/__tests__/integration/access.test.ts
+++ b/apps/api/src/shared/__tests__/integration/access.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'bun:test';
-import { authedApi } from '../../../__tests__/helpers/app';
+import { authedApi, createProject } from '../../../__tests__/helpers/app';
import { signUpTestUser } from '../../../__tests__/helpers/auth';
import { resetDb } from '../../../__tests__/helpers/db';
import { createRole } from '#tests/helpers/roles';
@@ -16,7 +16,7 @@ type Owner = { api: ReturnType<typeof authedApi> };
async function setupOwnerProject(): Promise<Owner> {
const owner = await signUpTestUser();
const api = authedApi(owner.cookie);
- await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await createProject(api, { key: 'MKT', name: 'Marketing' });
return { api };
}
diff --git a/apps/api/src/shared/auth-context.ts b/apps/api/src/shared/auth-context.ts
index efa8ae8d..41aa2d5b 100644
--- a/apps/api/src/shared/auth-context.ts
+++ b/apps/api/src/shared/auth-context.ts
@@ -61,6 +61,6 @@ export const authContext = new Elysia({ name: 'auth-context' }).resolve(
// has it on its next request instead of its next sign-in.
async function signedIn(user: SessionUser): Promise<SessionUser> {
if (isAccountDeactivated(user)) throw new HttpError(401, 'This account is deactivated');
- await ensurePersonalWorkspace(user.id);
+ await ensurePersonalWorkspace(user);
return user;
}
diff --git a/apps/api/src/shared/guards.ts b/apps/api/src/shared/guards.ts
index 5e748415..fa70982e 100644
--- a/apps/api/src/shared/guards.ts
+++ b/apps/api/src/shared/guards.ts
@@ -1,5 +1,5 @@
import { Elysia, type DocumentDecoration } from 'elysia';
-import { instanceScimWorkspace, workspaceScim as isScimPerWorkspace } from '@repo/auth';
+import { workspaceScim as isScimPerWorkspace } from '@repo/auth';
import { authContext } from './auth-context';
import {
requireProjectAccess,
@@ -343,10 +343,9 @@ export const guards = new Elysia({ name: 'guards' }).use(authContext).macro({
};
},
- // SCIM creates accounts and attaches existing ones to the workspace, which reaches past
- // the workspace to the whole instance, so only the instance owner sets it up, in a
- // workspace they own, unless SCIM is set up per workspace (setWorkspaceScim in
- // @repo/auth). The provider that acts on the whole instance stays the instance owner's.
+ // A workspace's own SCIM, where a build sets SCIM up per workspace (setWorkspaceScim in
+ // @repo/auth). Its provider attaches accounts to the workspace, so only the owner sets
+ // it up. Without it SCIM is the instance's, set up in god mode.
workspaceScim(_enabled: boolean) {
return {
async resolve({ params, user }) {
@@ -354,13 +353,11 @@ export const guards = new Elysia({ name: 'guards' }).use(authContext).macro({
Number((params as WorkspaceIdParams).workspaceId),
user,
);
- const byWorkspaceOwner =
- isScimPerWorkspace() && standing.workspaceId !== (await instanceScimWorkspace());
- if (standing.role !== 'owner' || (!byWorkspaceOwner && user?.role !== 'god')) {
- throw new HttpError(
- 403,
- `Only the ${byWorkspaceOwner ? 'workspace' : 'instance'} owner sets up SCIM provisioning`,
- );
+ if (!isScimPerWorkspace()) {
+ throw new HttpError(403, 'SCIM is set up for the whole instance in god mode');
+ }
+ if (standing.role !== 'owner') {
+ throw new HttpError(403, 'Only the workspace owner sets up SCIM provisioning');
}
return { standing };
},
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index b066ee01..cf52e0dc 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -31,10 +31,9 @@ Next.js App Router, SSR (not SPA). Tailwind v4 + shadcn/ui. See root `AGENTS.md`
the app shell, god mode and the teams pages; here it shows nothing, while the hosted
build shows notices about the instance there. `godSections(core)` returns the god mode
sections: here the core's as they are, while the hosted build adds, replaces or drops
- some. One it adds carries in `Component` the page `/god/<slug>` opens. SCIM is set up in
- god mode, for the instance workspace; the hosted build that moves it to every
- workspace drops the god section and adds `WorkspaceScimSection` through
- `useWorkspaceSections`. `SignInExtras` sits among the sign-in methods, after the
+ some. One it adds carries in `Component` the page `/god/<slug>` opens. The instance's
+ SCIM is set up in god mode; the hosted build that also sets it up per workspace adds
+ `WorkspaceScimSection` through `useWorkspaceSections`. `SignInExtras` sits among the sign-in methods, after the
instance's own provider; here it adds nothing, while the hosted build offers a sign-in
through providers of its own. A sign-in that comes back with a code the core does not
know shows the text the build's messages give it under `auth.errors.codes.<code>`.
diff --git a/apps/web/src/features/god/GodScimPage.tsx b/apps/web/src/features/god/GodScimPage.tsx
index 86a4383b..ab2aeda1 100644
--- a/apps/web/src/features/god/GodScimPage.tsx
+++ b/apps/web/src/features/god/GodScimPage.tsx
@@ -1,33 +1,23 @@
'use client';
-import { useWorkspaceScimQuery, useWorkspacesQuery } from '@/services/workspaces.service';
+import { useWorkspaceScimQuery } from '@/services/workspaces.service';
import ListSkeleton from '@/components/common/skeleton/ListSkeleton';
import WorkspaceScimSettings from '@/features/teams/components/workspace/scim/WorkspaceScimSettings';
import GodSectionPage from './components/GodSectionPage';
-// SCIM provisioning reaches past a workspace to the whole instance, so only the instance
-// owner sets it up, for the instance workspace (the API holds the same rule). That is the
-// first workspace, as `instanceWorkspaceId` in @repo/db has it, and the owner sees it
-// among theirs. The switch and the token act on their own, so there is no page-level Save.
+// The instance's SCIM provisioning: it reaches past every workspace to the whole
+// instance, so only the instance owner sets it up (the API holds the same rule). The
+// switch and the token act on their own, so there is no page-level Save.
export default function GodScimPage() {
- const workspaces = useWorkspacesQuery().data;
+ const settings = useWorkspaceScimQuery(null).data;
return (
<GodSectionPage slug="scim">
- {workspaces?.length ? (
- <InstanceScim workspaceId={Math.min(...workspaces.map((entry) => entry.id))} />
+ {settings ? (
+ <WorkspaceScimSettings workspaceId={null} settings={settings} />
) : (
<ListSkeleton rows={5} rowClassName="h-12" />
)}
</GodSectionPage>
);
}
-
-function InstanceScim({ workspaceId }: { workspaceId: number }) {
- const settings = useWorkspaceScimQuery(workspaceId).data;
- return settings ? (
- <WorkspaceScimSettings workspaceId={workspaceId} settings={settings} instance />
- ) : (
- <ListSkeleton rows={5} rowClassName="h-12" />
- );
-}
diff --git a/apps/web/src/features/teams/components/workspace/WorkspaceInfoSection.tsx b/apps/web/src/features/teams/components/workspace/WorkspaceInfoSection.tsx
index f8d7792d..efbed030 100644
--- a/apps/web/src/features/teams/components/workspace/WorkspaceInfoSection.tsx
+++ b/apps/web/src/features/teams/components/workspace/WorkspaceInfoSection.tsx
@@ -45,7 +45,6 @@ export default function WorkspaceInfoSection({ workspaceId }: { workspaceId: num
if (!workspace) return <SectionPageSkeleton rows={2} />;
const isOwner = workspace.role === 'owner';
- const deletable = isOwner && workspace.deletion !== 'instance';
const nextName = (name ?? workspace.name).trim();
const nextColor = color === null ? workspace.color : color.trim() || null;
const nextTeamCreation = teamCreation ?? workspace.teamCreation;
@@ -144,7 +143,7 @@ export default function WorkspaceInfoSection({ workspaceId }: { workspaceId: num
<WorkspaceSectionExtras slug="general" workspace={workspace} />
- {deletable && <WorkspaceDeleteSection workspace={workspace} />}
+ {isOwner && <WorkspaceDeleteSection workspace={workspace} />}
</div>
</SectionPageView>
);
diff --git a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupList.tsx b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupList.tsx
index 6eead333..97763aa2 100644
--- a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupList.tsx
+++ b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupList.tsx
@@ -12,7 +12,7 @@ import WorkspaceScimGroupMappingDialog from './WorkspaceScimGroupMappingDialog';
// The groups the identity provider has pushed. The list itself is read-only — it is
// the provider's — and what each group grants is set here.
-export default function WorkspaceScimGroupList({ workspaceId }: { workspaceId: number }) {
+export default function WorkspaceScimGroupList({ workspaceId }: { workspaceId: number | null }) {
const t = useTranslations('teams.workspace.scim');
const groups = useWorkspaceScimGroupsQuery(workspaceId);
const [editing, setEditing] = useState<WorkspaceScimGroup | null>(null);
diff --git a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupMappingDialog.tsx b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupMappingDialog.tsx
index faf927ff..c89a428f 100644
--- a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupMappingDialog.tsx
+++ b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimGroupMappingDialog.tsx
@@ -24,7 +24,7 @@ export default function WorkspaceScimGroupMappingDialog({
group,
onClose,
}: {
- workspaceId: number;
+ workspaceId: number | null;
group: WorkspaceScimGroup;
onClose: () => void;
}) {
diff --git a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSection.tsx b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSection.tsx
index 56787409..4a7fb930 100644
--- a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSection.tsx
+++ b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSection.tsx
@@ -9,8 +9,8 @@ import WorkspaceScimSettings from './WorkspaceScimSettings';
// SCIM provisioning: the token an identity provider authenticates with, and what the
// groups it pushes grant. Nothing here is a form the owner fills in and saves — the
// switch and the token act on their own — so there is no page-level Save. The core sets
-// up SCIM in god mode, for the instance workspace (GodScimPage); this is the page a
-// hosted build adds to every workspace's settings through `useWorkspaceSections`.
+// up the instance's SCIM in god mode (GodScimPage); this is the page a hosted build adds
+// to every workspace's settings through `useWorkspaceSections`.
export default function WorkspaceScimSection({ workspaceId }: { workspaceId: number }) {
const t = useTranslations('teams.workspace.scim');
const settings = useWorkspaceScimQuery(workspaceId).data;
diff --git a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSettings.tsx b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSettings.tsx
index 8675c63f..cff5e505 100644
--- a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSettings.tsx
+++ b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimSettings.tsx
@@ -14,16 +14,14 @@ import WorkspaceScimTokenDialog from './WorkspaceScimTokenDialog';
import WorkspaceScimGroupList from './WorkspaceScimGroupList';
// The endpoint and the token go into the identity provider; the groups it then
-// pushes appear below, where the owner says what each one grants. `instance` is set in
-// god mode, where the provider acts on the whole instance.
+// pushes appear below, where the owner says what each one grants. `workspaceId` is null
+// in god mode, where the provider is the instance's and acts on the whole instance.
export default function WorkspaceScimSettings({
workspaceId,
settings,
- instance = false,
}: {
- workspaceId: number;
+ workspaceId: number | null;
settings: Settings;
- instance?: boolean;
}) {
const t = useTranslations('teams.workspace.scim');
const update = useUpdateWorkspaceScim(workspaceId);
@@ -42,7 +40,7 @@ export default function WorkspaceScimSettings({
<div className="space-y-10">
<SettingsSection
title={t('provisioning')}
- description={t(provisioningHint(settings.hasToken, instance))}
+ description={t(provisioningHint(settings.hasToken, workspaceId === null))}
action={
<EnabledSwitch
checked={settings.enabled}
diff --git a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimTokenDialog.tsx b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimTokenDialog.tsx
index 407952d3..abae3965 100644
--- a/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimTokenDialog.tsx
+++ b/apps/web/src/features/teams/components/workspace/scim/WorkspaceScimTokenDialog.tsx
@@ -15,7 +15,7 @@ export default function WorkspaceScimTokenDialog({
workspaceId,
onClose,
}: {
- workspaceId: number;
+ workspaceId: number | null;
onClose: () => void;
}) {
const t = useTranslations('teams.workspace.scim.tokenDialog');
diff --git a/apps/web/src/features/teams/hooks/useWorkspaceScimMappingForm.ts b/apps/web/src/features/teams/hooks/useWorkspaceScimMappingForm.ts
index d9e1f677..f53f0b81 100644
--- a/apps/web/src/features/teams/hooks/useWorkspaceScimMappingForm.ts
+++ b/apps/web/src/features/teams/hooks/useWorkspaceScimMappingForm.ts
@@ -31,7 +31,7 @@ function serialize(mappings: ScimMappingDraft[]): string {
}
export function useWorkspaceScimMappingForm(
- workspaceId: number,
+ workspaceId: number | null,
group: WorkspaceScimGroup,
): WorkspaceScimMappingForm {
const update = useSetWorkspaceScimGroupMappings(workspaceId);
diff --git a/apps/web/src/lib/api/endpoints/workspaces.ts b/apps/web/src/lib/api/endpoints/workspaces.ts
index 37d529e5..31dd7d78 100644
--- a/apps/web/src/lib/api/endpoints/workspaces.ts
+++ b/apps/web/src/lib/api/endpoints/workspaces.ts
@@ -15,8 +15,8 @@ export interface WorkspaceSummary {
// one of its teams.
export type TeamCreation = 'owner' | 'managers' | 'members';
-// `deletion` says whether the owner may delete it: `instance` for the instance workspace,
-// which stays; `work` while a team of it holds a project or an AI agent.
+// `deletion` says whether the owner may delete it: `work` while a team of it holds a
+// project or an AI agent.
export interface Workspace {
id: number;
name: string;
@@ -24,7 +24,7 @@ export interface Workspace {
managerCount: number;
color: string | null;
teamCreation: TeamCreation;
- deletion: 'allowed' | 'instance' | 'work';
+ deletion: 'allowed' | 'work';
}
export interface WorkspacePatch {
@@ -75,8 +75,9 @@ export const addWorkspaceAdmin = (workspaceId: number, userId: string) =>
export const removeWorkspaceAdmin = (workspaceId: number, userId: string) =>
request<void>(`/workspaces/${workspaceId}/managers/${userId}`, { method: 'DELETE' });
-// SCIM provisioning. The token is never returned, only its prefix; a new one is
-// generated with createWorkspaceScimToken and shown once.
+// SCIM provisioning of a workspace, or of the instance in god mode when `workspaceId` is
+// null. The token is never returned, only its prefix; a new one is generated with
+// createWorkspaceScimToken and shown once.
export interface WorkspaceScimSettings {
enabled: boolean;
hasToken: boolean;
@@ -102,7 +103,7 @@ export interface WorkspaceScimGroup {
mappings: WorkspaceScimGroupMapping[];
}
-// A project of the workspace as the group mapping form picks it, with the roles of
+// A project a group may grant, as the group mapping form picks it, with the roles of
// the team that owns it.
export interface WorkspaceProjectOption {
id: number;
@@ -111,31 +112,34 @@ export interface WorkspaceProjectOption {
roles: { id: number; name: string }[];
}
-export const getWorkspaceScim = (workspaceId: number) =>
- request<WorkspaceScimSettings>(`/workspaces/${workspaceId}/scim`);
+const scimPath = (workspaceId: number | null) =>
+ workspaceId === null ? '/god/scim' : `/workspaces/${workspaceId}/scim`;
-export const updateWorkspaceScim = (workspaceId: number, patch: { enabled: boolean }) =>
- request<WorkspaceScimSettings>(`/workspaces/${workspaceId}/scim`, {
+export const getWorkspaceScim = (workspaceId: number | null) =>
+ request<WorkspaceScimSettings>(scimPath(workspaceId));
+
+export const updateWorkspaceScim = (workspaceId: number | null, patch: { enabled: boolean }) =>
+ request<WorkspaceScimSettings>(scimPath(workspaceId), {
method: 'PATCH',
body: JSON.stringify(patch),
});
// Returns the new token in the clear. It is shown once and cannot be read back.
-export const createWorkspaceScimToken = (workspaceId: number) =>
- request<{ token: string }>(`/workspaces/${workspaceId}/scim/token`, { method: 'POST' });
+export const createWorkspaceScimToken = (workspaceId: number | null) =>
+ request<{ token: string }>(`${scimPath(workspaceId)}/token`, { method: 'POST' });
-export const listWorkspaceScimGroups = (workspaceId: number) =>
- request<WorkspaceScimGroup[]>(`/workspaces/${workspaceId}/scim/groups`);
+export const listWorkspaceScimGroups = (workspaceId: number | null) =>
+ request<WorkspaceScimGroup[]>(`${scimPath(workspaceId)}/groups`);
export const setWorkspaceScimGroupMappings = (
- workspaceId: number,
+ workspaceId: number | null,
groupId: string,
mappings: { projectId: number; role: 'owner' | 'member'; roleId: number | null }[],
) =>
- request<WorkspaceScimGroup>(`/workspaces/${workspaceId}/scim/groups/${groupId}/mappings`, {
+ request<WorkspaceScimGroup>(`${scimPath(workspaceId)}/groups/${groupId}/mappings`, {
method: 'PUT',
body: JSON.stringify({ mappings }),
});
-export const listWorkspaceProjectOptions = (workspaceId: number) =>
- request<WorkspaceProjectOption[]>(`/workspaces/${workspaceId}/projects/options`);
+export const listWorkspaceProjectOptions = (workspaceId: number | null) =>
+ request<WorkspaceProjectOption[]>(`${scimPath(workspaceId)}/projects`);
diff --git a/apps/web/src/services/queryKeys.ts b/apps/web/src/services/queryKeys.ts
index 2be8647c..2b5d71cb 100644
--- a/apps/web/src/services/queryKeys.ts
+++ b/apps/web/src/services/queryKeys.ts
@@ -1,5 +1,8 @@
import type { FeedFilter, FeedOrder } from '@/lib/api/endpoints/activity';
+const scimKey = (workspaceId: number | null) =>
+ workspaceId === null ? (['god', 'scim'] as const) : (['workspace', workspaceId, 'scim'] as const);
+
// Query keys shared by every service. Each is a stable tuple; a project/issue id
// or key scopes its entry. Kept in one registry so a mutation in one service can
// invalidate another service's queries by the same key.
@@ -15,11 +18,9 @@ export const qk = {
workspaceManagers: (workspaceId: number) => ['workspace', workspaceId, 'managers'] as const,
workspaceManagerCandidates: (workspaceId: number, search: string) =>
['workspace', workspaceId, 'managers', 'candidates', search] as const,
- workspaceScim: (workspaceId: number) => ['workspace', workspaceId, 'scim'] as const,
- workspaceScimGroups: (workspaceId: number) =>
- ['workspace', workspaceId, 'scim', 'groups'] as const,
- workspaceProjectOptions: (workspaceId: number) =>
- ['workspace', workspaceId, 'projectOptions'] as const,
+ scim: scimKey,
+ scimGroups: (workspaceId: number | null) => [...scimKey(workspaceId), 'groups'] as const,
+ scimProjects: (workspaceId: number | null) => [...scimKey(workspaceId), 'projects'] as const,
teamProjectDefaults: (teamId: number) => ['team', teamId, 'project-defaults'] as const,
// The members of a team and the projects it owns, each read by its own section. A
// page is scoped by the search term and the window it was read with.
diff --git a/apps/web/src/services/workspaces.service.ts b/apps/web/src/services/workspaces.service.ts
index 39aaca90..6fd2c929 100644
--- a/apps/web/src/services/workspaces.service.ts
+++ b/apps/web/src/services/workspaces.service.ts
@@ -86,54 +86,54 @@ export function useRemoveWorkspaceAdmin(workspaceId: number) {
}
// SCIM provisioning: the token an identity provider authenticates with, and what the
-// groups it pushes grant.
-export function useWorkspaceScimQuery(workspaceId: number) {
+// groups it pushes grant. A workspace's, or the instance's in god mode for null.
+export function useWorkspaceScimQuery(workspaceId: number | null) {
return useQuery({
- queryKey: qk.workspaceScim(workspaceId),
+ queryKey: qk.scim(workspaceId),
queryFn: () => getWorkspaceScim(workspaceId),
});
}
-export function useUpdateWorkspaceScim(workspaceId: number) {
+export function useUpdateWorkspaceScim(workspaceId: number | null) {
const qc = useQueryClient();
return useMutation({
mutationFn: (patch: { enabled: boolean }) => updateWorkspaceScim(workspaceId, patch),
- onSuccess: (data) => qc.setQueryData(qk.workspaceScim(workspaceId), data),
+ onSuccess: (data) => qc.setQueryData(qk.scim(workspaceId), data),
});
}
-export function useCreateWorkspaceScimToken(workspaceId: number) {
+export function useCreateWorkspaceScimToken(workspaceId: number | null) {
const qc = useQueryClient();
return useMutation({
mutationFn: () => createWorkspaceScimToken(workspaceId),
// The response is the token itself, not the settings, so the redacted view has
// to be refetched for its new prefix.
- onSuccess: () => qc.invalidateQueries({ queryKey: qk.workspaceScim(workspaceId), exact: true }),
+ onSuccess: () => qc.invalidateQueries({ queryKey: qk.scim(workspaceId), exact: true }),
});
}
-export function useWorkspaceScimGroupsQuery(workspaceId: number) {
+export function useWorkspaceScimGroupsQuery(workspaceId: number | null) {
return useQuery({
- queryKey: qk.workspaceScimGroups(workspaceId),
+ queryKey: qk.scimGroups(workspaceId),
queryFn: () => listWorkspaceScimGroups(workspaceId),
});
}
-export function useSetWorkspaceScimGroupMappings(workspaceId: number) {
+export function useSetWorkspaceScimGroupMappings(workspaceId: number | null) {
const qc = useQueryClient();
return useMutation({
mutationFn: (input: {
groupId: string;
mappings: { projectId: number; role: 'owner' | 'member'; roleId: number | null }[];
}) => setWorkspaceScimGroupMappings(workspaceId, input.groupId, input.mappings),
- onSuccess: () => qc.invalidateQueries({ queryKey: qk.workspaceScimGroups(workspaceId) }),
+ onSuccess: () => qc.invalidateQueries({ queryKey: qk.scimGroups(workspaceId) }),
});
}
-// Every project of the workspace, for the group mapping picker.
-export function useWorkspaceProjectOptionsQuery(workspaceId: number) {
+// Every project a group may grant, for the group mapping picker.
+export function useWorkspaceProjectOptionsQuery(workspaceId: number | null) {
return useQuery({
- queryKey: qk.workspaceProjectOptions(workspaceId),
+ queryKey: qk.scimProjects(workspaceId),
queryFn: () => listWorkspaceProjectOptions(workspaceId),
});
}
diff --git a/docs/self-hosting.md b/docs/self-hosting.md
index 1bd2070c..81a9ec83 100644
--- a/docs/self-hosting.md
+++ b/docs/self-hosting.md
@@ -132,29 +132,28 @@ instance cannot be left with no way in.
## Provisioning with SCIM
-An identity provider can add people to a workspace and remove them over SCIM 2.0, and grant
-project access through its groups. Provisioning is a setting of the workspace, and only its
-owner can change it.
+An identity provider can create, deactivate and delete the accounts of the instance over
+SCIM 2.0, and grant project access through its groups. Provisioning is set up in god mode by
+the instance owner.
-1. In the workspace settings, open **SCIM**, generate a token and copy it — it is shown
- once — then turn provisioning on.
+1. In god mode, open **SCIM**, generate a token and copy it — it is shown once — then turn
+ provisioning on.
2. Point your provider's SCIM application at the endpoint the page shows
(`<API_URL>/scim/v2`), authenticating with `Authorization: Bearer <token>`.
3. Push users, and groups if you use them.
-An account belongs to the person, not to the workspace: one person can be in the teams of
-several workspaces, and each workspace's provider only decides whether they are in its own.
-The provider sees the people it created or linked and the people in the workspace's teams. A
-create for an address that already has an account links that account instead of making a
-second one; a name or address the provider sends is accepted and left as the account has it.
-
-Deactivating someone at the provider (`active: false`) or deleting them takes them out of
-every team and project of the workspace, including the ones they joined through an invite. A
-team or project they were the only owner of passes to the workspace owner. The account, its
-sign-in and the person's other workspaces are not touched. Reactivating gives back the
-projects their groups grant; memberships from invites do not come back. The instance owner and
-the workspace owner are outside SCIM's reach, and a repeated create for an address the
-provider already linked answers "already exists" rather than overwriting the link.
+The provider sees every account of the instance except those of AI agents. A create for an
+address that already has an account links that account instead of making a second one, and a
+name or address the provider sends is written to the account. While provisioning is on, the
+provider decides which accounts are active, and god mode cannot deactivate or reactivate one.
+
+Deactivating someone at the provider (`active: false`) keeps their teams and projects, but the
+account cannot sign in, and its sessions and API keys are refused until it is reactivated.
+Reactivating gives them the projects their groups grant. Deleting someone deletes the
+account. The delete is refused while they are the only owner of a project outside their own
+workspaces: deactivate them instead, or hand the project to another owner first. The instance
+owner is outside SCIM's reach, and a repeated create for an address the provider already
+linked answers "already exists" rather than overwriting the link.
A pushed group grants nothing until you say what it is for: on the same page, open a group
and add the projects its members should join, and the role they join on. A project belongs
diff --git a/packages/auth/AGENTS.md b/packages/auth/AGENTS.md
index 8b7a1764..fdd4dc2f 100644
--- a/packages/auth/AGENTS.md
+++ b/packages/auth/AGENTS.md
@@ -17,9 +17,9 @@ The **server-side** better-auth instance. Consumed by `apps/api`. See root `AGEN
The user table has a `role` column (`"god"` | `"user"`), declared as a better-auth
`additionalField` with `input: false` (not client-settable). A `databaseHooks.user.create.before`
hook sets it: the first user to register gets `"god"`, everyone after gets `"user"`.
-`databaseHooks.user.create.after` makes the `"god"` account the owner of the instance
-workspace and gives every other account a workspace of its own, named after the person,
-while `personalWorkspaces` is on in the auth settings (`ensurePersonalWorkspace`). apps/api
+`databaseHooks.user.create.after` gives the account a workspace of its own, named after
+the person (`ensurePersonalWorkspace`): the `"god"` account always, every other account
+while `personalWorkspaces` is on in the auth settings. apps/api
calls the same function on every request, so an account made before, by SCIM (a direct
insert, which passes no hook) or while the setting was off gets its own on its next
request. It remembers per process who needs nothing, so a request costs a lookup; an
@@ -35,9 +35,9 @@ through this module — never inline a query on `app_setting` / `app_secret` els
- `app_setting` key `auth` → `{ registration, requireEmailVerification, magicLink,
emailPassword, trustProviderEmails, personalWorkspaces, inviteTtlDays,
allowedEmailDomains }`.
-- `app_secret` keys `auth.email`, `auth.google` and `auth.oidc` → the mail provider, Google
- and the OIDC provider, set in god mode; `workspace.<id>.scim` → a workspace's SCIM token,
- set by the workspace owner. All encrypted with `@repo/crypto`, each with a `redacted`
+- `app_secret` keys `auth.email`, `auth.google`, `auth.oidc` and `auth.scim` → the mail
+ provider, Google, the OIDC provider and the instance's SCIM token, set in god mode;
+ `workspace.<id>.scim` → a workspace's SCIM token, set by the workspace owner. All encrypted with `@repo/crypto`, each with a `redacted`
mirror for the settings UI. Secrets never leave the server.
The mail provider is read by the api and the worker as well, so its shape and reader
@@ -150,29 +150,27 @@ which is what stops an instance being left with no way in.
## SCIM
-What a provider says about a person is kept per workspace in `scim_user`, written by
-`apps/api`. How far it reaches is `workspaceScim()`, which a hosted build turns on with
-`setWorkspaceScim()`. Off, as on a self-hosted instance, SCIM is the instance's: only the
-instance workspace's token opens it, and it also writes `active`, one more
+What a provider says about a person is kept per provider in `scim_user`, written by
+`apps/api`. The instance's provider is set up in god mode and stored with `workspace_id`
+null; a hosted build also lets every workspace set up its own with `setWorkspaceScim()`
+(`workspaceScim()` reads it). The instance's provider writes `active`, one more
`additionalField` on the user table (nullable, so every check is `active !== false`).
-God mode writes `active` too, from the users table, while no provider manages accounts
-(`accountsManagedByScim`: SCIM per workspace alone, or the instance workspace's SCIM set
-up with a token); while one does, `apps/api` answers god's switch with 409. An account
-with `active` false (`isAccountDeactivated`) is refused at sign-in by the
-`session.create.before` hook with `ACCOUNT_DEACTIVATED`, which covers every sign-in method
-at once; `apps/api` refuses the sessions and keys it already holds. On, a workspace's
-provider decides who is in the workspace, not who has an account, `active` is not read,
-and nothing here refuses a session. `setInstanceScimBeside()` keeps the instance
-workspace's provider, beside every other workspace's, as it is while off: acting on the
-whole instance and writing `active`. `instanceScimWorkspace()` names the workspace whose
-provider acts on the whole instance, or null when none does.
-
-`getScimSettings` / `rotateScimToken` / `verifyScimToken` hold the bearer token of each
-workspace that the SCIM endpoints in `apps/api` authenticate with. A token reads
-`scim_<workspaceId>_<secret>`, so `verifyScimToken` reads one workspace's token and answers
-with that workspace's id; a token issued before workspaces reads `scim_<secret>` and belongs
-to the instance workspace. The token is returned in the clear exactly once, when it is
-generated; only its prefix is kept in the redacted mirror.
+God mode writes `active` too, from the users table, while that provider does not manage
+accounts (`accountsManagedByScim`: its SCIM on with a token); while it does, `apps/api`
+answers god's switch with 409. An account with `active` false (`isAccountDeactivated`) is
+refused at sign-in by the `session.create.before` hook with `ACCOUNT_DEACTIVATED`, which
+covers every sign-in method at once; `apps/api` refuses the sessions and keys it already
+holds. A workspace's provider decides who is in the workspace, not who has an account;
+`active` is not written for it, and nothing here refuses a session.
+
+`getScimSettings` / `rotateScimToken` / `verifyScimToken` take the workspace, or null for the
+instance, and hold the bearer token the SCIM endpoints in `apps/api` authenticate with. The
+instance's is stored under `auth.scim` and reads `scim_<secret>`; one it held while it
+belonged to the first workspace reads `scim_<id>_<secret>` and keeps working. A workspace's
+is stored under `workspace.<id>.scim` and reads `scim_<workspaceId>_<secret>`, so
+`verifyScimToken` checks the instance's first and then reads only the named workspace's.
+The token is returned in the clear exactly once, when it is generated; only its prefix is
+kept in the redacted mirror.
## Passkey
diff --git a/packages/auth/src/index.ts b/packages/auth/src/index.ts
index 803151d6..7afc6198 100644
--- a/packages/auth/src/index.ts
+++ b/packages/auth/src/index.ts
@@ -1,5 +1,5 @@
import { randomInt } from 'node:crypto';
-import { createWorkspace, db, instanceWorkspaceId } from '@repo/db';
+import { createWorkspace, db } from '@repo/db';
import { and, eq, gt, isNull, sql, type SQL } from 'drizzle-orm';
import { betterAuth, type BetterAuthPlugin } from 'better-auth';
import { createAuthMiddleware, APIError } from 'better-auth/api';
@@ -445,30 +445,34 @@ function randomSuffix(): string {
return String(100 + randomInt(900));
}
-// Accounts that need no personal workspace made: they own a workspace, or are the
-// instance owner or an agent's bot user. Kept per process, so once an account is known a
-// request costs a lookup here and nothing in the database.
+// Accounts that need no personal workspace made: they own a workspace, or are an agent's
+// bot user. Kept per process, so once an account is known a request costs a lookup here
+// and nothing in the database.
const settled = new Set<string>();
-// The personal workspace of an account that owns none, while personal workspaces are on,
-// named after the person. Sign-up calls it, and apps/api on every request, so an account
-// made before personal workspaces, by SCIM, or while they were off gets its own without
-// signing in again. Nothing in the API creates a workspace; an edition that lets a
-// person own more mounts a route of its own. The instance owner owns the instance
-// workspace instead, and an agent's bot user is no person.
+// The personal workspace of an account that owns none, named after the person: the
+// instance owner's always, anyone else's while personal workspaces are on. Sign-up calls
+// it, and apps/api on every request, so an account made before personal workspaces, by
+// SCIM, or while they were off gets its own without signing in again. Nothing in the API
+// creates a workspace; an edition that lets a person own more mounts a route of its own.
+// An agent's bot user is no person.
// ponytail: an account with no workspace while they are off reads the setting on each
// request; cache it with the setting if that ever shows.
-export async function ensurePersonalWorkspace(userId: string): Promise<void> {
+export async function ensurePersonalWorkspace(account: {
+ id: string;
+ role?: string | null;
+}): Promise<void> {
+ const userId = account.id;
if (settled.has(userId)) return;
- if (!(await getAuthSettings()).personalWorkspaces) return;
+ if (account.role !== 'god' && !(await getAuthSettings()).personalWorkspaces) return;
await db.transaction(async (tx) => {
// Two sign-ins at once would otherwise both find none.
- const [account] = await tx
- .select({ name: schema.user.name, email: schema.user.email, role: schema.user.role })
+ const [person] = await tx
+ .select({ name: schema.user.name, email: schema.user.email })
.from(schema.user)
.where(eq(schema.user.id, userId))
.for('update');
- if (!account || account.role === 'god') return;
+ if (!person) return;
const [owned] = await tx
.select({ n: sql`1` })
.from(schema.workspaceManager)
@@ -482,7 +486,7 @@ export async function ensurePersonalWorkspace(userId: string): Promise<void> {
.where(eq(schema.aiAgent.userId, userId))
.limit(1);
if (owned || agent) return;
- const name = (account.name.trim() || account.email.split('@')[0]!).slice(0, 60);
+ const name = (person.name.trim() || person.email.split('@')[0]!).slice(0, 60);
await createWorkspace(tx, name, userId);
});
settled.add(userId);
@@ -812,18 +816,7 @@ function createAuth() {
};
},
after: async (user) => {
- if (user.role === 'god') {
- await db
- .insert(schema.workspaceManager)
- .values({
- workspaceId: await instanceWorkspaceId(db),
- userId: user.id,
- role: 'owner',
- })
- .onConflictDoNothing();
- } else {
- await ensurePersonalWorkspace(user.id);
- }
+ await ensurePersonalWorkspace(user);
},
},
},
@@ -1051,8 +1044,6 @@ export {
verifyScimToken,
setWorkspaceScim,
workspaceScim,
- setInstanceScimBeside,
- instanceScimWorkspace,
workspacesWithOwnScim,
isAccountDeactivated,
accountsManagedByScim,
@@ -1068,5 +1059,5 @@ export type {
InstanceOidcDto,
InstanceOidcPatch,
InstanceOidcConfig,
- WorkspaceScimDto,
+ ScimSettingsDto,
} from './instance';
diff --git a/packages/auth/src/instance.ts b/packages/auth/src/instance.ts
index b48933ff..b0bed846 100644
--- a/packages/auth/src/instance.ts
+++ b/packages/auth/src/instance.ts
@@ -2,7 +2,6 @@ import { randomBytes, timingSafeEqual } from 'node:crypto';
import {
db,
appSecret,
- instanceWorkspaceId,
teamInvite,
getSetting,
setSetting,
@@ -26,15 +25,17 @@ import type { GenericEndpointContext } from 'better-auth';
// Non-secret settings are one jsonb blob in app_setting under the 'auth' key; the
// credentials are encrypted in app_secret, each with a `redacted` mirror the settings
// UI can read without decrypting. The instance's own are under 'auth.email',
-// 'auth.google' and 'auth.oidc', set in god mode; SCIM belongs to a workspace and is
-// stored under 'workspace.<id>.scim'. The mail config is also read by the api and the
-// worker, so its shape and reader live in @repo/db; what stays here is the write side.
+// 'auth.google', 'auth.oidc' and 'auth.scim', set in god mode; a workspace's SCIM, where
+// a build sets it up per workspace, is under 'workspace.<id>.scim'. The mail config is
+// also read by the api and the worker, so its shape and reader live in @repo/db; what
+// stays here is the write side.
const AUTH_SETTING_KEY = 'auth';
const GOOGLE_SECRET_KEY = 'auth.google';
const OIDC_SECRET_KEY = 'auth.oidc';
-const scimSecretKey = (workspaceId: number) => `workspace.${workspaceId}.scim`;
+const scimSecretKey = (workspaceId: number | null) =>
+ workspaceId === null ? 'auth.scim' : `workspace.${workspaceId}.scim`;
// Who may create an account.
// open — anyone can sign up
@@ -467,15 +468,17 @@ export async function setOidcSettings(patch: InstanceOidcPatch): Promise<Instanc
// ── SCIM provisioning token ───────────────────────────────────────────────────
-// The bearer token an identity provider sends to /scim/v2. One token per workspace,
-// generated here and shown to the owner once: only its prefix is kept in the
-// redacted mirror, so a lost token is replaced rather than recovered.
-export interface WorkspaceScimConfig {
+// The bearer token an identity provider sends to /scim/v2: the instance's, set up in god
+// mode, and one per workspace where a build sets SCIM up per workspace. Every function
+// here takes the workspace, or null for the instance's. A token is generated here and
+// shown once: only its prefix is kept in the redacted mirror, so a lost token is
+// replaced rather than recovered.
+export interface ScimConfig {
enabled: boolean;
token: string;
}
-export interface WorkspaceScimDto {
+export interface ScimSettingsDto {
enabled: boolean;
hasToken: boolean;
// First characters of the stored token, so the owner can tell which one an IdP
@@ -483,11 +486,10 @@ export interface WorkspaceScimDto {
tokenPrefix: string;
}
-// Whether SCIM is set up per workspace. Off, as on a self-hosted instance, it is the
-// instance owner's alone and acts on the whole instance: only the instance workspace's
-// token opens /scim/v2, its provider sees and deactivates every account, and a
-// deactivated account cannot sign in. On, as in a hosted build, every workspace owner
-// sets it up and their provider decides who is in their workspace, nothing more.
+// The instance's provider is god's and acts on the whole instance: it sees and
+// deactivates every account, and a deactivated account cannot sign in. A hosted build
+// also lets every workspace owner set up a provider of their own, which decides who is
+// in their workspace, nothing more.
let scimPerWorkspace = false;
export function setWorkspaceScim(on = true): void {
@@ -498,42 +500,23 @@ export function workspaceScim(): boolean {
return scimPerWorkspace;
}
-// Set up per workspace, whether the instance workspace's provider still acts on the
-// whole instance, as it does while SCIM is the instance's. A build where one
-// organisation runs the instance keeps its own provider over every account, and a
-// workspace that sets up its own decides who is in that workspace instead.
-let instanceScimBeside = false;
-
-export function setInstanceScimBeside(on = true): void {
- instanceScimBeside = on;
-}
-
-const instanceScimWide = () => !scimPerWorkspace || instanceScimBeside;
-
-// The workspace whose provider acts on the whole instance, or null when none does.
-export async function instanceScimWorkspace(): Promise<number | null> {
- return instanceScimWide() ? instanceWorkspaceId(db) : null;
-}
-
-// True for an account the instance's identity provider deactivated (`user.active`),
-// while that provider acts on the whole instance. Such an account cannot sign in, and
-// the api refuses the sessions and keys it already holds.
+// True for an account the instance's identity provider or god deactivated
+// (`user.active`). Such an account cannot sign in, and the api refuses the sessions and
+// keys it already holds.
export function isAccountDeactivated(account: { active?: boolean | null }): boolean {
- return instanceScimWide() && account.active === false;
+ return account.active === false;
}
-// Whether an identity provider decides which accounts are active, so god does not: SCIM
-// per workspace alone, where a deactivation has no effect, or the instance workspace's
-// SCIM set up with a token, the same condition under which verifyScimToken opens /scim/v2.
+// Whether the instance's identity provider decides which accounts are active, so god
+// does not: its SCIM is on with a token, the condition under which verifyScimToken
+// opens /scim/v2 for it.
export async function accountsManagedByScim(): Promise<boolean> {
- if (!instanceScimWide()) return true;
- const config = await getScimConfig(await instanceWorkspaceId(db));
+ const config = await getScimConfig(null);
return config.enabled && config.token.length > 0;
}
-// The workspaces besides the instance's that set up SCIM of their own, read from the
-// redacted mirror. Their own provider decides who is in them, so the instance's groups
-// grant nothing there.
+// The workspaces that set up SCIM of their own, read from the redacted mirror. Their own
+// provider decides who is in them, so the instance's groups grant nothing there.
export async function workspacesWithOwnScim(): Promise<number[]> {
if (!scimPerWorkspace) return [];
const rows = await db
@@ -546,23 +529,21 @@ export async function workspacesWithOwnScim(): Promise<number[]> {
sql`${appSecret.redacted}->>'hasToken' = 'true'`,
),
);
- const instanceId = await instanceWorkspaceId(db);
- return rows
- .map((row) => Number(row.key.split('.')[1]))
- .filter((id) => Number.isInteger(id) && id !== instanceId);
+ return rows.map((row) => Number(row.key.split('.')[1])).filter(Number.isInteger);
}
-// A token reads scim_<workspaceId>_<secret>, so the workspace it opens is found
-// without trying the token of every workspace. A token issued before workspaces
-// existed reads scim_<secret> and belongs to the instance workspace.
+// A workspace's token reads scim_<workspaceId>_<secret>, so the workspace it opens is
+// found without trying the token of every workspace. The instance's reads
+// scim_<secret>, or carries the id of the workspace it belonged to before SCIM was the
+// instance's.
const SCIM_TOKEN_PREFIX = 'scim_';
const SCIM_TOKEN_WORKSPACE = /^scim_(\d+)_/;
-function defaultScimConfig(): WorkspaceScimConfig {
+function defaultScimConfig(): ScimConfig {
return { enabled: false, token: '' };
}
-function toScimDto(config: WorkspaceScimConfig): WorkspaceScimDto {
+function toScimDto(config: ScimConfig): ScimSettingsDto {
return {
enabled: config.enabled,
hasToken: config.token.length > 0,
@@ -572,21 +553,21 @@ function toScimDto(config: WorkspaceScimConfig): WorkspaceScimDto {
};
}
-async function getScimConfig(workspaceId: number): Promise<WorkspaceScimConfig> {
- const stored = await readSecret<WorkspaceScimConfig>(scimSecretKey(workspaceId));
+async function getScimConfig(workspaceId: number | null): Promise<ScimConfig> {
+ const stored = await readSecret<ScimConfig>(scimSecretKey(workspaceId));
return { ...defaultScimConfig(), ...(stored ?? {}) };
}
-export async function getScimSettings(workspaceId: number): Promise<WorkspaceScimDto> {
+export async function getScimSettings(workspaceId: number | null): Promise<ScimSettingsDto> {
return toScimDto(await getScimConfig(workspaceId));
}
export async function setScimSettings(
- workspaceId: number,
+ workspaceId: number | null,
patch: { enabled?: boolean },
-): Promise<WorkspaceScimDto> {
+): Promise<ScimSettingsDto> {
const current = await getScimConfig(workspaceId);
- const next: WorkspaceScimConfig = { ...current, enabled: patch.enabled ?? current.enabled };
+ const next: ScimConfig = { ...current, enabled: patch.enabled ?? current.enabled };
const redacted = toScimDto(next);
await writeSecret(scimSecretKey(workspaceId), next, redacted);
return redacted;
@@ -594,29 +575,36 @@ export async function setScimSettings(
// Mints a token, replacing any previous one, and returns it in the clear. This is
// the only time the value leaves the server.
-export async function rotateScimToken(workspaceId: number): Promise<string> {
+export async function rotateScimToken(workspaceId: number | null): Promise<string> {
const current = await getScimConfig(workspaceId);
- const token = `${SCIM_TOKEN_PREFIX}${workspaceId}_${randomBytes(24).toString('hex')}`;
- const next: WorkspaceScimConfig = { ...current, token };
+ const scope = workspaceId === null ? '' : `${workspaceId}_`;
+ const token = `${SCIM_TOKEN_PREFIX}${scope}${randomBytes(24).toString('hex')}`;
+ const next: ScimConfig = { ...current, token };
await writeSecret(scimSecretKey(workspaceId), next, toScimDto(next));
return token;
}
-// The workspace a token opens, or null when it opens none: provisioning is off, no
-// token was generated, the token is wrong, or it is another workspace's while SCIM is
-// the instance's. The comparison is constant-time, so a
-// wrong token cannot be recovered by timing the answer. Lengths are compared first
-// because timingSafeEqual rejects buffers of different sizes.
-export async function verifyScimToken(candidate: string): Promise<number | null> {
- const named = candidate.match(SCIM_TOKEN_WORKSPACE)?.[1];
- const instanceId = await instanceWorkspaceId(db);
- const workspaceId = named ? Number(named) : instanceId;
- if (!scimPerWorkspace && workspaceId !== instanceId) return null;
+// The comparison is constant-time, so a wrong token cannot be recovered by timing the
+// answer. Lengths are compared first because timingSafeEqual rejects buffers of
+// different sizes.
+async function tokenOpens(workspaceId: number | null, candidate: string): Promise<boolean> {
const config = await getScimConfig(workspaceId);
- if (!config.enabled || config.token.length === 0) return null;
+ if (!config.enabled || config.token.length === 0) return false;
const expected = Buffer.from(config.token);
const given = Buffer.from(candidate);
- return expected.length === given.length && timingSafeEqual(expected, given) ? workspaceId : null;
+ return expected.length === given.length && timingSafeEqual(expected, given);
+}
+
+// The provider a token opens: the instance's (workspaceId null) or a workspace's, or
+// null when it opens none.
+export async function verifyScimToken(
+ candidate: string,
+): Promise<{ workspaceId: number | null } | null> {
+ if (await tokenOpens(null, candidate)) return { workspaceId: null };
+ const named = candidate.match(SCIM_TOKEN_WORKSPACE)?.[1];
+ if (!scimPerWorkspace || !named) return null;
+ const workspaceId = Number(named);
+ return (await tokenOpens(workspaceId, candidate)) ? { workspaceId } : null;
}
// ── Invites ───────────────────────────────────────────────────────────────────
diff --git a/packages/db/drizzle/0150_workspace_per_owner.sql b/packages/db/drizzle/0150_workspace_per_owner.sql
new file mode 100644
index 00000000..a9542264
--- /dev/null
+++ b/packages/db/drizzle/0150_workspace_per_owner.sql
@@ -0,0 +1,49 @@
+ALTER TABLE "scim_user" DROP CONSTRAINT "scim_user_workspace_id_user_id_pk";--> statement-breakpoint
+ALTER TABLE "scim_group" ALTER COLUMN "workspace_id" DROP NOT NULL;--> statement-breakpoint
+ALTER TABLE "scim_user" ALTER COLUMN "workspace_id" DROP NOT NULL;--> statement-breakpoint
+CREATE UNIQUE INDEX "scim_group_instance_display_name_uq" ON "scim_group" USING btree ("display_name") WHERE "scim_group"."workspace_id" IS NULL;--> statement-breakpoint
+CREATE UNIQUE INDEX "scim_user_instance_user_uq" ON "scim_user" USING btree ("user_id") WHERE "scim_user"."workspace_id" IS NULL;--> statement-breakpoint
+ALTER TABLE "scim_user" ADD CONSTRAINT "scim_user_workspace_id_user_id_unique" UNIQUE("workspace_id","user_id");--> statement-breakpoint
+-- The instance's SCIM provider is set up in god mode and belongs to no workspace. Until now it was the first workspace's.
+UPDATE "scim_user" SET "workspace_id" = NULL WHERE "workspace_id" = (SELECT min("id") FROM "workspace");--> statement-breakpoint
+UPDATE "scim_group" SET "workspace_id" = NULL WHERE "workspace_id" = (SELECT min("id") FROM "workspace");--> statement-breakpoint
+UPDATE "app_secret" SET "key" = 'auth.scim' WHERE "key" = 'workspace.' || (SELECT min("id") FROM "workspace") || '.scim';--> statement-breakpoint
+-- The first workspace held every team. Each one goes to the workspace of its first owner, and the first workspace stays its owner's.
+-- An owner with no workspace gets one named after them. The first workspace's owner and admins do not follow a team out: the owner
+-- of its new workspace decides who manages it. Its model prices do, so the team's agent costs read as before.
+DO $$
+DECLARE
+ shared integer := (SELECT min("id") FROM "workspace");
+ moving record;
+ target integer;
+BEGIN
+ FOR moving IN
+ SELECT DISTINCT ON (tm."team_id") tm."team_id", tm."user_id", u."name", u."email"
+ FROM "team_member" tm
+ JOIN "team" t ON t."id" = tm."team_id"
+ JOIN "user" u ON u."id" = tm."user_id"
+ WHERE t."workspace_id" = shared AND tm."role" = 'owner'
+ ORDER BY tm."team_id", tm."created_at", tm."user_id"
+ LOOP
+ SELECT "workspace_id" INTO target FROM "workspace_manager"
+ WHERE "user_id" = moving."user_id" AND "role" = 'owner'
+ ORDER BY "workspace_id" LIMIT 1;
+ CONTINUE WHEN target = shared;
+ IF target IS NULL THEN
+ INSERT INTO "workspace" ("name")
+ VALUES (left(coalesce(nullif(trim(moving."name"), ''), split_part(moving."email", '@', 1)), 60))
+ RETURNING "id" INTO target;
+ INSERT INTO "workspace_manager" ("workspace_id", "user_id", "role")
+ VALUES (target, moving."user_id", 'owner');
+ END IF;
+ INSERT INTO "model_price" ("workspace_id", "provider", "model", "input", "output", "cache_read", "cache_write")
+ SELECT target, "provider", "model", "input", "output", "cache_read", "cache_write" FROM "model_price"
+ WHERE "workspace_id" = shared
+ ON CONFLICT DO NOTHING;
+ UPDATE "team" SET "workspace_id" = target WHERE "id" = moving."team_id";
+ END LOOP;
+END $$;--> statement-breakpoint
+-- On a database with no account yet the first workspace has no owner and no team.
+DELETE FROM "workspace" w
+WHERE NOT EXISTS (SELECT 1 FROM "workspace_manager" wm WHERE wm."workspace_id" = w."id" AND wm."role" = 'owner')
+ AND NOT EXISTS (SELECT 1 FROM "team" t WHERE t."workspace_id" = w."id");
diff --git a/packages/db/drizzle/meta/0150_snapshot.json b/packages/db/drizzle/meta/0150_snapshot.json
new file mode 100644
index 00000000..747dd90a
--- /dev/null
+++ b/packages/db/drizzle/meta/0150_snapshot.json
@@ -0,0 +1,12379 @@
+{
+ "id": "2e4b7f25-0a5a-4548-bd8a-cb97fce4b45d",
+ "prevId": "4cd74f3e-e253-459d-8de4-c74dba487814",
+ "version": "7",
+ "dialect": "postgresql",
+ "tables": {
+ "public.account": {
+ "name": "account",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "account_id": {
+ "name": "account_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "access_token": {
+ "name": "access_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refresh_token": {
+ "name": "refresh_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "id_token": {
+ "name": "id_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "access_token_expires_at": {
+ "name": "access_token_expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refresh_token_expires_at": {
+ "name": "refresh_token_expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "account_userId_idx": {
+ "name": "account_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "account_user_id_user_id_fk": {
+ "name": "account_user_id_user_id_fk",
+ "tableFrom": "account",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.apikey": {
+ "name": "apikey",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "config_id": {
+ "name": "config_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'default'"
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "start": {
+ "name": "start",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "reference_id": {
+ "name": "reference_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "prefix": {
+ "name": "prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "refill_interval": {
+ "name": "refill_interval",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refill_amount": {
+ "name": "refill_amount",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "last_refill_at": {
+ "name": "last_refill_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ },
+ "rate_limit_enabled": {
+ "name": "rate_limit_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ },
+ "rate_limit_time_window": {
+ "name": "rate_limit_time_window",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 1000
+ },
+ "rate_limit_max": {
+ "name": "rate_limit_max",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 100
+ },
+ "request_count": {
+ "name": "request_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 0
+ },
+ "remaining": {
+ "name": "remaining",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "last_request": {
+ "name": "last_request",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "permissions": {
+ "name": "permissions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "apikey_configId_idx": {
+ "name": "apikey_configId_idx",
+ "columns": [
+ {
+ "expression": "config_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "apikey_referenceId_idx": {
+ "name": "apikey_referenceId_idx",
+ "columns": [
+ {
+ "expression": "reference_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "apikey_key_idx": {
+ "name": "apikey_key_idx",
+ "columns": [
+ {
+ "expression": "key",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.jwks": {
+ "name": "jwks",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "public_key": {
+ "name": "public_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "private_key": {
+ "name": "private_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "alg": {
+ "name": "alg",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "crv": {
+ "name": "crv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_access_token": {
+ "name": "oauth_access_token",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "reference_id": {
+ "name": "reference_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "authorization_code_id": {
+ "name": "authorization_code_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "resources": {
+ "name": "resources",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "requested_user_info_claims": {
+ "name": "requested_user_info_claims",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refresh_id": {
+ "name": "refresh_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "revoked": {
+ "name": "revoked",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "confirmation": {
+ "name": "confirmation",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scopes": {
+ "name": "scopes",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "oauthAccessToken_clientId_idx": {
+ "name": "oauthAccessToken_clientId_idx",
+ "columns": [
+ {
+ "expression": "client_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthAccessToken_sessionId_idx": {
+ "name": "oauthAccessToken_sessionId_idx",
+ "columns": [
+ {
+ "expression": "session_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthAccessToken_userId_idx": {
+ "name": "oauthAccessToken_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthAccessToken_authorizationCodeId_idx": {
+ "name": "oauthAccessToken_authorizationCodeId_idx",
+ "columns": [
+ {
+ "expression": "authorization_code_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthAccessToken_refreshId_idx": {
+ "name": "oauthAccessToken_refreshId_idx",
+ "columns": [
+ {
+ "expression": "refresh_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "oauth_access_token_client_id_oauth_client_client_id_fk": {
+ "name": "oauth_access_token_client_id_oauth_client_client_id_fk",
+ "tableFrom": "oauth_access_token",
+ "tableTo": "oauth_client",
+ "columnsFrom": [
+ "client_id"
+ ],
+ "columnsTo": [
+ "client_id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "oauth_access_token_session_id_session_id_fk": {
+ "name": "oauth_access_token_session_id_session_id_fk",
+ "tableFrom": "oauth_access_token",
+ "tableTo": "session",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "oauth_access_token_user_id_user_id_fk": {
+ "name": "oauth_access_token_user_id_user_id_fk",
+ "tableFrom": "oauth_access_token",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "oauth_access_token_refresh_id_oauth_refresh_token_id_fk": {
+ "name": "oauth_access_token_refresh_id_oauth_refresh_token_id_fk",
+ "tableFrom": "oauth_access_token",
+ "tableTo": "oauth_refresh_token",
+ "columnsFrom": [
+ "refresh_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "oauth_access_token_token_unique": {
+ "name": "oauth_access_token_token_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "token"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_client": {
+ "name": "oauth_client",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "client_secret": {
+ "name": "client_secret",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "client_discovery_id": {
+ "name": "client_discovery_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "disabled": {
+ "name": "disabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "skip_consent": {
+ "name": "skip_consent",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "enable_end_session": {
+ "name": "enable_end_session",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "subject_type": {
+ "name": "subject_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scopes": {
+ "name": "scopes",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "client_credentials_scopes": {
+ "name": "client_credentials_scopes",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "'{}'"
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "uri": {
+ "name": "uri",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "contacts": {
+ "name": "contacts",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "tos": {
+ "name": "tos",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "policy": {
+ "name": "policy",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "software_id": {
+ "name": "software_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "software_version": {
+ "name": "software_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "software_statement": {
+ "name": "software_statement",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "redirect_uris": {
+ "name": "redirect_uris",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "post_logout_redirect_uris": {
+ "name": "post_logout_redirect_uris",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "backchannel_logout_uri": {
+ "name": "backchannel_logout_uri",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "backchannel_logout_session_required": {
+ "name": "backchannel_logout_session_required",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "token_endpoint_auth_method": {
+ "name": "token_endpoint_auth_method",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "application_type": {
+ "name": "application_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "jwks": {
+ "name": "jwks",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "jwks_uri": {
+ "name": "jwks_uri",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "grant_types": {
+ "name": "grant_types",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "response_types": {
+ "name": "response_types",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "require_pkce": {
+ "name": "require_pkce",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "dpop_bound_access_tokens": {
+ "name": "dpop_bound_access_tokens",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "reference_id": {
+ "name": "reference_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "oauthClient_userId_idx": {
+ "name": "oauthClient_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "oauth_client_user_id_user_id_fk": {
+ "name": "oauth_client_user_id_user_id_fk",
+ "tableFrom": "oauth_client",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "oauth_client_client_id_unique": {
+ "name": "oauth_client_client_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "client_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_client_assertion": {
+ "name": "oauth_client_assertion",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_client_resource": {
+ "name": "oauth_client_resource",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "resource_id": {
+ "name": "resource_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "oauthClientResource_clientId_resourceId_uidx": {
+ "name": "oauthClientResource_clientId_resourceId_uidx",
+ "columns": [
+ {
+ "expression": "client_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "resource_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthClientResource_clientId_idx": {
+ "name": "oauthClientResource_clientId_idx",
+ "columns": [
+ {
+ "expression": "client_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthClientResource_resourceId_idx": {
+ "name": "oauthClientResource_resourceId_idx",
+ "columns": [
+ {
+ "expression": "resource_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "oauth_client_resource_client_id_oauth_client_client_id_fk": {
+ "name": "oauth_client_resource_client_id_oauth_client_client_id_fk",
+ "tableFrom": "oauth_client_resource",
+ "tableTo": "oauth_client",
+ "columnsFrom": [
+ "client_id"
+ ],
+ "columnsTo": [
+ "client_id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "oauth_client_resource_resource_id_oauth_resource_identifier_fk": {
+ "name": "oauth_client_resource_resource_id_oauth_resource_identifier_fk",
+ "tableFrom": "oauth_client_resource",
+ "tableTo": "oauth_resource",
+ "columnsFrom": [
+ "resource_id"
+ ],
+ "columnsTo": [
+ "identifier"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_consent": {
+ "name": "oauth_consent",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "reference_id": {
+ "name": "reference_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "resources": {
+ "name": "resources",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "requested_user_info_claims": {
+ "name": "requested_user_info_claims",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scopes": {
+ "name": "scopes",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "oauthConsent_clientId_idx": {
+ "name": "oauthConsent_clientId_idx",
+ "columns": [
+ {
+ "expression": "client_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthConsent_userId_idx": {
+ "name": "oauthConsent_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "oauth_consent_client_id_oauth_client_client_id_fk": {
+ "name": "oauth_consent_client_id_oauth_client_client_id_fk",
+ "tableFrom": "oauth_consent",
+ "tableTo": "oauth_client",
+ "columnsFrom": [
+ "client_id"
+ ],
+ "columnsTo": [
+ "client_id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "oauth_consent_user_id_user_id_fk": {
+ "name": "oauth_consent_user_id_user_id_fk",
+ "tableFrom": "oauth_consent",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_refresh_token": {
+ "name": "oauth_refresh_token",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "reference_id": {
+ "name": "reference_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "authorization_code_id": {
+ "name": "authorization_code_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "resources": {
+ "name": "resources",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "requested_user_info_claims": {
+ "name": "requested_user_info_claims",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "revoked": {
+ "name": "revoked",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "rotated_at": {
+ "name": "rotated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "rotation_replay_response": {
+ "name": "rotation_replay_response",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "rotation_replay_expires_at": {
+ "name": "rotation_replay_expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "auth_time": {
+ "name": "auth_time",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "confirmation": {
+ "name": "confirmation",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scopes": {
+ "name": "scopes",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "oauthRefreshToken_clientId_idx": {
+ "name": "oauthRefreshToken_clientId_idx",
+ "columns": [
+ {
+ "expression": "client_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthRefreshToken_sessionId_idx": {
+ "name": "oauthRefreshToken_sessionId_idx",
+ "columns": [
+ {
+ "expression": "session_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthRefreshToken_userId_idx": {
+ "name": "oauthRefreshToken_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "oauthRefreshToken_authorizationCodeId_idx": {
+ "name": "oauthRefreshToken_authorizationCodeId_idx",
+ "columns": [
+ {
+ "expression": "authorization_code_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "oauth_refresh_token_client_id_oauth_client_client_id_fk": {
+ "name": "oauth_refresh_token_client_id_oauth_client_client_id_fk",
+ "tableFrom": "oauth_refresh_token",
+ "tableTo": "oauth_client",
+ "columnsFrom": [
+ "client_id"
+ ],
+ "columnsTo": [
+ "client_id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "oauth_refresh_token_session_id_session_id_fk": {
+ "name": "oauth_refresh_token_session_id_session_id_fk",
+ "tableFrom": "oauth_refresh_token",
+ "tableTo": "session",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "oauth_refresh_token_user_id_user_id_fk": {
+ "name": "oauth_refresh_token_user_id_user_id_fk",
+ "tableFrom": "oauth_refresh_token",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "oauth_refresh_token_token_unique": {
+ "name": "oauth_refresh_token_token_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "token"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.oauth_resource": {
+ "name": "oauth_resource",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "access_token_ttl": {
+ "name": "access_token_ttl",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refresh_token_ttl": {
+ "name": "refresh_token_ttl",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "signing_algorithm": {
+ "name": "signing_algorithm",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "signing_key_id": {
+ "name": "signing_key_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "allowed_scopes": {
+ "name": "allowed_scopes",
+ "type": "text[]",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "custom_claims": {
+ "name": "custom_claims",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "dpop_bound_access_tokens_required": {
+ "name": "dpop_bound_access_tokens_required",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "disabled": {
+ "name": "disabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "policy_version": {
+ "name": "policy_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 1
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "oauth_resource_identifier_unique": {
+ "name": "oauth_resource_identifier_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "identifier"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.passkey": {
+ "name": "passkey",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "public_key": {
+ "name": "public_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "credential_id": {
+ "name": "credential_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "counter": {
+ "name": "counter",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "device_type": {
+ "name": "device_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "backed_up": {
+ "name": "backed_up",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "transports": {
+ "name": "transports",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "aaguid": {
+ "name": "aaguid",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "passkey_userId_idx": {
+ "name": "passkey_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "passkey_credentialID_idx": {
+ "name": "passkey_credentialID_idx",
+ "columns": [
+ {
+ "expression": "credential_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "passkey_user_id_user_id_fk": {
+ "name": "passkey_user_id_user_id_fk",
+ "tableFrom": "passkey",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.session": {
+ "name": "session",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "ip_address": {
+ "name": "ip_address",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_agent": {
+ "name": "user_agent",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "session_userId_idx": {
+ "name": "session_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "session_user_id_user_id_fk": {
+ "name": "session_user_id_user_id_fk",
+ "tableFrom": "session",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "session_token_unique": {
+ "name": "session_token_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "token"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.user": {
+ "name": "user",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email_verified": {
+ "name": "email_verified",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "image": {
+ "name": "image",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "display_username": {
+ "name": "display_username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "'user'"
+ },
+ "active": {
+ "name": "active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "user_email_unique": {
+ "name": "user_email_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "email"
+ ]
+ },
+ "user_username_unique": {
+ "name": "user_username_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "username"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.verification": {
+ "name": "verification",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "verification_identifier_idx": {
+ "name": "verification_identifier_idx",
+ "columns": [
+ {
+ "expression": "identifier",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_chat_event": {
+ "name": "agent_chat_event",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "bigserial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "payload": {
+ "name": "payload",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_chat_event_message_idx": {
+ "name": "agent_chat_event_message_idx",
+ "columns": [
+ {
+ "expression": "message_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_chat_event_message_id_agent_chat_message_id_fk": {
+ "name": "agent_chat_event_message_id_agent_chat_message_id_fk",
+ "tableFrom": "agent_chat_event",
+ "tableTo": "agent_chat_message",
+ "columnsFrom": [
+ "message_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_chat_favorite": {
+ "name": "agent_chat_favorite",
+ "schema": "",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "agent_chat_favorite_user_id_user_id_fk": {
+ "name": "agent_chat_favorite_user_id_user_id_fk",
+ "tableFrom": "agent_chat_favorite",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_chat_favorite_agent_id_ai_agent_id_fk": {
+ "name": "agent_chat_favorite_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_chat_favorite",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "agent_chat_favorite_user_id_thread_id_pk": {
+ "name": "agent_chat_favorite_user_id_thread_id_pk",
+ "columns": [
+ "user_id",
+ "thread_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_chat_message": {
+ "name": "agent_chat_message",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "next_attempt_at": {
+ "name": "next_attempt_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "finished_at": {
+ "name": "finished_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_chat_message_thread_idx": {
+ "name": "agent_chat_message_thread_idx",
+ "columns": [
+ {
+ "expression": "thread_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_chat_message_due_idx": {
+ "name": "agent_chat_message_due_idx",
+ "columns": [
+ {
+ "expression": "agent_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "next_attempt_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"agent_chat_message\".\"status\" IN ('pending', 'streaming')",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_chat_message_thread_id_agent_chat_thread_id_fk": {
+ "name": "agent_chat_message_thread_id_agent_chat_thread_id_fk",
+ "tableFrom": "agent_chat_message",
+ "tableTo": "agent_chat_thread",
+ "columnsFrom": [
+ "thread_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_chat_message_agent_id_ai_agent_id_fk": {
+ "name": "agent_chat_message_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_chat_message",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "agent_chat_message_role_check": {
+ "name": "agent_chat_message_role_check",
+ "value": "\"agent_chat_message\".\"role\" IN ('user', 'assistant')"
+ },
+ "agent_chat_message_status_check": {
+ "name": "agent_chat_message_status_check",
+ "value": "\"agent_chat_message\".\"status\" IN ('pending', 'streaming', 'success', 'failed', 'canceled')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.agent_chat_thread": {
+ "name": "agent_chat_thread",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "cli_session_id": {
+ "name": "cli_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_chat_thread_agent_user_idx": {
+ "name": "agent_chat_thread_agent_user_idx",
+ "columns": [
+ {
+ "expression": "agent_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "updated_at",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_chat_thread_agent_id_ai_agent_id_fk": {
+ "name": "agent_chat_thread_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_chat_thread",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_chat_thread_user_id_user_id_fk": {
+ "name": "agent_chat_thread_user_id_user_id_fk",
+ "tableFrom": "agent_chat_thread",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_chat_usage": {
+ "name": "agent_chat_usage",
+ "schema": "",
+ "columns": {
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "input_tokens": {
+ "name": "input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "output_tokens": {
+ "name": "output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_chat_usage_agent_idx": {
+ "name": "agent_chat_usage_agent_idx",
+ "columns": [
+ {
+ "expression": "agent_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_chat_usage_agent_id_ai_agent_id_fk": {
+ "name": "agent_chat_usage_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_chat_usage",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_field_trigger": {
+ "name": "agent_field_trigger",
+ "schema": "",
+ "columns": {
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "field_id": {
+ "name": "field_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "delay_sec": {
+ "name": "delay_sec",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 120
+ }
+ },
+ "indexes": {
+ "agent_field_trigger_field_idx": {
+ "name": "agent_field_trigger_field_idx",
+ "columns": [
+ {
+ "expression": "field_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_field_trigger_agent_id_ai_agent_id_fk": {
+ "name": "agent_field_trigger_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_field_trigger",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_field_trigger_field_id_custom_field_id_fk": {
+ "name": "agent_field_trigger_field_id_custom_field_id_fk",
+ "tableFrom": "agent_field_trigger",
+ "tableTo": "custom_field",
+ "columnsFrom": [
+ "field_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "agent_field_trigger_agent_id_field_id_pk": {
+ "name": "agent_field_trigger_agent_id_field_id_pk",
+ "columns": [
+ "agent_id",
+ "field_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "agent_field_trigger_delay_check": {
+ "name": "agent_field_trigger_delay_check",
+ "value": "\"agent_field_trigger\".\"delay_sec\" >= 0 AND \"agent_field_trigger\".\"delay_sec\" <= 86400"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.agent_run": {
+ "name": "agent_run",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "schedule_id": {
+ "name": "schedule_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "trigger": {
+ "name": "trigger",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'delegation'"
+ },
+ "scheduled_for": {
+ "name": "scheduled_for",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "source_activity_id": {
+ "name": "source_activity_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "prompt": {
+ "name": "prompt",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "next_attempt_at": {
+ "name": "next_attempt_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "output": {
+ "name": "output",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "input_tokens": {
+ "name": "input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "output_tokens": {
+ "name": "output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "finished_at": {
+ "name": "finished_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_run_schedule_fire_uq": {
+ "name": "agent_run_schedule_fire_uq",
+ "columns": [
+ {
+ "expression": "schedule_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "scheduled_for",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_run_due_idx": {
+ "name": "agent_run_due_idx",
+ "columns": [
+ {
+ "expression": "status",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "next_attempt_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_run_schedule_idx": {
+ "name": "agent_run_schedule_idx",
+ "columns": [
+ {
+ "expression": "schedule_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_run_project_idx": {
+ "name": "agent_run_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_run_agent_id_ai_agent_id_fk": {
+ "name": "agent_run_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_run",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_run_project_id_project_id_fk": {
+ "name": "agent_run_project_id_project_id_fk",
+ "tableFrom": "agent_run",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_run_issue_id_issue_id_fk": {
+ "name": "agent_run_issue_id_issue_id_fk",
+ "tableFrom": "agent_run",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_run_schedule_id_agent_schedule_id_fk": {
+ "name": "agent_run_schedule_id_agent_schedule_id_fk",
+ "tableFrom": "agent_run",
+ "tableTo": "agent_schedule",
+ "columnsFrom": [
+ "schedule_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_run_source_activity_id_issue_activity_id_fk": {
+ "name": "agent_run_source_activity_id_issue_activity_id_fk",
+ "tableFrom": "agent_run",
+ "tableTo": "issue_activity",
+ "columnsFrom": [
+ "source_activity_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "agent_run_status_check": {
+ "name": "agent_run_status_check",
+ "value": "\"agent_run\".\"status\" IN ('pending', 'success', 'failed', 'canceled')"
+ },
+ "agent_run_trigger_check": {
+ "name": "agent_run_trigger_check",
+ "value": "\"agent_run\".\"trigger\" IN ('mention', 'delegation', 'field', 'schedule', 'manual', 'status', 'event')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.agent_schedule": {
+ "name": "agent_schedule",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "prompt": {
+ "name": "prompt",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'cron'"
+ },
+ "cron": {
+ "name": "cron",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "timezone": {
+ "name": "timezone",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'active'"
+ },
+ "next_run_at": {
+ "name": "next_run_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "column_id": {
+ "name": "column_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "delay_sec": {
+ "name": "delay_sec",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "options": {
+ "name": "options",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "last_run_at": {
+ "name": "last_run_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_schedule_due_idx": {
+ "name": "agent_schedule_due_idx",
+ "columns": [
+ {
+ "expression": "status",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "next_run_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_schedule_agent_idx": {
+ "name": "agent_schedule_agent_idx",
+ "columns": [
+ {
+ "expression": "agent_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_schedule_project_idx": {
+ "name": "agent_schedule_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_schedule_column_idx": {
+ "name": "agent_schedule_column_idx",
+ "columns": [
+ {
+ "expression": "column_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_schedule_agent_id_ai_agent_id_fk": {
+ "name": "agent_schedule_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_schedule",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_schedule_project_id_project_id_fk": {
+ "name": "agent_schedule_project_id_project_id_fk",
+ "tableFrom": "agent_schedule",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_schedule_column_id_project_column_id_fk": {
+ "name": "agent_schedule_column_id_project_column_id_fk",
+ "tableFrom": "agent_schedule",
+ "tableTo": "project_column",
+ "columnsFrom": [
+ "column_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "agent_schedule_project_id_agent_id_name_unique": {
+ "name": "agent_schedule_project_id_agent_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "agent_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "agent_schedule_status_check": {
+ "name": "agent_schedule_status_check",
+ "value": "\"agent_schedule\".\"status\" IN ('active', 'paused')"
+ },
+ "agent_schedule_type_check": {
+ "name": "agent_schedule_type_check",
+ "value": "(\"agent_schedule\".\"type\" = 'cron' AND \"agent_schedule\".\"cron\" IS NOT NULL AND \"agent_schedule\".\"next_run_at\" IS NOT NULL AND \"agent_schedule\".\"column_id\" IS NULL)\n OR (\"agent_schedule\".\"type\" = 'status' AND \"agent_schedule\".\"column_id\" IS NOT NULL AND \"agent_schedule\".\"cron\" IS NULL AND \"agent_schedule\".\"next_run_at\" IS NULL)\n OR (\"agent_schedule\".\"type\" NOT IN ('cron', 'status') AND \"agent_schedule\".\"cron\" IS NULL AND \"agent_schedule\".\"next_run_at\" IS NULL AND \"agent_schedule\".\"column_id\" IS NULL)"
+ },
+ "agent_schedule_delay_check": {
+ "name": "agent_schedule_delay_check",
+ "value": "\"agent_schedule\".\"delay_sec\" >= 0 AND \"agent_schedule\".\"delay_sec\" <= 86400"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.agent_skill": {
+ "name": "agent_skill",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "source_url": {
+ "name": "source_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "s3_prefix": {
+ "name": "s3_prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "files": {
+ "name": "files",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'[]'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_skill_team_idx": {
+ "name": "agent_skill_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_skill_team_id_team_id_fk": {
+ "name": "agent_skill_team_id_team_id_fk",
+ "tableFrom": "agent_skill",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "agent_skill_team_id_name_unique": {
+ "name": "agent_skill_team_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "team_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "agent_skill_source_check": {
+ "name": "agent_skill_source_check",
+ "value": "\"agent_skill\".\"source\" IN ('upload', 'inline', 'github')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.agent_skill_link": {
+ "name": "agent_skill_link",
+ "schema": "",
+ "columns": {
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "skill_id": {
+ "name": "skill_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "agent_skill_link_skill_idx": {
+ "name": "agent_skill_link_skill_idx",
+ "columns": [
+ {
+ "expression": "skill_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_skill_link_agent_id_ai_agent_id_fk": {
+ "name": "agent_skill_link_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_skill_link",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_skill_link_skill_id_agent_skill_id_fk": {
+ "name": "agent_skill_link_skill_id_agent_skill_id_fk",
+ "tableFrom": "agent_skill_link",
+ "tableTo": "agent_skill",
+ "columnsFrom": [
+ "skill_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "agent_skill_link_agent_id_skill_id_pk": {
+ "name": "agent_skill_link_agent_id_skill_id_pk",
+ "columns": [
+ "agent_id",
+ "skill_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_tool": {
+ "name": "agent_tool",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "tool_key": {
+ "name": "tool_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "credential_id": {
+ "name": "credential_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "agent_tool_team_idx": {
+ "name": "agent_tool_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "agent_tool_credential_idx": {
+ "name": "agent_tool_credential_idx",
+ "columns": [
+ {
+ "expression": "credential_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_tool_team_id_team_id_fk": {
+ "name": "agent_tool_team_id_team_id_fk",
+ "tableFrom": "agent_tool",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_tool_credential_id_integration_credential_id_fk": {
+ "name": "agent_tool_credential_id_integration_credential_id_fk",
+ "tableFrom": "agent_tool",
+ "tableTo": "integration_credential",
+ "columnsFrom": [
+ "credential_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "agent_tool_team_id_tool_key_credential_id_unique": {
+ "name": "agent_tool_team_id_tool_key_credential_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "team_id",
+ "tool_key",
+ "credential_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.agent_tool_link": {
+ "name": "agent_tool_link",
+ "schema": "",
+ "columns": {
+ "agent_id": {
+ "name": "agent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "agent_tool_id": {
+ "name": "agent_tool_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "agent_tool_link_tool_idx": {
+ "name": "agent_tool_link_tool_idx",
+ "columns": [
+ {
+ "expression": "agent_tool_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "agent_tool_link_agent_id_ai_agent_id_fk": {
+ "name": "agent_tool_link_agent_id_ai_agent_id_fk",
+ "tableFrom": "agent_tool_link",
+ "tableTo": "ai_agent",
+ "columnsFrom": [
+ "agent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "agent_tool_link_agent_tool_id_agent_tool_id_fk": {
+ "name": "agent_tool_link_agent_tool_id_agent_tool_id_fk",
+ "tableFrom": "agent_tool_link",
+ "tableTo": "agent_tool",
+ "columnsFrom": [
+ "agent_tool_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "agent_tool_link_agent_id_agent_tool_id_pk": {
+ "name": "agent_tool_link_agent_id_agent_tool_id_pk",
+ "columns": [
+ "agent_id",
+ "agent_tool_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.ai_agent": {
+ "name": "ai_agent",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "model_credential_id": {
+ "name": "model_credential_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "instructions": {
+ "name": "instructions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "tools": {
+ "name": "tools",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'[]'::jsonb"
+ },
+ "temperature": {
+ "name": "temperature",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "reasoning_effort": {
+ "name": "reasoning_effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "max_steps": {
+ "name": "max_steps",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "trigger_on_mention": {
+ "name": "trigger_on_mention",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "trigger_on_assign": {
+ "name": "trigger_on_assign",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "delegation_delay_sec": {
+ "name": "delegation_delay_sec",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 120
+ },
+ "api_key_ciphertext": {
+ "name": "api_key_ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "api_key_iv": {
+ "name": "api_key_iv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "api_key_auth_tag": {
+ "name": "api_key_auth_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "memory_enabled": {
+ "name": "memory_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "memory_last_messages": {
+ "name": "memory_last_messages",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "owner_user_id": {
+ "name": "owner_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "runner_scope": {
+ "name": "runner_scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'team'"
+ },
+ "last_seen_at": {
+ "name": "last_seen_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "ai_agent_team_username_uq": {
+ "name": "ai_agent_team_username_uq",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "lower(\"username\")",
+ "asc": true,
+ "isExpression": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "ai_agent_team_idx": {
+ "name": "ai_agent_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "ai_agent_team_id_team_id_fk": {
+ "name": "ai_agent_team_id_team_id_fk",
+ "tableFrom": "ai_agent",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "ai_agent_user_id_user_id_fk": {
+ "name": "ai_agent_user_id_user_id_fk",
+ "tableFrom": "ai_agent",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "ai_agent_model_credential_id_integration_credential_id_fk": {
+ "name": "ai_agent_model_credential_id_integration_credential_id_fk",
+ "tableFrom": "ai_agent",
+ "tableTo": "integration_credential",
+ "columnsFrom": [
+ "model_credential_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "ai_agent_owner_user_id_user_id_fk": {
+ "name": "ai_agent_owner_user_id_user_id_fk",
+ "tableFrom": "ai_agent",
+ "tableTo": "user",
+ "columnsFrom": [
+ "owner_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "ai_agent_user_id_unique": {
+ "name": "ai_agent_user_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "user_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "ai_agent_kind_check": {
+ "name": "ai_agent_kind_check",
+ "value": "\"ai_agent\".\"kind\" IN ('external', 'internal')"
+ },
+ "ai_agent_runner_scope_check": {
+ "name": "ai_agent_runner_scope_check",
+ "value": "\"ai_agent\".\"runner_scope\" IN ('owner', 'team')"
+ },
+ "ai_agent_reasoning_effort_check": {
+ "name": "ai_agent_reasoning_effort_check",
+ "value": "\"ai_agent\".\"reasoning_effort\" IN ('low', 'medium', 'high')"
+ },
+ "ai_agent_delegation_delay_check": {
+ "name": "ai_agent_delegation_delay_check",
+ "value": "\"ai_agent\".\"delegation_delay_sec\" >= 0 AND \"ai_agent\".\"delegation_delay_sec\" <= 86400"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.app_secret": {
+ "name": "app_secret",
+ "schema": "",
+ "columns": {
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "ciphertext": {
+ "name": "ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "iv": {
+ "name": "iv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "auth_tag": {
+ "name": "auth_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "redacted": {
+ "name": "redacted",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.app_setting": {
+ "name": "app_setting",
+ "schema": "",
+ "columns": {
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "value": {
+ "name": "value",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.chat_attachment": {
+ "name": "chat_attachment",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "public_id": {
+ "name": "public_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "uploaded_by_user_id": {
+ "name": "uploaded_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "s3_key": {
+ "name": "s3_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content_type": {
+ "name": "content_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "size_bytes": {
+ "name": "size_bytes",
+ "type": "bigint",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "chat_attachment_project_idx": {
+ "name": "chat_attachment_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "chat_attachment_project_id_project_id_fk": {
+ "name": "chat_attachment_project_id_project_id_fk",
+ "tableFrom": "chat_attachment",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "chat_attachment_uploaded_by_user_id_user_id_fk": {
+ "name": "chat_attachment_uploaded_by_user_id_user_id_fk",
+ "tableFrom": "chat_attachment",
+ "tableTo": "user",
+ "columnsFrom": [
+ "uploaded_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "chat_attachment_public_id_unique": {
+ "name": "chat_attachment_public_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "public_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.custom_field": {
+ "name": "custom_field",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "issue_type_id": {
+ "name": "issue_type_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "field_type": {
+ "name": "field_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "member_scope": {
+ "name": "member_scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "show_in_body": {
+ "name": "show_in_body",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "custom_field_project_id_project_id_fk": {
+ "name": "custom_field_project_id_project_id_fk",
+ "tableFrom": "custom_field",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "custom_field_issue_type_id_issue_type_id_fk": {
+ "name": "custom_field_issue_type_id_issue_type_id_fk",
+ "tableFrom": "custom_field",
+ "tableTo": "issue_type",
+ "columnsFrom": [
+ "issue_type_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "custom_field_field_type_check": {
+ "name": "custom_field_field_type_check",
+ "value": "\"custom_field\".\"field_type\" IN ('text', 'markdown', 'url', 'number', 'boolean', 'date', 'datetime', 'datetime_range', 'select', 'multi_select', 'member')"
+ },
+ "custom_field_member_scope_check": {
+ "name": "custom_field_member_scope_check",
+ "value": "(\"custom_field\".\"field_type\" = 'member') = (\"custom_field\".\"member_scope\" IS NOT NULL) AND (\"custom_field\".\"member_scope\" IS NULL OR \"custom_field\".\"member_scope\" IN ('all', 'humans', 'agents'))"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.custom_field_option": {
+ "name": "custom_field_option",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "field_id": {
+ "name": "field_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'#6b7280'"
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "custom_field_option_field_id_custom_field_id_fk": {
+ "name": "custom_field_option_field_id_custom_field_id_fk",
+ "tableFrom": "custom_field_option",
+ "tableTo": "custom_field",
+ "columnsFrom": [
+ "field_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "custom_field_option_field_id_value_unique": {
+ "name": "custom_field_option_field_id_value_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "field_id",
+ "value"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.cycle": {
+ "name": "cycle",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "goal": {
+ "name": "goal",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "start_date": {
+ "name": "start_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "end_date": {
+ "name": "end_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "completed_at": {
+ "name": "completed_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "cycle_project_idx": {
+ "name": "cycle_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "start_date",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "cycle_project_id_project_id_fk": {
+ "name": "cycle_project_id_project_id_fk",
+ "tableFrom": "cycle",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "cycle_dates_check": {
+ "name": "cycle_dates_check",
+ "value": "\"cycle\".\"end_date\" >= \"cycle\".\"start_date\""
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.document_asset": {
+ "name": "document_asset",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "public_id": {
+ "name": "public_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "uploaded_by_user_id": {
+ "name": "uploaded_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "s3_key": {
+ "name": "s3_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content_type": {
+ "name": "content_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "size_bytes": {
+ "name": "size_bytes",
+ "type": "bigint",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "document_asset_document_idx": {
+ "name": "document_asset_document_idx",
+ "columns": [
+ {
+ "expression": "document_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "created_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "document_asset_document_id_project_document_id_fk": {
+ "name": "document_asset_document_id_project_document_id_fk",
+ "tableFrom": "document_asset",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "document_asset_uploaded_by_user_id_user_id_fk": {
+ "name": "document_asset_uploaded_by_user_id_user_id_fk",
+ "tableFrom": "document_asset",
+ "tableTo": "user",
+ "columnsFrom": [
+ "uploaded_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "document_asset_public_id_unique": {
+ "name": "document_asset_public_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "public_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.document_collaboration": {
+ "name": "document_collaboration",
+ "schema": "",
+ "columns": {
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "epoch": {
+ "name": "epoch",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "version": {
+ "name": "version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "content_json": {
+ "name": "content_json",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "document_collaboration_document_id_project_document_id_fk": {
+ "name": "document_collaboration_document_id_project_document_id_fk",
+ "tableFrom": "document_collaboration",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.document_comment": {
+ "name": "document_comment",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "parent_id": {
+ "name": "parent_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "author_id": {
+ "name": "author_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "body": {
+ "name": "body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "quote": {
+ "name": "quote",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "selection_from": {
+ "name": "selection_from",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "selection_to": {
+ "name": "selection_to",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "orphaned": {
+ "name": "orphaned",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "resolved_at": {
+ "name": "resolved_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "document_comment_document_idx": {
+ "name": "document_comment_document_idx",
+ "columns": [
+ {
+ "expression": "document_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "created_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "document_comment_document_id_project_document_id_fk": {
+ "name": "document_comment_document_id_project_document_id_fk",
+ "tableFrom": "document_comment",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "document_comment_parent_id_document_comment_id_fk": {
+ "name": "document_comment_parent_id_document_comment_id_fk",
+ "tableFrom": "document_comment",
+ "tableTo": "document_comment",
+ "columnsFrom": [
+ "parent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "document_comment_author_id_user_id_fk": {
+ "name": "document_comment_author_id_user_id_fk",
+ "tableFrom": "document_comment",
+ "tableTo": "user",
+ "columnsFrom": [
+ "author_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.document_step": {
+ "name": "document_step",
+ "schema": "",
+ "columns": {
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "version": {
+ "name": "version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "step": {
+ "name": "step",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "document_step_document_id_project_document_id_fk": {
+ "name": "document_step_document_id_project_document_id_fk",
+ "tableFrom": "document_step",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "document_step_document_id_version_pk": {
+ "name": "document_step_document_id_version_pk",
+ "columns": [
+ "document_id",
+ "version"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.git_managed_repository": {
+ "name": "git_managed_repository",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "connection_id": {
+ "name": "connection_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "full_name": {
+ "name": "full_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "web_url": {
+ "name": "web_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "webhook_external_id": {
+ "name": "webhook_external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'connected'"
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "git_managed_repository_project_connection_idx": {
+ "name": "git_managed_repository_project_connection_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "connection_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "git_managed_repository_project_id_project_id_fk": {
+ "name": "git_managed_repository_project_id_project_id_fk",
+ "tableFrom": "git_managed_repository",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "git_managed_repository_connection_id_git_provider_connection_id_fk": {
+ "name": "git_managed_repository_connection_id_git_provider_connection_id_fk",
+ "tableFrom": "git_managed_repository",
+ "tableTo": "git_provider_connection",
+ "columnsFrom": [
+ "connection_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "git_managed_repository_project_connection_external_unique": {
+ "name": "git_managed_repository_project_connection_external_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "connection_id",
+ "external_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.git_provider_connection": {
+ "name": "git_provider_connection",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "base_url": {
+ "name": "base_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "account_login": {
+ "name": "account_login",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "ciphertext": {
+ "name": "ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "iv": {
+ "name": "iv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "auth_tag": {
+ "name": "auth_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "git_provider_connection_team_idx": {
+ "name": "git_provider_connection_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "git_provider_connection_team_id_team_id_fk": {
+ "name": "git_provider_connection_team_id_team_id_fk",
+ "tableFrom": "git_provider_connection",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.import_job": {
+ "name": "import_job",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "phase": {
+ "name": "phase",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'discover'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "config": {
+ "name": "config",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "cursor": {
+ "name": "cursor",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "credential_ciphertext": {
+ "name": "credential_ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "credential_iv": {
+ "name": "credential_iv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "credential_auth_tag": {
+ "name": "credential_auth_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "next_attempt_at": {
+ "name": "next_attempt_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "import_job_project_idx": {
+ "name": "import_job_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "import_job_due_idx": {
+ "name": "import_job_due_idx",
+ "columns": [
+ {
+ "expression": "next_attempt_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"import_job\".\"status\" = 'pending'",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "import_job_project_id_project_id_fk": {
+ "name": "import_job_project_id_project_id_fk",
+ "tableFrom": "import_job",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "import_job_created_by_user_id_user_id_fk": {
+ "name": "import_job_created_by_user_id_user_id_fk",
+ "tableFrom": "import_job",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "import_job_source_check": {
+ "name": "import_job_source_check",
+ "value": "\"import_job\".\"source\" IN ('plane', 'linear')"
+ },
+ "import_job_phase_check": {
+ "name": "import_job_phase_check",
+ "value": "\"import_job\".\"phase\" IN ('discover', 'create', 'link', 'rewrite', 'attachments', 'done')"
+ },
+ "import_job_status_check": {
+ "name": "import_job_status_check",
+ "value": "\"import_job\".\"status\" IN ('pending', 'running', 'paused', 'completed', 'failed')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.import_record": {
+ "name": "import_record",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "import_job_id": {
+ "name": "import_job_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "source_entity_type": {
+ "name": "source_entity_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "source_id": {
+ "name": "source_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "source_display_id": {
+ "name": "source_display_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "local_entity_type": {
+ "name": "local_entity_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "local_id": {
+ "name": "local_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "import_record_job_source_uq": {
+ "name": "import_record_job_source_uq",
+ "columns": [
+ {
+ "expression": "import_job_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "source_entity_type",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "source_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "import_record_job_local_idx": {
+ "name": "import_record_job_local_idx",
+ "columns": [
+ {
+ "expression": "import_job_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "local_entity_type",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "local_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "import_record_job_display_idx": {
+ "name": "import_record_job_display_idx",
+ "columns": [
+ {
+ "expression": "import_job_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "source_entity_type",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "source_display_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "import_record_import_job_id_import_job_id_fk": {
+ "name": "import_record_import_job_id_import_job_id_fk",
+ "tableFrom": "import_record",
+ "tableTo": "import_job",
+ "columnsFrom": [
+ "import_job_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "import_record_source_entity_type_check": {
+ "name": "import_record_source_entity_type_check",
+ "value": "\"import_record\".\"source_entity_type\" IN ('issue', 'comment', 'label', 'state', 'cycle', 'attachment')"
+ },
+ "import_record_local_entity_type_check": {
+ "name": "import_record_local_entity_type_check",
+ "value": "\"import_record\".\"local_entity_type\" IS NULL OR \"import_record\".\"local_entity_type\" IN ('issue', 'comment', 'label', 'state', 'cycle', 'attachment')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.initiative": {
+ "name": "initiative",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'planned'"
+ },
+ "owner_user_id": {
+ "name": "owner_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "priority": {
+ "name": "priority",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "start_date": {
+ "name": "start_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "target_date": {
+ "name": "target_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "initiative_project_idx": {
+ "name": "initiative_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "initiative_project_id_project_id_fk": {
+ "name": "initiative_project_id_project_id_fk",
+ "tableFrom": "initiative",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "initiative_owner_user_id_user_id_fk": {
+ "name": "initiative_owner_user_id_user_id_fk",
+ "tableFrom": "initiative",
+ "tableTo": "user",
+ "columnsFrom": [
+ "owner_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "initiative_status_check": {
+ "name": "initiative_status_check",
+ "value": "\"initiative\".\"status\" IN ('proposed', 'planned', 'active', 'completed', 'canceled')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.initiative_attachment": {
+ "name": "initiative_attachment",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "public_id": {
+ "name": "public_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "initiative_id": {
+ "name": "initiative_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "s3_key": {
+ "name": "s3_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content_type": {
+ "name": "content_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "size_bytes": {
+ "name": "size_bytes",
+ "type": "bigint",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "initiative_attachment_initiative_idx": {
+ "name": "initiative_attachment_initiative_idx",
+ "columns": [
+ {
+ "expression": "initiative_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "initiative_attachment_initiative_id_initiative_id_fk": {
+ "name": "initiative_attachment_initiative_id_initiative_id_fk",
+ "tableFrom": "initiative_attachment",
+ "tableTo": "initiative",
+ "columnsFrom": [
+ "initiative_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "initiative_attachment_public_id_unique": {
+ "name": "initiative_attachment_public_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "public_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.initiative_label": {
+ "name": "initiative_label",
+ "schema": "",
+ "columns": {
+ "initiative_id": {
+ "name": "initiative_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "label_id": {
+ "name": "label_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "initiative_label_initiative_id_initiative_id_fk": {
+ "name": "initiative_label_initiative_id_initiative_id_fk",
+ "tableFrom": "initiative_label",
+ "tableTo": "initiative",
+ "columnsFrom": [
+ "initiative_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "initiative_label_label_id_label_id_fk": {
+ "name": "initiative_label_label_id_label_id_fk",
+ "tableFrom": "initiative_label",
+ "tableTo": "label",
+ "columnsFrom": [
+ "label_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "initiative_label_initiative_id_label_id_pk": {
+ "name": "initiative_label_initiative_id_label_id_pk",
+ "columns": [
+ "initiative_id",
+ "label_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.integration_credential": {
+ "name": "integration_credential",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "integration_key": {
+ "name": "integration_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "ciphertext": {
+ "name": "ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "iv": {
+ "name": "iv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "auth_tag": {
+ "name": "auth_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "redacted": {
+ "name": "redacted",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "integration_credential_team_idx": {
+ "name": "integration_credential_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "integration_credential_team_id_team_id_fk": {
+ "name": "integration_credential_team_id_team_id_fk",
+ "tableFrom": "integration_credential",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue": {
+ "name": "issue",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "sequence_number": {
+ "name": "sequence_number",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "type_id": {
+ "name": "type_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "initiative_id": {
+ "name": "initiative_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "cycle_id": {
+ "name": "cycle_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "column_id": {
+ "name": "column_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "parent_id": {
+ "name": "parent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "assignee_user_id": {
+ "name": "assignee_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "delegate_user_id": {
+ "name": "delegate_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "priority": {
+ "name": "priority",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "estimate_points": {
+ "name": "estimate_points",
+ "type": "numeric",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "estimate_minutes": {
+ "name": "estimate_minutes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "start_date": {
+ "name": "start_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "due_date": {
+ "name": "due_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "share_token": {
+ "name": "share_token",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "share_extended": {
+ "name": "share_extended",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_project_active_idx": {
+ "name": "issue_project_active_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "column_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"issue\".\"archived_at\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_project_title_idx": {
+ "name": "issue_project_title_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "lower(btrim(\"title\"))",
+ "asc": true,
+ "isExpression": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_parent_idx": {
+ "name": "issue_parent_idx",
+ "columns": [
+ {
+ "expression": "parent_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"issue\".\"parent_id\" IS NOT NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_cycle_idx": {
+ "name": "issue_cycle_idx",
+ "columns": [
+ {
+ "expression": "cycle_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"issue\".\"cycle_id\" IS NOT NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_project_id_project_id_fk": {
+ "name": "issue_project_id_project_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_type_id_issue_type_id_fk": {
+ "name": "issue_type_id_issue_type_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "issue_type",
+ "columnsFrom": [
+ "type_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_initiative_id_initiative_id_fk": {
+ "name": "issue_initiative_id_initiative_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "initiative",
+ "columnsFrom": [
+ "initiative_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_cycle_id_cycle_id_fk": {
+ "name": "issue_cycle_id_cycle_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "cycle",
+ "columnsFrom": [
+ "cycle_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_column_id_project_column_id_fk": {
+ "name": "issue_column_id_project_column_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "project_column",
+ "columnsFrom": [
+ "column_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "issue_parent_id_issue_id_fk": {
+ "name": "issue_parent_id_issue_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "parent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_assignee_user_id_user_id_fk": {
+ "name": "issue_assignee_user_id_user_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "user",
+ "columnsFrom": [
+ "assignee_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_delegate_user_id_user_id_fk": {
+ "name": "issue_delegate_user_id_user_id_fk",
+ "tableFrom": "issue",
+ "tableTo": "user",
+ "columnsFrom": [
+ "delegate_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_share_token_unique": {
+ "name": "issue_share_token_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "share_token"
+ ]
+ },
+ "issue_project_id_sequence_number_unique": {
+ "name": "issue_project_id_sequence_number_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "sequence_number"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "issue_estimate_points_check": {
+ "name": "issue_estimate_points_check",
+ "value": "\"issue\".\"estimate_points\" >= 0"
+ },
+ "issue_estimate_minutes_check": {
+ "name": "issue_estimate_minutes_check",
+ "value": "\"issue\".\"estimate_minutes\" >= 0"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.issue_activity": {
+ "name": "issue_activity",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "initiative_id": {
+ "name": "initiative_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "reply_to_id": {
+ "name": "reply_to_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "actor_user_id": {
+ "name": "actor_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "actor_name": {
+ "name": "actor_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "body": {
+ "name": "body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "action": {
+ "name": "action",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "payload": {
+ "name": "payload",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "edited_at": {
+ "name": "edited_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_activity_issue_idx": {
+ "name": "issue_activity_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "created_at",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_activity_reply_idx": {
+ "name": "issue_activity_reply_idx",
+ "columns": [
+ {
+ "expression": "reply_to_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_activity_initiative_idx": {
+ "name": "issue_activity_initiative_idx",
+ "columns": [
+ {
+ "expression": "initiative_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "created_at",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_activity_issue_id_issue_id_fk": {
+ "name": "issue_activity_issue_id_issue_id_fk",
+ "tableFrom": "issue_activity",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_activity_initiative_id_initiative_id_fk": {
+ "name": "issue_activity_initiative_id_initiative_id_fk",
+ "tableFrom": "issue_activity",
+ "tableTo": "initiative",
+ "columnsFrom": [
+ "initiative_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_activity_reply_to_id_issue_activity_id_fk": {
+ "name": "issue_activity_reply_to_id_issue_activity_id_fk",
+ "tableFrom": "issue_activity",
+ "tableTo": "issue_activity",
+ "columnsFrom": [
+ "reply_to_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_activity_actor_user_id_user_id_fk": {
+ "name": "issue_activity_actor_user_id_user_id_fk",
+ "tableFrom": "issue_activity",
+ "tableTo": "user",
+ "columnsFrom": [
+ "actor_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "issue_activity_kind_check": {
+ "name": "issue_activity_kind_check",
+ "value": "\"issue_activity\".\"kind\" IN ('comment', 'activity')"
+ },
+ "issue_activity_owner_check": {
+ "name": "issue_activity_owner_check",
+ "value": "(\"issue_activity\".\"issue_id\" IS NOT NULL) <> (\"issue_activity\".\"initiative_id\" IS NOT NULL)"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.issue_attachment": {
+ "name": "issue_attachment",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "public_id": {
+ "name": "public_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "s3_key": {
+ "name": "s3_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content_type": {
+ "name": "content_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "size_bytes": {
+ "name": "size_bytes",
+ "type": "bigint",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_attachment_issue_idx": {
+ "name": "issue_attachment_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_attachment_issue_id_issue_id_fk": {
+ "name": "issue_attachment_issue_id_issue_id_fk",
+ "tableFrom": "issue_attachment",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_attachment_public_id_unique": {
+ "name": "issue_attachment_public_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "public_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_checklist": {
+ "name": "issue_checklist",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_checklist_issue_idx": {
+ "name": "issue_checklist_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_checklist_issue_id_issue_id_fk": {
+ "name": "issue_checklist_issue_id_issue_id_fk",
+ "tableFrom": "issue_checklist",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_checklist_item": {
+ "name": "issue_checklist_item",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "checklist_id": {
+ "name": "checklist_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "done": {
+ "name": "done",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_checklist_item_checklist_idx": {
+ "name": "issue_checklist_item_checklist_idx",
+ "columns": [
+ {
+ "expression": "checklist_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_checklist_item_checklist_id_issue_checklist_id_fk": {
+ "name": "issue_checklist_item_checklist_id_issue_checklist_id_fk",
+ "tableFrom": "issue_checklist_item",
+ "tableTo": "issue_checklist",
+ "columnsFrom": [
+ "checklist_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_cycle": {
+ "name": "issue_cycle",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "cycle_id": {
+ "name": "cycle_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "entered_at": {
+ "name": "entered_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "left_at": {
+ "name": "left_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "issue_cycle_issue_idx": {
+ "name": "issue_cycle_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "entered_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_cycle_cycle_idx": {
+ "name": "issue_cycle_cycle_idx",
+ "columns": [
+ {
+ "expression": "cycle_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_cycle_open_idx": {
+ "name": "issue_cycle_open_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "cycle_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"issue_cycle\".\"left_at\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_cycle_issue_id_issue_id_fk": {
+ "name": "issue_cycle_issue_id_issue_id_fk",
+ "tableFrom": "issue_cycle",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_cycle_cycle_id_cycle_id_fk": {
+ "name": "issue_cycle_cycle_id_cycle_id_fk",
+ "tableFrom": "issue_cycle",
+ "tableTo": "cycle",
+ "columnsFrom": [
+ "cycle_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_development_check": {
+ "name": "issue_development_check",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "development_link_id": {
+ "name": "development_link_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "app_id": {
+ "name": "app_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "head_sha": {
+ "name": "head_sha",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_development_check_link_sha_idx": {
+ "name": "issue_development_check_link_sha_idx",
+ "columns": [
+ {
+ "expression": "development_link_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "head_sha",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_development_check_development_link_id_issue_development_link_id_fk": {
+ "name": "issue_development_check_development_link_id_issue_development_link_id_fk",
+ "tableFrom": "issue_development_check",
+ "tableTo": "issue_development_link",
+ "columnsFrom": [
+ "development_link_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_development_check_development_link_id_app_id_name_unique": {
+ "name": "issue_development_check_development_link_id_app_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "development_link_id",
+ "app_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_development_link": {
+ "name": "issue_development_link",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "repository": {
+ "name": "repository",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pull_request'"
+ },
+ "external_key": {
+ "name": "external_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "number": {
+ "name": "number",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "state": {
+ "name": "state",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "draft": {
+ "name": "draft",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "source_branch": {
+ "name": "source_branch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "target_branch": {
+ "name": "target_branch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "head_sha": {
+ "name": "head_sha",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "pipeline_status": {
+ "name": "pipeline_status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "pipeline_url": {
+ "name": "pipeline_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_development_link_issue_idx": {
+ "name": "issue_development_link_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "updated_at",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_development_link_pr_idx": {
+ "name": "issue_development_link_pr_idx",
+ "columns": [
+ {
+ "expression": "provider",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "repository",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "number",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_development_link_sha_idx": {
+ "name": "issue_development_link_sha_idx",
+ "columns": [
+ {
+ "expression": "provider",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "repository",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "head_sha",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_development_link_issue_id_issue_id_fk": {
+ "name": "issue_development_link_issue_id_issue_id_fk",
+ "tableFrom": "issue_development_link",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_development_link_issue_id_provider_repository_external_key_unique": {
+ "name": "issue_development_link_issue_id_provider_repository_external_key_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "issue_id",
+ "provider",
+ "repository",
+ "external_key"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_field_option": {
+ "name": "issue_field_option",
+ "schema": "",
+ "columns": {
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "field_id": {
+ "name": "field_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "option_id": {
+ "name": "option_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_field_option_issue_id_issue_id_fk": {
+ "name": "issue_field_option_issue_id_issue_id_fk",
+ "tableFrom": "issue_field_option",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_field_option_field_id_custom_field_id_fk": {
+ "name": "issue_field_option_field_id_custom_field_id_fk",
+ "tableFrom": "issue_field_option",
+ "tableTo": "custom_field",
+ "columnsFrom": [
+ "field_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_field_option_option_id_custom_field_option_id_fk": {
+ "name": "issue_field_option_option_id_custom_field_option_id_fk",
+ "tableFrom": "issue_field_option",
+ "tableTo": "custom_field_option",
+ "columnsFrom": [
+ "option_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "issue_field_option_issue_id_field_id_option_id_pk": {
+ "name": "issue_field_option_issue_id_field_id_option_id_pk",
+ "columns": [
+ "issue_id",
+ "field_id",
+ "option_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_field_value": {
+ "name": "issue_field_value",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "field_id": {
+ "name": "field_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "value_text": {
+ "name": "value_text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "value_number": {
+ "name": "value_number",
+ "type": "numeric",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "value_bool": {
+ "name": "value_bool",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "value_date": {
+ "name": "value_date",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "value_datetime": {
+ "name": "value_datetime",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "value_datetime_end": {
+ "name": "value_datetime_end",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "value_user_id": {
+ "name": "value_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_field_value_issue_id_issue_id_fk": {
+ "name": "issue_field_value_issue_id_issue_id_fk",
+ "tableFrom": "issue_field_value",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_field_value_field_id_custom_field_id_fk": {
+ "name": "issue_field_value_field_id_custom_field_id_fk",
+ "tableFrom": "issue_field_value",
+ "tableTo": "custom_field",
+ "columnsFrom": [
+ "field_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_field_value_value_user_id_user_id_fk": {
+ "name": "issue_field_value_value_user_id_user_id_fk",
+ "tableFrom": "issue_field_value",
+ "tableTo": "user",
+ "columnsFrom": [
+ "value_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_field_value_issue_id_field_id_unique": {
+ "name": "issue_field_value_issue_id_field_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "issue_id",
+ "field_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_import": {
+ "name": "issue_import",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "public_id": {
+ "name": "public_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "attachment_id": {
+ "name": "attachment_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'mapped'"
+ },
+ "mapping": {
+ "name": "mapping",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "error_text": {
+ "name": "error_text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_import_project_idx": {
+ "name": "issue_import_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_import_project_id_project_id_fk": {
+ "name": "issue_import_project_id_project_id_fk",
+ "tableFrom": "issue_import",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_import_attachment_id_chat_attachment_id_fk": {
+ "name": "issue_import_attachment_id_chat_attachment_id_fk",
+ "tableFrom": "issue_import",
+ "tableTo": "chat_attachment",
+ "columnsFrom": [
+ "attachment_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_import_public_id_unique": {
+ "name": "issue_import_public_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "public_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_key_alias": {
+ "name": "issue_key_alias",
+ "schema": "",
+ "columns": {
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "sequence_number": {
+ "name": "sequence_number",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "issue_key_alias_issue_idx": {
+ "name": "issue_key_alias_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_key_alias_project_id_project_id_fk": {
+ "name": "issue_key_alias_project_id_project_id_fk",
+ "tableFrom": "issue_key_alias",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_key_alias_issue_id_issue_id_fk": {
+ "name": "issue_key_alias_issue_id_issue_id_fk",
+ "tableFrom": "issue_key_alias",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "issue_key_alias_project_id_sequence_number_pk": {
+ "name": "issue_key_alias_project_id_sequence_number_pk",
+ "columns": [
+ "project_id",
+ "sequence_number"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_label": {
+ "name": "issue_label",
+ "schema": "",
+ "columns": {
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "label_id": {
+ "name": "label_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_label_issue_id_issue_id_fk": {
+ "name": "issue_label_issue_id_issue_id_fk",
+ "tableFrom": "issue_label",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_label_label_id_label_id_fk": {
+ "name": "issue_label_label_id_label_id_fk",
+ "tableFrom": "issue_label",
+ "tableTo": "label",
+ "columnsFrom": [
+ "label_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "issue_label_issue_id_label_id_pk": {
+ "name": "issue_label_issue_id_label_id_pk",
+ "columns": [
+ "issue_id",
+ "label_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_link": {
+ "name": "issue_link",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "source_issue_id": {
+ "name": "source_issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "target_issue_id": {
+ "name": "target_issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_link_pair_kind_idx": {
+ "name": "issue_link_pair_kind_idx",
+ "columns": [
+ {
+ "expression": "least(\"source_issue_id\", \"target_issue_id\")",
+ "asc": true,
+ "isExpression": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "greatest(\"source_issue_id\", \"target_issue_id\")",
+ "asc": true,
+ "isExpression": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "kind",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_link_source_idx": {
+ "name": "issue_link_source_idx",
+ "columns": [
+ {
+ "expression": "source_issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_link_target_idx": {
+ "name": "issue_link_target_idx",
+ "columns": [
+ {
+ "expression": "target_issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_link_source_issue_id_issue_id_fk": {
+ "name": "issue_link_source_issue_id_issue_id_fk",
+ "tableFrom": "issue_link",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "source_issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_link_target_issue_id_issue_id_fk": {
+ "name": "issue_link_target_issue_id_issue_id_fk",
+ "tableFrom": "issue_link",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "target_issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "issue_link_kind_check": {
+ "name": "issue_link_kind_check",
+ "value": "\"issue_link\".\"kind\" IN ('blocks', 'relates', 'duplicates')"
+ },
+ "issue_link_self_check": {
+ "name": "issue_link_self_check",
+ "value": "\"issue_link\".\"source_issue_id\" <> \"issue_link\".\"target_issue_id\""
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.issue_status": {
+ "name": "issue_status",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "column_id": {
+ "name": "column_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "column_name": {
+ "name": "column_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "state_type": {
+ "name": "state_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "entered_at": {
+ "name": "entered_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "left_at": {
+ "name": "left_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "issue_status_issue_idx": {
+ "name": "issue_status_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "entered_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_status_column_idx": {
+ "name": "issue_status_column_idx",
+ "columns": [
+ {
+ "expression": "column_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"issue_status\".\"column_id\" IS NOT NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "issue_status_open_idx": {
+ "name": "issue_status_open_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"issue_status\".\"left_at\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_status_issue_id_issue_id_fk": {
+ "name": "issue_status_issue_id_issue_id_fk",
+ "tableFrom": "issue_status",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_status_column_id_project_column_id_fk": {
+ "name": "issue_status_column_id_project_column_id_fk",
+ "tableFrom": "issue_status",
+ "tableTo": "project_column",
+ "columnsFrom": [
+ "column_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_template": {
+ "name": "issue_template",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "title_template": {
+ "name": "title_template",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "description_template": {
+ "name": "description_template",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "type_id": {
+ "name": "type_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "column_id": {
+ "name": "column_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "priority": {
+ "name": "priority",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "assignee_user_id": {
+ "name": "assignee_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_template_project_id_project_id_fk": {
+ "name": "issue_template_project_id_project_id_fk",
+ "tableFrom": "issue_template",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_template_type_id_issue_type_id_fk": {
+ "name": "issue_template_type_id_issue_type_id_fk",
+ "tableFrom": "issue_template",
+ "tableTo": "issue_type",
+ "columnsFrom": [
+ "type_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_template_column_id_project_column_id_fk": {
+ "name": "issue_template_column_id_project_column_id_fk",
+ "tableFrom": "issue_template",
+ "tableTo": "project_column",
+ "columnsFrom": [
+ "column_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "issue_template_assignee_user_id_user_id_fk": {
+ "name": "issue_template_assignee_user_id_user_id_fk",
+ "tableFrom": "issue_template",
+ "tableTo": "user",
+ "columnsFrom": [
+ "assignee_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_template_project_id_name_unique": {
+ "name": "issue_template_project_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_template_label": {
+ "name": "issue_template_label",
+ "schema": "",
+ "columns": {
+ "template_id": {
+ "name": "template_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "label_id": {
+ "name": "label_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_template_label_template_id_issue_template_id_fk": {
+ "name": "issue_template_label_template_id_issue_template_id_fk",
+ "tableFrom": "issue_template_label",
+ "tableTo": "issue_template",
+ "columnsFrom": [
+ "template_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_template_label_label_id_label_id_fk": {
+ "name": "issue_template_label_label_id_label_id_fk",
+ "tableFrom": "issue_template_label",
+ "tableTo": "label",
+ "columnsFrom": [
+ "label_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "issue_template_label_template_id_label_id_pk": {
+ "name": "issue_template_label_template_id_label_id_pk",
+ "columns": [
+ "template_id",
+ "label_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_type": {
+ "name": "issue_type",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'#6b7280'"
+ },
+ "is_default": {
+ "name": "is_default",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_type_project_id_project_id_fk": {
+ "name": "issue_type_project_id_project_id_fk",
+ "tableFrom": "issue_type",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "issue_type_project_id_name_unique": {
+ "name": "issue_type_project_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_watcher": {
+ "name": "issue_watcher",
+ "schema": "",
+ "columns": {
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "subscribed": {
+ "name": "subscribed",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "issue_watcher_issue_id_issue_id_fk": {
+ "name": "issue_watcher_issue_id_issue_id_fk",
+ "tableFrom": "issue_watcher",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_watcher_user_id_user_id_fk": {
+ "name": "issue_watcher_user_id_user_id_fk",
+ "tableFrom": "issue_watcher",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "issue_watcher_issue_id_user_id_pk": {
+ "name": "issue_watcher_issue_id_user_id_pk",
+ "columns": [
+ "issue_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.issue_worklog": {
+ "name": "issue_worklog",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "minutes": {
+ "name": "minutes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "spent_on": {
+ "name": "spent_on",
+ "type": "date",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "note": {
+ "name": "note",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "issue_worklog_issue_idx": {
+ "name": "issue_worklog_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "spent_on",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "issue_worklog_issue_id_issue_id_fk": {
+ "name": "issue_worklog_issue_id_issue_id_fk",
+ "tableFrom": "issue_worklog",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "issue_worklog_user_id_user_id_fk": {
+ "name": "issue_worklog_user_id_user_id_fk",
+ "tableFrom": "issue_worklog",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "issue_worklog_minutes_check": {
+ "name": "issue_worklog_minutes_check",
+ "value": "\"issue_worklog\".\"minutes\" > 0"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.label": {
+ "name": "label",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "group_id": {
+ "name": "group_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'#6b7280'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "label_project_id_project_id_fk": {
+ "name": "label_project_id_project_id_fk",
+ "tableFrom": "label",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "label_group_id_label_group_id_fk": {
+ "name": "label_group_id_label_group_id_fk",
+ "tableFrom": "label",
+ "tableTo": "label_group",
+ "columnsFrom": [
+ "group_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "label_project_id_name_unique": {
+ "name": "label_project_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.label_group": {
+ "name": "label_group",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'#6b7280'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "label_group_project_id_project_id_fk": {
+ "name": "label_group_project_id_project_id_fk",
+ "tableFrom": "label_group",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "label_group_project_id_name_unique": {
+ "name": "label_group_project_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.model_price": {
+ "name": "model_price",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "input": {
+ "name": "input",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "output": {
+ "name": "output",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "cache_read": {
+ "name": "cache_read",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "cache_write": {
+ "name": "cache_write",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "model_price_workspace_id_workspace_id_fk": {
+ "name": "model_price_workspace_id_workspace_id_fk",
+ "tableFrom": "model_price",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "model_price_workspace_id_provider_model_unique": {
+ "name": "model_price_workspace_id_provider_model_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "workspace_id",
+ "provider",
+ "model"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "model_price_rates_check": {
+ "name": "model_price_rates_check",
+ "value": "\"model_price\".\"input\" >= 0 AND \"model_price\".\"output\" >= 0 AND coalesce(\"model_price\".\"cache_read\", 0) >= 0 AND coalesce(\"model_price\".\"cache_write\", 0) >= 0"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.note_board": {
+ "name": "note_board",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "owner_user_id": {
+ "name": "owner_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "canvas": {
+ "name": "canvas",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "note_board_project_idx": {
+ "name": "note_board_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "updated_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "note_board_project_id_project_id_fk": {
+ "name": "note_board_project_id_project_id_fk",
+ "tableFrom": "note_board",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "note_board_owner_user_id_user_id_fk": {
+ "name": "note_board_owner_user_id_user_id_fk",
+ "tableFrom": "note_board",
+ "tableTo": "user",
+ "columnsFrom": [
+ "owner_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "note_board_created_by_user_id_user_id_fk": {
+ "name": "note_board_created_by_user_id_user_id_fk",
+ "tableFrom": "note_board",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.note_board_member": {
+ "name": "note_board_member",
+ "schema": "",
+ "columns": {
+ "board_id": {
+ "name": "board_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "note_board_member_user_idx": {
+ "name": "note_board_member_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "note_board_member_board_id_note_board_id_fk": {
+ "name": "note_board_member_board_id_note_board_id_fk",
+ "tableFrom": "note_board_member",
+ "tableTo": "note_board",
+ "columnsFrom": [
+ "board_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "note_board_member_user_id_user_id_fk": {
+ "name": "note_board_member_user_id_user_id_fk",
+ "tableFrom": "note_board_member",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "note_board_member_board_id_user_id_pk": {
+ "name": "note_board_member_board_id_user_id_pk",
+ "columns": [
+ "board_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.notification": {
+ "name": "notification",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "source_activity_id": {
+ "name": "source_activity_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "actor_user_id": {
+ "name": "actor_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "actor_name": {
+ "name": "actor_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "read_at": {
+ "name": "read_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "snoozed_until": {
+ "name": "snoozed_until",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "notification_user_idx": {
+ "name": "notification_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "created_at",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "notification_user_unread_idx": {
+ "name": "notification_user_unread_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": false,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"notification\".\"read_at\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "notification_user_id_user_id_fk": {
+ "name": "notification_user_id_user_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "notification_project_id_project_id_fk": {
+ "name": "notification_project_id_project_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "notification_issue_id_issue_id_fk": {
+ "name": "notification_issue_id_issue_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "notification_source_activity_id_issue_activity_id_fk": {
+ "name": "notification_source_activity_id_issue_activity_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "issue_activity",
+ "columnsFrom": [
+ "source_activity_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "notification_actor_user_id_user_id_fk": {
+ "name": "notification_actor_user_id_user_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "user",
+ "columnsFrom": [
+ "actor_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "notification_type_check": {
+ "name": "notification_type_check",
+ "value": "\"notification\".\"type\" IN ('assigned', 'mentioned', 'commented', 'state_changed')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.notification_delivery": {
+ "name": "notification_delivery",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "channel": {
+ "name": "channel",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "recipient": {
+ "name": "recipient",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "payload": {
+ "name": "payload",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "next_attempt_at": {
+ "name": "next_attempt_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "notification_delivery_due_idx": {
+ "name": "notification_delivery_due_idx",
+ "columns": [
+ {
+ "expression": "next_attempt_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"notification_delivery\".\"status\" = 'pending'",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "notification_delivery_project_id_project_id_fk": {
+ "name": "notification_delivery_project_id_project_id_fk",
+ "tableFrom": "notification_delivery",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "notification_delivery_channel_check": {
+ "name": "notification_delivery_channel_check",
+ "value": "\"notification_delivery\".\"channel\" IN ('email', 'telegram')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.project": {
+ "name": "project",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "next_sequence": {
+ "name": "next_sequence",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 1
+ },
+ "mcp_enabled": {
+ "name": "mcp_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "initiatives_enabled": {
+ "name": "initiatives_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "dashboards_enabled": {
+ "name": "dashboards_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "documents_enabled": {
+ "name": "documents_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "notes_enabled": {
+ "name": "notes_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "cycles_enabled": {
+ "name": "cycles_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "subtasks_enabled": {
+ "name": "subtasks_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "checklists_enabled": {
+ "name": "checklists_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "issue_stats_enabled": {
+ "name": "issue_stats_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "points_estimate_enabled": {
+ "name": "points_estimate_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "time_estimate_enabled": {
+ "name": "time_estimate_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "time_logging_enabled": {
+ "name": "time_logging_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "project_team_id_team_id_fk": {
+ "name": "project_team_id_team_id_fk",
+ "tableFrom": "project",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "project_team_key_uq": {
+ "name": "project_team_key_uq",
+ "nullsNotDistinct": false,
+ "columns": [
+ "team_id",
+ "key"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_action": {
+ "name": "project_action",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "condition": {
+ "name": "condition",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "effect": {
+ "name": "effect",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_action_project_idx": {
+ "name": "project_action_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_action_project_id_project_id_fk": {
+ "name": "project_action_project_id_project_id_fk",
+ "tableFrom": "project_action",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_column": {
+ "name": "project_column",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "state_type": {
+ "name": "state_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'unstarted'"
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'#6b7280'"
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "wip_limit": {
+ "name": "wip_limit",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "wip_mode": {
+ "name": "wip_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'soft'"
+ },
+ "auto_assign_user_id": {
+ "name": "auto_assign_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "project_column_project_id_project_id_fk": {
+ "name": "project_column_project_id_project_id_fk",
+ "tableFrom": "project_column",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_column_auto_assign_user_id_user_id_fk": {
+ "name": "project_column_auto_assign_user_id_user_id_fk",
+ "tableFrom": "project_column",
+ "tableTo": "user",
+ "columnsFrom": [
+ "auto_assign_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "project_column_project_id_position_unique": {
+ "name": "project_column_project_id_position_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "project_id",
+ "position"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "project_column_state_type_check": {
+ "name": "project_column_state_type_check",
+ "value": "\"project_column\".\"state_type\" IN ('backlog', 'unstarted', 'started', 'completed', 'canceled')"
+ },
+ "project_column_wip_mode_check": {
+ "name": "project_column_wip_mode_check",
+ "value": "\"project_column\".\"wip_mode\" IN ('soft', 'hard')"
+ },
+ "project_column_wip_limit_check": {
+ "name": "project_column_wip_limit_check",
+ "value": "\"project_column\".\"wip_limit\" IS NULL OR \"project_column\".\"wip_limit\" > 0"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.project_dashboard": {
+ "name": "project_dashboard",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "layout": {
+ "name": "layout",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'[]'::jsonb"
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_dashboard_project_idx": {
+ "name": "project_dashboard_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_dashboard_project_id_project_id_fk": {
+ "name": "project_dashboard_project_id_project_id_fk",
+ "tableFrom": "project_dashboard",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_document": {
+ "name": "project_document",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "parent_id": {
+ "name": "parent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "content_json": {
+ "name": "content_json",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "full_width": {
+ "name": "full_width",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "is_private": {
+ "name": "is_private",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "is_locked": {
+ "name": "is_locked",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "archived_by_ancestor_id": {
+ "name": "archived_by_ancestor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "version": {
+ "name": "version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 1
+ },
+ "owner_user_id": {
+ "name": "owner_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "updated_by_user_id": {
+ "name": "updated_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_document_project_tree_idx": {
+ "name": "project_document_project_tree_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "parent_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "project_document_owner_idx": {
+ "name": "project_document_owner_idx",
+ "columns": [
+ {
+ "expression": "owner_user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "project_document_project_archive_idx": {
+ "name": "project_document_project_archive_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "archived_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_document_project_id_project_id_fk": {
+ "name": "project_document_project_id_project_id_fk",
+ "tableFrom": "project_document",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_parent_id_project_document_id_fk": {
+ "name": "project_document_parent_id_project_document_id_fk",
+ "tableFrom": "project_document",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "parent_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "project_document_archived_by_ancestor_id_project_document_id_fk": {
+ "name": "project_document_archived_by_ancestor_id_project_document_id_fk",
+ "tableFrom": "project_document",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "archived_by_ancestor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "project_document_owner_user_id_user_id_fk": {
+ "name": "project_document_owner_user_id_user_id_fk",
+ "tableFrom": "project_document",
+ "tableTo": "user",
+ "columnsFrom": [
+ "owner_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "project_document_created_by_user_id_user_id_fk": {
+ "name": "project_document_created_by_user_id_user_id_fk",
+ "tableFrom": "project_document",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "project_document_updated_by_user_id_user_id_fk": {
+ "name": "project_document_updated_by_user_id_user_id_fk",
+ "tableFrom": "project_document",
+ "tableTo": "user",
+ "columnsFrom": [
+ "updated_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "project_document_version_check": {
+ "name": "project_document_version_check",
+ "value": "\"project_document\".\"version\" > 0"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.project_document_initiative": {
+ "name": "project_document_initiative",
+ "schema": "",
+ "columns": {
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "initiative_id": {
+ "name": "initiative_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_document_initiative_initiative_idx": {
+ "name": "project_document_initiative_initiative_idx",
+ "columns": [
+ {
+ "expression": "initiative_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "document_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_document_initiative_document_id_project_document_id_fk": {
+ "name": "project_document_initiative_document_id_project_document_id_fk",
+ "tableFrom": "project_document_initiative",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_initiative_initiative_id_initiative_id_fk": {
+ "name": "project_document_initiative_initiative_id_initiative_id_fk",
+ "tableFrom": "project_document_initiative",
+ "tableTo": "initiative",
+ "columnsFrom": [
+ "initiative_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_initiative_created_by_user_id_user_id_fk": {
+ "name": "project_document_initiative_created_by_user_id_user_id_fk",
+ "tableFrom": "project_document_initiative",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "project_document_initiative_document_id_initiative_id_pk": {
+ "name": "project_document_initiative_document_id_initiative_id_pk",
+ "columns": [
+ "document_id",
+ "initiative_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_document_issue": {
+ "name": "project_document_issue",
+ "schema": "",
+ "columns": {
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "issue_id": {
+ "name": "issue_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_document_issue_issue_idx": {
+ "name": "project_document_issue_issue_idx",
+ "columns": [
+ {
+ "expression": "issue_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "document_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_document_issue_document_id_project_document_id_fk": {
+ "name": "project_document_issue_document_id_project_document_id_fk",
+ "tableFrom": "project_document_issue",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_issue_issue_id_issue_id_fk": {
+ "name": "project_document_issue_issue_id_issue_id_fk",
+ "tableFrom": "project_document_issue",
+ "tableTo": "issue",
+ "columnsFrom": [
+ "issue_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_issue_created_by_user_id_user_id_fk": {
+ "name": "project_document_issue_created_by_user_id_user_id_fk",
+ "tableFrom": "project_document_issue",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "project_document_issue_document_id_issue_id_pk": {
+ "name": "project_document_issue_document_id_issue_id_pk",
+ "columns": [
+ "document_id",
+ "issue_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_document_preference": {
+ "name": "project_document_preference",
+ "schema": "",
+ "columns": {
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "is_favorite": {
+ "name": "is_favorite",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_document_preference_user_idx": {
+ "name": "project_document_preference_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_document_preference_document_id_project_document_id_fk": {
+ "name": "project_document_preference_document_id_project_document_id_fk",
+ "tableFrom": "project_document_preference",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_preference_user_id_user_id_fk": {
+ "name": "project_document_preference_user_id_user_id_fk",
+ "tableFrom": "project_document_preference",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "project_document_preference_document_id_user_id_pk": {
+ "name": "project_document_preference_document_id_user_id_pk",
+ "columns": [
+ "document_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_document_revision": {
+ "name": "project_document_revision",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "document_id": {
+ "name": "document_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "version": {
+ "name": "version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "parent_id": {
+ "name": "parent_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content_json": {
+ "name": "content_json",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "full_width": {
+ "name": "full_width",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "is_private": {
+ "name": "is_private",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "is_locked": {
+ "name": "is_locked",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "owner_user_id": {
+ "name": "owner_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_document_revision_document_idx": {
+ "name": "project_document_revision_document_idx",
+ "columns": [
+ {
+ "expression": "document_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "version",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_document_revision_document_id_project_document_id_fk": {
+ "name": "project_document_revision_document_id_project_document_id_fk",
+ "tableFrom": "project_document_revision",
+ "tableTo": "project_document",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_document_revision_owner_user_id_user_id_fk": {
+ "name": "project_document_revision_owner_user_id_user_id_fk",
+ "tableFrom": "project_document_revision",
+ "tableTo": "user",
+ "columnsFrom": [
+ "owner_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "project_document_revision_created_by_user_id_user_id_fk": {
+ "name": "project_document_revision_created_by_user_id_user_id_fk",
+ "tableFrom": "project_document_revision",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "project_document_revision_document_version_unique": {
+ "name": "project_document_revision_document_version_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "document_id",
+ "version"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_member": {
+ "name": "project_member",
+ "schema": "",
+ "columns": {
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'member'"
+ },
+ "role_id": {
+ "name": "role_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "''"
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'invite'"
+ },
+ "is_favorite": {
+ "name": "is_favorite",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "is_hidden": {
+ "name": "is_hidden",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_member_user_idx": {
+ "name": "project_member_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_member_project_id_project_id_fk": {
+ "name": "project_member_project_id_project_id_fk",
+ "tableFrom": "project_member",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_member_user_id_user_id_fk": {
+ "name": "project_member_user_id_user_id_fk",
+ "tableFrom": "project_member",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_member_role_id_team_role_id_fk": {
+ "name": "project_member_role_id_team_role_id_fk",
+ "tableFrom": "project_member",
+ "tableTo": "team_role",
+ "columnsFrom": [
+ "role_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "project_member_project_id_user_id_pk": {
+ "name": "project_member_project_id_user_id_pk",
+ "columns": [
+ "project_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "project_member_role_check": {
+ "name": "project_member_role_check",
+ "value": "\"project_member\".\"role\" IN ('owner', 'member')"
+ },
+ "project_member_source_check": {
+ "name": "project_member_source_check",
+ "value": "\"project_member\".\"source\" IN ('invite', 'scim')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.project_setting": {
+ "name": "project_setting",
+ "schema": "",
+ "columns": {
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "value": {
+ "name": "value",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "project_setting_project_id_project_id_fk": {
+ "name": "project_setting_project_id_project_id_fk",
+ "tableFrom": "project_setting",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "project_setting_project_id_key_pk": {
+ "name": "project_setting_project_id_key_pk",
+ "columns": [
+ "project_id",
+ "key"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_view": {
+ "name": "project_view",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "filters": {
+ "name": "filters",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "display": {
+ "name": "display",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "position": {
+ "name": "position",
+ "type": "double precision",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "share_token": {
+ "name": "share_token",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "share_extended": {
+ "name": "share_extended",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "project_view_project_idx": {
+ "name": "project_view_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "position",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "project_view_project_id_project_id_fk": {
+ "name": "project_view_project_id_project_id_fk",
+ "tableFrom": "project_view",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "project_view_share_token_unique": {
+ "name": "project_view_share_token_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "share_token"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project_view_favorite": {
+ "name": "project_view_favorite",
+ "schema": "",
+ "columns": {
+ "view_id": {
+ "name": "view_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "project_view_favorite_view_id_project_view_id_fk": {
+ "name": "project_view_favorite_view_id_project_view_id_fk",
+ "tableFrom": "project_view_favorite",
+ "tableTo": "project_view",
+ "columnsFrom": [
+ "view_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "project_view_favorite_user_id_user_id_fk": {
+ "name": "project_view_favorite_user_id_user_id_fk",
+ "tableFrom": "project_view_favorite",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "project_view_favorite_view_id_user_id_pk": {
+ "name": "project_view_favorite_view_id_user_id_pk",
+ "columns": [
+ "view_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.revision": {
+ "name": "revision",
+ "schema": "",
+ "columns": {
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "rev": {
+ "name": "rev",
+ "type": "bigint",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ }
+ },
+ "indexes": {
+ "revision_project_idx": {
+ "name": "revision_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.team": {
+ "name": "team",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "mcp_enabled": {
+ "name": "mcp_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "default_agent_ids": {
+ "name": "default_agent_ids",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'[]'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "team_workspace_idx": {
+ "name": "team_workspace_idx",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "team_workspace_id_workspace_id_fk": {
+ "name": "team_workspace_id_workspace_id_fk",
+ "tableFrom": "team",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "team_slug_unique": {
+ "name": "team_slug_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "slug"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.team_invite": {
+ "name": "team_invite",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "token": {
+ "name": "token",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "team_role": {
+ "name": "team_role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'member'"
+ },
+ "project_role": {
+ "name": "project_role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "role_id": {
+ "name": "role_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "invited_by_user_id": {
+ "name": "invited_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "accepted_by_user_id": {
+ "name": "accepted_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "responded_at": {
+ "name": "responded_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "team_invite_team_pending_uq": {
+ "name": "team_invite_team_pending_uq",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "email",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"team_invite\".\"status\" = 'pending' AND \"team_invite\".\"project_id\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "team_invite_project_pending_uq": {
+ "name": "team_invite_project_pending_uq",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "email",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"team_invite\".\"status\" = 'pending' AND \"team_invite\".\"project_id\" IS NOT NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "team_invite_team_idx": {
+ "name": "team_invite_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "team_invite_project_idx": {
+ "name": "team_invite_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "team_invite_team_id_team_id_fk": {
+ "name": "team_invite_team_id_team_id_fk",
+ "tableFrom": "team_invite",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "team_invite_project_id_project_id_fk": {
+ "name": "team_invite_project_id_project_id_fk",
+ "tableFrom": "team_invite",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "team_invite_role_id_team_role_id_fk": {
+ "name": "team_invite_role_id_team_role_id_fk",
+ "tableFrom": "team_invite",
+ "tableTo": "team_role",
+ "columnsFrom": [
+ "role_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "team_invite_invited_by_user_id_user_id_fk": {
+ "name": "team_invite_invited_by_user_id_user_id_fk",
+ "tableFrom": "team_invite",
+ "tableTo": "user",
+ "columnsFrom": [
+ "invited_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "team_invite_accepted_by_user_id_user_id_fk": {
+ "name": "team_invite_accepted_by_user_id_user_id_fk",
+ "tableFrom": "team_invite",
+ "tableTo": "user",
+ "columnsFrom": [
+ "accepted_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "team_invite_token_unique": {
+ "name": "team_invite_token_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "token"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "team_invite_team_role_check": {
+ "name": "team_invite_team_role_check",
+ "value": "\"team_invite\".\"team_role\" IN ('owner', 'manager', 'member')"
+ },
+ "team_invite_project_role_check": {
+ "name": "team_invite_project_role_check",
+ "value": "(\"team_invite\".\"project_id\" IS NULL AND \"team_invite\".\"project_role\" IS NULL)\n OR (\"team_invite\".\"project_id\" IS NOT NULL AND \"team_invite\".\"project_role\" IN ('owner', 'member'))"
+ },
+ "team_invite_status_check": {
+ "name": "team_invite_status_check",
+ "value": "\"team_invite\".\"status\" IN ('pending', 'accepted', 'rejected')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.team_member": {
+ "name": "team_member",
+ "schema": "",
+ "columns": {
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'member'"
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'invite'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "team_member_user_idx": {
+ "name": "team_member_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "team_member_team_id_team_id_fk": {
+ "name": "team_member_team_id_team_id_fk",
+ "tableFrom": "team_member",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "team_member_user_id_user_id_fk": {
+ "name": "team_member_user_id_user_id_fk",
+ "tableFrom": "team_member",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "team_member_team_id_user_id_pk": {
+ "name": "team_member_team_id_user_id_pk",
+ "columns": [
+ "team_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "team_member_role_check": {
+ "name": "team_member_role_check",
+ "value": "\"team_member\".\"role\" IN ('owner', 'manager', 'member', 'agent')"
+ },
+ "team_member_source_check": {
+ "name": "team_member_source_check",
+ "value": "\"team_member\".\"source\" IN ('invite', 'scim')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.team_notification_setting": {
+ "name": "team_notification_setting",
+ "schema": "",
+ "columns": {
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "ciphertext": {
+ "name": "ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "iv": {
+ "name": "iv",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "auth_tag": {
+ "name": "auth_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "redacted": {
+ "name": "redacted",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "team_notification_setting_team_id_team_id_fk": {
+ "name": "team_notification_setting_team_id_team_id_fk",
+ "tableFrom": "team_notification_setting",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.team_role": {
+ "name": "team_role",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "is_default": {
+ "name": "is_default",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "permissions": {
+ "name": "permissions",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "team_role_default_uq": {
+ "name": "team_role_default_uq",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"team_role\".\"is_default\"",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "team_role_team_idx": {
+ "name": "team_role_team_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "team_role_team_id_team_id_fk": {
+ "name": "team_role_team_id_team_id_fk",
+ "tableFrom": "team_role",
+ "tableTo": "team",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "team_role_team_id_name_unique": {
+ "name": "team_role_team_id_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "team_id",
+ "name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.user_notification_preference": {
+ "name": "user_notification_preference",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email_events": {
+ "name": "email_events",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "telegram_events": {
+ "name": "telegram_events",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "user_notification_preference_user_id_user_id_fk": {
+ "name": "user_notification_preference_user_id_user_id_fk",
+ "tableFrom": "user_notification_preference",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "user_notification_preference_project_id_project_id_fk": {
+ "name": "user_notification_preference_project_id_project_id_fk",
+ "tableFrom": "user_notification_preference",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "user_notification_pref_user_project_unique": {
+ "name": "user_notification_pref_user_project_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "user_id",
+ "project_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.user_preference": {
+ "name": "user_preference",
+ "schema": "",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "timezone": {
+ "name": "timezone",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'UTC'"
+ },
+ "locale": {
+ "name": "locale",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'en'"
+ },
+ "theme": {
+ "name": "theme",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'system'"
+ },
+ "issue_open_mode": {
+ "name": "issue_open_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'panel'"
+ },
+ "start_page": {
+ "name": "start_page",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'work-items'"
+ },
+ "show_chat_by_default": {
+ "name": "show_chat_by_default",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "issue_stats_open": {
+ "name": "issue_stats_open",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "issue_stats_view": {
+ "name": "issue_stats_view",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'compact'"
+ },
+ "issue_activity_view": {
+ "name": "issue_activity_view",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'flat'"
+ },
+ "auto_watch": {
+ "name": "auto_watch",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "hotkeys": {
+ "name": "hotkeys",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "last_project_id": {
+ "name": "last_project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "seen_version": {
+ "name": "seen_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "user_preference_user_id_user_id_fk": {
+ "name": "user_preference_user_id_user_id_fk",
+ "tableFrom": "user_preference",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "user_preference_last_project_id_project_id_fk": {
+ "name": "user_preference_last_project_id_project_id_fk",
+ "tableFrom": "user_preference",
+ "tableTo": "project",
+ "columnsFrom": [
+ "last_project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "user_preference_theme_check": {
+ "name": "user_preference_theme_check",
+ "value": "\"user_preference\".\"theme\" IN ('light', 'dark', 'system')"
+ },
+ "user_preference_issue_open_mode_check": {
+ "name": "user_preference_issue_open_mode_check",
+ "value": "\"user_preference\".\"issue_open_mode\" IN ('panel', 'page')"
+ },
+ "user_preference_start_page_check": {
+ "name": "user_preference_start_page_check",
+ "value": "\"user_preference\".\"start_page\" IN ('inbox', 'dashboard', 'work-items', 'initiatives')"
+ },
+ "user_preference_issue_stats_view_check": {
+ "name": "user_preference_issue_stats_view_check",
+ "value": "\"user_preference\".\"issue_stats_view\" IN ('compact', 'timeline')"
+ },
+ "user_preference_issue_activity_view_check": {
+ "name": "user_preference_issue_activity_view_check",
+ "value": "\"user_preference\".\"issue_activity_view\" IN ('flat', 'grouped')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.user_telegram_account": {
+ "name": "user_telegram_account",
+ "schema": "",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "first_name": {
+ "name": "first_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "link_code": {
+ "name": "link_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "link_code_expires_at": {
+ "name": "link_code_expires_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "linked_at": {
+ "name": "linked_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "user_telegram_account_chat_id_unique": {
+ "name": "user_telegram_account_chat_id_unique",
+ "columns": [
+ {
+ "expression": "chat_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"user_telegram_account\".\"chat_id\" IS NOT NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "user_telegram_account_link_code_unique": {
+ "name": "user_telegram_account_link_code_unique",
+ "columns": [
+ {
+ "expression": "link_code",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"user_telegram_account\".\"link_code\" IS NOT NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "user_telegram_account_user_id_user_id_fk": {
+ "name": "user_telegram_account_user_id_user_id_fk",
+ "tableFrom": "user_telegram_account",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.webhook": {
+ "name": "webhook",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "secret": {
+ "name": "secret",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "events": {
+ "name": "events",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'[]'::jsonb"
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "consecutive_failures": {
+ "name": "consecutive_failures",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "webhook_project_idx": {
+ "name": "webhook_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "webhook_project_id_project_id_fk": {
+ "name": "webhook_project_id_project_id_fk",
+ "tableFrom": "webhook",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.webhook_delivery": {
+ "name": "webhook_delivery",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "webhook_id": {
+ "name": "webhook_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "event_id": {
+ "name": "event_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "event_type": {
+ "name": "event_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "payload": {
+ "name": "payload",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "next_attempt_at": {
+ "name": "next_attempt_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "response_status": {
+ "name": "response_status",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "response_body": {
+ "name": "response_body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "webhook_delivery_due_idx": {
+ "name": "webhook_delivery_due_idx",
+ "columns": [
+ {
+ "expression": "next_attempt_at",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "where": "\"webhook_delivery\".\"status\" = 'pending'",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "webhook_delivery_webhook_idx": {
+ "name": "webhook_delivery_webhook_idx",
+ "columns": [
+ {
+ "expression": "webhook_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "webhook_delivery_webhook_id_webhook_id_fk": {
+ "name": "webhook_delivery_webhook_id_webhook_id_fk",
+ "tableFrom": "webhook_delivery",
+ "tableTo": "webhook",
+ "columnsFrom": [
+ "webhook_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.workspace": {
+ "name": "workspace",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "team_creation": {
+ "name": "team_creation",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'owner'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "workspace_team_creation_check": {
+ "name": "workspace_team_creation_check",
+ "value": "\"workspace\".\"team_creation\" IN ('owner', 'managers', 'members')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.workspace_manager": {
+ "name": "workspace_manager",
+ "schema": "",
+ "columns": {
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'admin'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "workspace_manager_owner_uq": {
+ "name": "workspace_manager_owner_uq",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"workspace_manager\".\"role\" = 'owner'",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "workspace_manager_user_idx": {
+ "name": "workspace_manager_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "workspace_manager_workspace_id_workspace_id_fk": {
+ "name": "workspace_manager_workspace_id_workspace_id_fk",
+ "tableFrom": "workspace_manager",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "workspace_manager_user_id_user_id_fk": {
+ "name": "workspace_manager_user_id_user_id_fk",
+ "tableFrom": "workspace_manager",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "workspace_manager_workspace_id_user_id_pk": {
+ "name": "workspace_manager_workspace_id_user_id_pk",
+ "columns": [
+ "workspace_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {
+ "workspace_manager_role_check": {
+ "name": "workspace_manager_role_check",
+ "value": "\"workspace_manager\".\"role\" IN ('owner', 'admin')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.scim_group": {
+ "name": "scim_group",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "display_name": {
+ "name": "display_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "scim_group_instance_display_name_uq": {
+ "name": "scim_group_instance_display_name_uq",
+ "columns": [
+ {
+ "expression": "display_name",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"scim_group\".\"workspace_id\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "scim_group_workspace_id_workspace_id_fk": {
+ "name": "scim_group_workspace_id_workspace_id_fk",
+ "tableFrom": "scim_group",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "scim_group_workspace_id_display_name_unique": {
+ "name": "scim_group_workspace_id_display_name_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "workspace_id",
+ "display_name"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.scim_group_mapping": {
+ "name": "scim_group_mapping",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "group_id": {
+ "name": "group_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'member'"
+ },
+ "role_id": {
+ "name": "role_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "scim_group_mapping_project_idx": {
+ "name": "scim_group_mapping_project_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "scim_group_mapping_group_id_scim_group_id_fk": {
+ "name": "scim_group_mapping_group_id_scim_group_id_fk",
+ "tableFrom": "scim_group_mapping",
+ "tableTo": "scim_group",
+ "columnsFrom": [
+ "group_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "scim_group_mapping_project_id_project_id_fk": {
+ "name": "scim_group_mapping_project_id_project_id_fk",
+ "tableFrom": "scim_group_mapping",
+ "tableTo": "project",
+ "columnsFrom": [
+ "project_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "scim_group_mapping_role_id_team_role_id_fk": {
+ "name": "scim_group_mapping_role_id_team_role_id_fk",
+ "tableFrom": "scim_group_mapping",
+ "tableTo": "team_role",
+ "columnsFrom": [
+ "role_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "scim_group_mapping_group_id_project_id_unique": {
+ "name": "scim_group_mapping_group_id_project_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "group_id",
+ "project_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {
+ "scim_group_mapping_role_check": {
+ "name": "scim_group_mapping_role_check",
+ "value": "\"scim_group_mapping\".\"role\" IN ('owner', 'member')"
+ }
+ },
+ "isRLSEnabled": false
+ },
+ "public.scim_group_member": {
+ "name": "scim_group_member",
+ "schema": "",
+ "columns": {
+ "group_id": {
+ "name": "group_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "scim_group_member_user_idx": {
+ "name": "scim_group_member_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "scim_group_member_group_id_scim_group_id_fk": {
+ "name": "scim_group_member_group_id_scim_group_id_fk",
+ "tableFrom": "scim_group_member",
+ "tableTo": "scim_group",
+ "columnsFrom": [
+ "group_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "scim_group_member_user_id_user_id_fk": {
+ "name": "scim_group_member_user_id_user_id_fk",
+ "tableFrom": "scim_group_member",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "scim_group_member_group_id_user_id_pk": {
+ "name": "scim_group_member_group_id_user_id_pk",
+ "columns": [
+ "group_id",
+ "user_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.scim_user": {
+ "name": "scim_user",
+ "schema": "",
+ "columns": {
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "active": {
+ "name": "active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "scim_user_instance_user_uq": {
+ "name": "scim_user_instance_user_uq",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"scim_user\".\"workspace_id\" IS NULL",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "scim_user_user_idx": {
+ "name": "scim_user_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "scim_user_workspace_id_workspace_id_fk": {
+ "name": "scim_user_workspace_id_workspace_id_fk",
+ "tableFrom": "scim_user",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "scim_user_user_id_user_id_fk": {
+ "name": "scim_user_user_id_user_id_fk",
+ "tableFrom": "scim_user",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "scim_user_workspace_id_user_id_unique": {
+ "name": "scim_user_workspace_id_user_id_unique",
+ "nullsNotDistinct": false,
+ "columns": [
+ "workspace_id",
+ "user_id"
+ ]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "sequences": {},
+ "roles": {},
+ "policies": {},
+ "views": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json
index 3c5f92d0..bccd276c 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -1051,6 +1051,13 @@
"when": 1791907060303,
"tag": "0149_oauth_provider_tables",
"breakpoints": true
+ },
+ {
+ "idx": 150,
+ "version": "7",
+ "when": 1792098421237,
+ "tag": "0150_workspace_per_owner",
+ "breakpoints": true
}
]
-}
\ No newline at end of file
+}
diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts
index d9eaafab..d7d0e68a 100644
--- a/packages/db/src/index.ts
+++ b/packages/db/src/index.ts
@@ -3,7 +3,7 @@ export * from './schema';
export * from './permissions';
export { getSetting, getOrCreateSetting, setSetting } from './settings';
export { readSecret, writeSecret } from './secrets';
-export { createWorkspace, instanceWorkspaceId, teamWorkspaceId } from './workspace';
+export { createWorkspace, teamWorkspaceId } from './workspace';
export {
TELEGRAM_BOT_SECRET_KEY,
getInstanceBotConfig,
diff --git a/packages/db/src/schema/app.ts b/packages/db/src/schema/app.ts
index fcb42030..c9912f5e 100644
--- a/packages/db/src/schema/app.ts
+++ b/packages/db/src/schema/app.ts
@@ -49,9 +49,8 @@ export const appSecret = pgTable('app_secret', {
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
});
-// A workspace owns teams; its members are derived from them. The instance workspace was
-// created by the migration that introduced the table and belongs to the instance owner;
-// everyone else gets one of their own at sign-up.
+// A workspace owns teams; its members are derived from them. Every person, the instance
+// owner included, gets one of their own at sign-up, and a team is always created in one.
export const workspace = pgTable(
'workspace',
{
diff --git a/packages/db/src/schema/scim.ts b/packages/db/src/schema/scim.ts
index 7ae02aaa..e08c5f43 100644
--- a/packages/db/src/schema/scim.ts
+++ b/packages/db/src/schema/scim.ts
@@ -1,6 +1,9 @@
// SCIM 2.0 provisioning tables. An identity provider pushes users and groups to
// /scim/v2 in the API; an account is one `user` row across the instance, and what a
-// workspace's provider knows about it lands here, as do its groups.
+// provider knows about it lands here, as do its groups. `workspace_id` names the
+// workspace whose provider wrote the row, and is null for the instance's provider, the
+// one god mode sets up. A NULL takes no part in a unique constraint, so the instance's
+// rows are kept unique by a partial index of their own.
import {
boolean,
check,
@@ -12,24 +15,22 @@ import {
text,
timestamp,
unique,
+ uniqueIndex,
uuid,
} from 'drizzle-orm/pg-core';
import { sql } from 'drizzle-orm';
import { user } from './auth';
import { project, teamRole, workspace } from './app';
-// An account as the identity provider of one workspace sees it. While SCIM is the
-// instance's, the instance workspace's provider speaks for the whole instance and
-// `active` false means the account cannot sign in. Set up per workspace, the provider
-// decides who has the workspace, not who has an account: `active` false means the person
-// was taken out of the workspace's teams and its groups grant them nothing. Every
-// workspace's provider keeps its own row for the same person.
+// An account as one identity provider sees it. For the instance's provider `active`
+// false means the account cannot sign in. For a workspace's, it decides who has the
+// workspace, not who has an account: `active` false means the person was taken out of
+// the workspace's teams and its groups grant them nothing. Every provider keeps its own
+// row for the same person.
export const scimUser = pgTable(
'scim_user',
{
- workspaceId: integer('workspace_id')
- .notNull()
- .references(() => workspace.id, { onDelete: 'cascade' }),
+ workspaceId: integer('workspace_id').references(() => workspace.id, { onDelete: 'cascade' }),
userId: text('user_id')
.notNull()
.references(() => user.id, { onDelete: 'cascade' }),
@@ -39,21 +40,21 @@ export const scimUser = pgTable(
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
},
(t) => [
- primaryKey({ columns: [t.workspaceId, t.userId] }),
+ unique().on(t.workspaceId, t.userId),
+ uniqueIndex('scim_user_instance_user_uq')
+ .on(t.userId)
+ .where(sql`${t.workspaceId} IS NULL`),
index('scim_user_user_idx').on(t.userId),
],
);
-// A group as the identity provider of one workspace sees it. Written only over SCIM:
-// the group list and its members are the provider's, and the workspace settings show
-// them read-only.
+// A group as one identity provider sees it. Written only over SCIM: the group list and
+// its members are the provider's, and the settings show them read-only.
export const scimGroup = pgTable(
'scim_group',
{
id: uuid('id').primaryKey().defaultRandom(),
- workspaceId: integer('workspace_id')
- .notNull()
- .references(() => workspace.id, { onDelete: 'cascade' }),
+ workspaceId: integer('workspace_id').references(() => workspace.id, { onDelete: 'cascade' }),
displayName: text('display_name').notNull(),
// The provider's own id for the group, sent as `externalId` and used to find a
// group again after it is renamed.
@@ -61,7 +62,12 @@ export const scimGroup = pgTable(
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
},
- (t) => [unique().on(t.workspaceId, t.displayName)],
+ (t) => [
+ unique().on(t.workspaceId, t.displayName),
+ uniqueIndex('scim_group_instance_display_name_uq')
+ .on(t.displayName)
+ .where(sql`${t.workspaceId} IS NULL`),
+ ],
);
export const scimGroupMember = pgTable(
@@ -80,10 +86,11 @@ export const scimGroupMember = pgTable(
],
);
-// What a group grants. A SCIM group carries only a name and a member list, so the
-// workspace owner declares that group X makes its members part of project Y of the
-// same workspace at role Z. One group may map to several projects; at most one
-// mapping per pair.
+// What a group grants. A SCIM group carries only a name and a member list, so whoever
+// set up its provider declares that group X makes its members part of project Y at
+// role Z: god for the instance's groups, the workspace owner for a workspace's, which
+// map to projects of that workspace only. One group may map to several projects; at
+// most one mapping per pair.
// `role_id` names the team_role a "member" joins on, and is NULL for an owner (an
// owner bypasses the permission matrix) or when the team's default role applies.
export const scimGroupMapping = pgTable(
diff --git a/packages/db/src/workspace.ts b/packages/db/src/workspace.ts
index ac1f497e..8a98b6cf 100644
--- a/packages/db/src/workspace.ts
+++ b/packages/db/src/workspace.ts
@@ -1,18 +1,7 @@
-import { asc, eq } from 'drizzle-orm';
+import { eq } from 'drizzle-orm';
import type { DbExecutor } from './client';
import { team, workspace, workspaceManager } from './schema';
-// The instance owner's workspace, the first one. Migration 0135 creates it.
-export async function instanceWorkspaceId(executor: DbExecutor): Promise<number> {
- const [row] = await executor
- .select({ id: workspace.id })
- .from(workspace)
- .orderBy(asc(workspace.id))
- .limit(1);
- if (!row) throw new Error('The instance has no workspace');
- return row.id;
-}
-
export async function teamWorkspaceId(teamId: number, executor: DbExecutor): Promise<number> {
const [row] = await executor
.select({ workspaceId: team.workspaceId })