⭐️⭐️⭐️ 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.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
import { eq } from 'drizzle-orm';
import type { DbExecutor } from './client';
import { team, workspace, workspaceManager } from './schema';
export async function teamWorkspaceId(teamId: number, executor: DbExecutor): Promise<number> {
const [row] = await executor
.select({ workspaceId: team.workspaceId })
.from(team)
.where(eq(team.id, teamId));
if (!row) throw new Error(`Team ${teamId} does not exist`);
return row.workspaceId;
}
// A workspace with `ownerId` as its owner. Run it in a transaction so neither row is
// written without the other.
export async function createWorkspace(
executor: DbExecutor,
name: string,
ownerId: string,
): Promise<number> {
const [row] = await executor.insert(workspace).values({ name }).returning({ id: workspace.id });
await executor
.insert(workspaceManager)
.values({ workspaceId: row!.id, userId: ownerId, role: 'owner' });
return row!.id;
}