diff options
| author | Frank <[email protected]> | 2025-09-18 10:59:01 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-09-18 10:59:01 -0400 |
| commit | 4ceabdffa07b1af8d99eb73622a4d549d99ec6d2 (patch) | |
| tree | 72e2ae62084a9e24cc76caffbd1f30dafc69ea56 /packages/console/core/src/schema | |
| parent | c87480cf931a6f8f8b55552558ef521f1918b578 (diff) | |
| download | opencode-4ceabdffa07b1af8d99eb73622a4d549d99ec6d2.tar.gz opencode-4ceabdffa07b1af8d99eb73622a4d549d99ec6d2.zip | |
wip: zen
Diffstat (limited to 'packages/console/core/src/schema')
| -rw-r--r-- | packages/console/core/src/schema/account.sql.ts | 12 | ||||
| -rw-r--r-- | packages/console/core/src/schema/billing.sql.ts | 53 | ||||
| -rw-r--r-- | packages/console/core/src/schema/key.sql.ts | 22 | ||||
| -rw-r--r-- | packages/console/core/src/schema/user.sql.ts | 16 | ||||
| -rw-r--r-- | packages/console/core/src/schema/workspace.sql.ts | 21 |
5 files changed, 124 insertions, 0 deletions
diff --git a/packages/console/core/src/schema/account.sql.ts b/packages/console/core/src/schema/account.sql.ts new file mode 100644 index 000000000..4d9937114 --- /dev/null +++ b/packages/console/core/src/schema/account.sql.ts @@ -0,0 +1,12 @@ +import { mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core" +import { id, timestamps } from "../drizzle/types" + +export const AccountTable = mysqlTable( + "account", + { + id: id(), + ...timestamps, + email: varchar("email", { length: 255 }).notNull(), + }, + (table) => [uniqueIndex("email").on(table.email)], +) diff --git a/packages/console/core/src/schema/billing.sql.ts b/packages/console/core/src/schema/billing.sql.ts new file mode 100644 index 000000000..5bec4e900 --- /dev/null +++ b/packages/console/core/src/schema/billing.sql.ts @@ -0,0 +1,53 @@ +import { bigint, boolean, int, mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core" +import { timestamps, utc, workspaceColumns } from "../drizzle/types" +import { workspaceIndexes } from "./workspace.sql" + +export const BillingTable = mysqlTable( + "billing", + { + ...workspaceColumns, + ...timestamps, + customerID: varchar("customer_id", { length: 255 }), + paymentMethodID: varchar("payment_method_id", { length: 255 }), + paymentMethodLast4: varchar("payment_method_last4", { length: 4 }), + balance: bigint("balance", { mode: "number" }).notNull(), + monthlyLimit: int("monthly_limit"), + monthlyUsage: bigint("monthly_usage", { mode: "number" }), + timeMonthlyUsageUpdated: utc("time_monthly_usage_updated"), + reload: boolean("reload"), + reloadError: varchar("reload_error", { length: 255 }), + timeReloadError: utc("time_reload_error"), + timeReloadLockedTill: utc("time_reload_locked_till"), + }, + (table) => [...workspaceIndexes(table), uniqueIndex("global_customer_id").on(table.customerID)], +) + +export const PaymentTable = mysqlTable( + "payment", + { + ...workspaceColumns, + ...timestamps, + customerID: varchar("customer_id", { length: 255 }), + paymentID: varchar("payment_id", { length: 255 }), + amount: bigint("amount", { mode: "number" }).notNull(), + }, + (table) => [...workspaceIndexes(table)], +) + +export const UsageTable = mysqlTable( + "usage", + { + ...workspaceColumns, + ...timestamps, + model: varchar("model", { length: 255 }).notNull(), + provider: varchar("provider", { length: 255 }).notNull(), + inputTokens: int("input_tokens").notNull(), + outputTokens: int("output_tokens").notNull(), + reasoningTokens: int("reasoning_tokens"), + cacheReadTokens: int("cache_read_tokens"), + cacheWrite5mTokens: int("cache_write_5m_tokens"), + cacheWrite1hTokens: int("cache_write_1h_tokens"), + cost: bigint("cost", { mode: "number" }).notNull(), + }, + (table) => [...workspaceIndexes(table)], +) diff --git a/packages/console/core/src/schema/key.sql.ts b/packages/console/core/src/schema/key.sql.ts new file mode 100644 index 000000000..98b99c788 --- /dev/null +++ b/packages/console/core/src/schema/key.sql.ts @@ -0,0 +1,22 @@ +import { mysqlTable, varchar, uniqueIndex, json } from "drizzle-orm/mysql-core" +import { timestamps, utc, workspaceColumns } from "../drizzle/types" +import { workspaceIndexes } from "./workspace.sql" +import { Actor } from "../actor" + +export const KeyTable = mysqlTable( + "key", + { + ...workspaceColumns, + ...timestamps, + actor: json("actor").$type<Actor.Info>(), + name: varchar("name", { length: 255 }).notNull(), + oldName: varchar("old_name", { length: 255 }), + key: varchar("key", { length: 255 }).notNull(), + timeUsed: utc("time_used"), + }, + (table) => [ + ...workspaceIndexes(table), + uniqueIndex("global_key").on(table.key), + uniqueIndex("name").on(table.workspaceID, table.name), + ], +) diff --git a/packages/console/core/src/schema/user.sql.ts b/packages/console/core/src/schema/user.sql.ts new file mode 100644 index 000000000..00c372d1a --- /dev/null +++ b/packages/console/core/src/schema/user.sql.ts @@ -0,0 +1,16 @@ +import { text, mysqlTable, uniqueIndex, varchar, int } from "drizzle-orm/mysql-core" +import { timestamps, utc, workspaceColumns } from "../drizzle/types" +import { workspaceIndexes } from "./workspace.sql" + +export const UserTable = mysqlTable( + "user", + { + ...workspaceColumns, + ...timestamps, + email: varchar("email", { length: 255 }).notNull(), + name: varchar("name", { length: 255 }).notNull(), + timeSeen: utc("time_seen"), + color: int("color"), + }, + (table) => [...workspaceIndexes(table), uniqueIndex("user_email").on(table.workspaceID, table.email)], +) diff --git a/packages/console/core/src/schema/workspace.sql.ts b/packages/console/core/src/schema/workspace.sql.ts new file mode 100644 index 000000000..979255428 --- /dev/null +++ b/packages/console/core/src/schema/workspace.sql.ts @@ -0,0 +1,21 @@ +import { primaryKey, mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core" +import { timestamps, ulid } from "../drizzle/types" + +export const WorkspaceTable = mysqlTable( + "workspace", + { + id: ulid("id").notNull().primaryKey(), + slug: varchar("slug", { length: 255 }), + name: varchar("name", { length: 255 }), + ...timestamps, + }, + (table) => [uniqueIndex("slug").on(table.slug)], +) + +export function workspaceIndexes(table: any) { + return [ + primaryKey({ + columns: [table.workspaceID, table.id], + }), + ] +} |
