The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { defineRelationsPart } from "drizzle-orm"; |
| 2 | import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core"; |
| 3 | |
| 4 | export const user = sqliteTable("user", { |
| 5 | id: text("id").primaryKey(), |
| 6 | name: text("name").notNull(), |
| 7 | email: text("email").notNull().unique(), |
| 8 | emailVerified: integer("email_verified", { mode: "boolean" }).default(false).notNull(), |
| 9 | image: text("image"), |
| 10 | createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(), |
| 11 | updatedAt: integer("updated_at", { mode: "timestamp_ms" }) |
| 12 | .$onUpdate(() => new Date()) |
| 13 | .notNull(), |
| 14 | }); |
| 15 | |
| 16 | export const session = sqliteTable( |
| 17 | "session", |
| 18 | { |
| 19 | id: text("id").primaryKey(), |
| 20 | expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(), |
| 21 | token: text("token").notNull().unique(), |
| 22 | createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(), |
| 23 | updatedAt: integer("updated_at", { mode: "timestamp_ms" }) |
| 24 | .$onUpdate(() => new Date()) |
| 25 | .notNull(), |
| 26 | ipAddress: text("ip_address"), |
| 27 | userAgent: text("user_agent"), |
| 28 | userId: text("user_id") |
| 29 | .notNull() |
| 30 | .references(() => user.id, { onDelete: "cascade" }), |
| 31 | }, |
| 32 | (table) => [index("session_userId_idx").on(table.userId)], |
| 33 | ); |
| 34 | |
| 35 | export const account = sqliteTable( |
| 36 | "account", |
| 37 | { |
| 38 | id: text("id").primaryKey(), |
| 39 | accountId: text("account_id").notNull(), |
| 40 | providerId: text("provider_id").notNull(), |
| 41 | userId: text("user_id") |
| 42 | .notNull() |
| 43 | .references(() => user.id, { onDelete: "cascade" }), |
| 44 | accessToken: text("access_token"), |
| 45 | refreshToken: text("refresh_token"), |
| 46 | idToken: text("id_token"), |
| 47 | accessTokenExpiresAt: integer("access_token_expires_at", { |
| 48 | mode: "timestamp_ms", |
| 49 | }), |
| 50 | refreshTokenExpiresAt: integer("refresh_token_expires_at", { |
| 51 | mode: "timestamp_ms", |
| 52 | }), |
| 53 | scope: text("scope"), |
| 54 | password: text("password"), |
| 55 | createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(), |
| 56 | updatedAt: integer("updated_at", { mode: "timestamp_ms" }) |
| 57 | .$onUpdate(() => new Date()) |
| 58 | .notNull(), |
| 59 | }, |
| 60 | (table) => [index("account_userId_idx").on(table.userId)], |
| 61 | ); |
| 62 | |
| 63 | export const verification = sqliteTable( |
| 64 | "verification", |
| 65 | { |
| 66 | id: text("id").primaryKey(), |
| 67 | identifier: text("identifier").notNull(), |
| 68 | value: text("value").notNull(), |
| 69 | expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(), |
| 70 | createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(), |
| 71 | updatedAt: integer("updated_at", { mode: "timestamp_ms" }) |
| 72 | .$onUpdate(() => new Date()) |
| 73 | .notNull(), |
| 74 | }, |
| 75 | (table) => [index("verification_identifier_idx").on(table.identifier)], |
| 76 | ); |
| 77 | |
| 78 | export const authRelations = defineRelationsPart({ user, session, account, verification }, (r) => ({ |
| 79 | user: { |
| 80 | sessions: r.many.session({ |
| 81 | from: r.user.id, |
| 82 | to: r.session.userId, |
| 83 | }), |
| 84 | accounts: r.many.account({ |
| 85 | from: r.user.id, |
| 86 | to: r.account.userId, |
| 87 | }), |
| 88 | }, |
| 89 | session: { |
| 90 | user: r.one.user({ |
| 91 | from: r.session.userId, |
| 92 | to: r.user.id, |
| 93 | }), |
| 94 | }, |
| 95 | account: { |
| 96 | user: r.one.user({ |
| 97 | from: r.account.userId, |
| 98 | to: r.user.id, |
| 99 | }), |
| 100 | }, |
| 101 | })); |