diff options
| author | Frank <[email protected]> | 2025-09-28 12:49:27 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-09-28 12:49:28 -0400 |
| commit | 06495ea9640d5e72fc9d418e56c70c5ab19fc41b (patch) | |
| tree | 48c29dd99d614422ae7bb777c6cf4d21870d8c7e /packages/console/core/src | |
| parent | b64cecb07956c77be0456eb9a5018c463d09e77d (diff) | |
| download | opencode-06495ea9640d5e72fc9d418e56c70c5ab19fc41b.tar.gz opencode-06495ea9640d5e72fc9d418e56c70c5ab19fc41b.zip | |
wip: zen
Diffstat (limited to 'packages/console/core/src')
| -rw-r--r-- | packages/console/core/src/actor.ts | 2 | ||||
| -rw-r--r-- | packages/console/core/src/schema/user.sql.ts | 7 | ||||
| -rw-r--r-- | packages/console/core/src/workspace.ts | 19 |
3 files changed, 11 insertions, 17 deletions
diff --git a/packages/console/core/src/actor.ts b/packages/console/core/src/actor.ts index 0d13f7216..9f2216f9c 100644 --- a/packages/console/core/src/actor.ts +++ b/packages/console/core/src/actor.ts @@ -1,4 +1,5 @@ import { Context } from "./context" +import { UserRole } from "./schema/user.sql" import { Log } from "./util/log" export namespace Actor { @@ -20,6 +21,7 @@ export namespace Actor { properties: { userID: string workspaceID: string + role: UserRole } } diff --git a/packages/console/core/src/schema/user.sql.ts b/packages/console/core/src/schema/user.sql.ts index 00c372d1a..7f051a614 100644 --- a/packages/console/core/src/schema/user.sql.ts +++ b/packages/console/core/src/schema/user.sql.ts @@ -1,7 +1,10 @@ -import { text, mysqlTable, uniqueIndex, varchar, int } from "drizzle-orm/mysql-core" +import { mysqlTable, uniqueIndex, varchar, int, mysqlEnum } from "drizzle-orm/mysql-core" import { timestamps, utc, workspaceColumns } from "../drizzle/types" import { workspaceIndexes } from "./workspace.sql" +const UserRole = ["admin", "member"] as const +export type UserRole = (typeof UserRole)[number] + export const UserTable = mysqlTable( "user", { @@ -10,7 +13,9 @@ export const UserTable = mysqlTable( email: varchar("email", { length: 255 }).notNull(), name: varchar("name", { length: 255 }).notNull(), timeSeen: utc("time_seen"), + timeJoined: utc("time_joined"), color: int("color"), + role: mysqlEnum("role", ["admin", "member"]), }, (table) => [...workspaceIndexes(table), uniqueIndex("user_email").on(table.workspaceID, table.email)], ) diff --git a/packages/console/core/src/workspace.ts b/packages/console/core/src/workspace.ts index 79959f708..5067803ee 100644 --- a/packages/console/core/src/workspace.ts +++ b/packages/console/core/src/workspace.ts @@ -1,7 +1,7 @@ import { z } from "zod" import { fn } from "./util/fn" import { Actor } from "./actor" -import { Database, eq } from "./drizzle" +import { Database, sql } from "./drizzle" import { Identifier } from "./identifier" import { UserTable } from "./schema/user.sql" import { BillingTable } from "./schema/billing.sql" @@ -21,6 +21,8 @@ export namespace Workspace { id: Identifier.create("user"), email: account.properties.email, name: "", + role: "admin", + timeJoined: sql`now()`, }) await tx.insert(BillingTable).values({ workspaceID, @@ -39,19 +41,4 @@ export namespace Workspace { ) return workspaceID }) - - export async function list() { - const account = Actor.assert("account") - return Database.use(async (tx) => { - return tx - .select({ - id: WorkspaceTable.id, - slug: WorkspaceTable.slug, - name: WorkspaceTable.name, - }) - .from(UserTable) - .innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id)) - .where(eq(UserTable.email, account.properties.email)) - }) - } } |
