cloudaxe-opencode/packages/console/core/src/schema/user.sql.ts

30 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2025-10-07 13:17:05 +00:00
import { mysqlTable, uniqueIndex, varchar, int, mysqlEnum, index, bigint } from "drizzle-orm/mysql-core"
2025-10-02 17:58:38 +00:00
import { timestamps, ulid, utc, workspaceColumns } from "../drizzle/types"
2025-08-08 17:22:54 +00:00
import { workspaceIndexes } from "./workspace.sql"
2025-09-29 18:17:53 +00:00
export const UserRole = ["admin", "member"] as const
2025-09-28 16:49:27 +00:00
2025-09-02 07:14:56 +00:00
export const UserTable = mysqlTable(
2025-08-08 17:22:54 +00:00
"user",
{
...workspaceColumns,
...timestamps,
2025-10-02 17:58:38 +00:00
accountID: ulid("account_id"),
2025-10-01 23:34:37 +00:00
email: varchar("email", { length: 255 }),
2025-08-08 17:22:54 +00:00
name: varchar("name", { length: 255 }).notNull(),
timeSeen: utc("time_seen"),
2025-09-02 07:14:56 +00:00
color: int("color"),
2025-09-29 18:17:53 +00:00
role: mysqlEnum("role", UserRole).notNull(),
2025-10-07 13:17:05 +00:00
monthlyLimit: int("monthly_limit"),
monthlyUsage: bigint("monthly_usage", { mode: "number" }),
timeMonthlyUsageUpdated: utc("time_monthly_usage_updated"),
2025-08-08 17:22:54 +00:00
},
2025-10-02 17:58:38 +00:00
(table) => [
...workspaceIndexes(table),
uniqueIndex("user_account_id").on(table.workspaceID, table.accountID),
uniqueIndex("user_email").on(table.workspaceID, table.email),
2025-10-02 22:42:52 +00:00
index("global_account_id").on(table.accountID),
index("global_email").on(table.email),
2025-10-02 17:58:38 +00:00
],
2025-08-08 17:22:54 +00:00
)