diff options
Diffstat (limited to 'packages/db/src')
| -rw-r--r-- | packages/db/src/index.ts | 32 | ||||
| -rw-r--r-- | packages/db/src/keys.ts | 30 | ||||
| -rw-r--r-- | packages/db/src/schema.ts | 106 |
3 files changed, 85 insertions, 83 deletions
diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 26b3116e..9b395ab6 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -8,12 +8,12 @@ const { DATABASE_URL } = keys(); let _db: ReturnType<typeof drizzle> | null = null; function getDb() { - if (!_db) { - const client = postgres(DATABASE_URL); - _db = drizzle(client, { schema }); - } + if (!_db) { + const client = postgres(DATABASE_URL); + _db = drizzle(client, { schema }); + } - return _db; + return _db; } // Export a proxy that forwards all calls to the actual db instance @@ -24,15 +24,15 @@ export * from "./schema"; // Re-export drizzle-orm functions to ensure version consistency export { - eq, - and, - or, - not, - isNull, - isNotNull, - inArray, - notInArray, - exists, - notExists, - sql, + eq, + and, + or, + not, + isNull, + isNotNull, + inArray, + notInArray, + exists, + notExists, + sql, } from "drizzle-orm"; diff --git a/packages/db/src/keys.ts b/packages/db/src/keys.ts index 49c682c0..65983416 100644 --- a/packages/db/src/keys.ts +++ b/packages/db/src/keys.ts @@ -2,18 +2,18 @@ import { createEnv } from "@t3-oss/env-nextjs"; import { z } from "zod"; export const keys = () => - createEnv({ - server: { - NODE_ENV: z - .enum(["development", "production", "test"]) - .default("development"), - DATABASE_URL: z - .string() - .startsWith("postgres://") - .or(z.string().startsWith("postgresql://")), - }, - runtimeEnv: { - NODE_ENV: process.env.NODE_ENV, - DATABASE_URL: process.env.DATABASE_URL, - }, - }); + createEnv({ + server: { + NODE_ENV: z + .enum(["development", "production", "test"]) + .default("development"), + DATABASE_URL: z + .string() + .startsWith("postgres://") + .or(z.string().startsWith("postgresql://")), + }, + runtimeEnv: { + NODE_ENV: process.env.NODE_ENV, + DATABASE_URL: process.env.DATABASE_URL, + }, + }); diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index aea5ec55..c4af608d 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -1,67 +1,69 @@ import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core"; export const users = pgTable("users", { - id: text("id").primaryKey(), - name: text("name").notNull(), - email: text("email").notNull().unique(), - emailVerified: boolean("email_verified").default(false).notNull(), - image: text("image"), - createdAt: timestamp("created_at") - .$defaultFn(() => /* @__PURE__ */ new Date()) - .notNull(), - updatedAt: timestamp("updated_at") - .$defaultFn(() => /* @__PURE__ */ new Date()) - .notNull(), + id: text("id").primaryKey(), + name: text("name").notNull(), + email: text("email").notNull().unique(), + emailVerified: boolean("email_verified") + .default(false) + .notNull(), + image: text("image"), + createdAt: timestamp("created_at") + .$defaultFn(() => /* @__PURE__ */ new Date()) + .notNull(), + updatedAt: timestamp("updated_at") + .$defaultFn(() => /* @__PURE__ */ new Date()) + .notNull(), }).enableRLS(); export const sessions = pgTable("sessions", { - id: text("id").primaryKey(), - expiresAt: timestamp("expires_at").notNull(), - token: text("token").notNull().unique(), - createdAt: timestamp("created_at").notNull(), - updatedAt: timestamp("updated_at").notNull(), - ipAddress: text("ip_address"), - userAgent: text("user_agent"), - userId: text("user_id") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), + id: text("id").primaryKey(), + expiresAt: timestamp("expires_at").notNull(), + token: text("token").notNull().unique(), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), + ipAddress: text("ip_address"), + userAgent: text("user_agent"), + userId: text("user_id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), }).enableRLS(); export const accounts = pgTable("accounts", { - id: text("id").primaryKey(), - accountId: text("account_id").notNull(), - providerId: text("provider_id").notNull(), - userId: text("user_id") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - accessToken: text("access_token"), - refreshToken: text("refresh_token"), - idToken: text("id_token"), - accessTokenExpiresAt: timestamp("access_token_expires_at"), - refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), - scope: text("scope"), - password: text("password"), - createdAt: timestamp("created_at").notNull(), - updatedAt: timestamp("updated_at").notNull(), + id: text("id").primaryKey(), + accountId: text("account_id").notNull(), + providerId: text("provider_id").notNull(), + userId: text("user_id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + accessToken: text("access_token"), + refreshToken: text("refresh_token"), + idToken: text("id_token"), + accessTokenExpiresAt: timestamp("access_token_expires_at"), + refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), + scope: text("scope"), + password: text("password"), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), }).enableRLS(); export const verifications = pgTable("verifications", { - id: text("id").primaryKey(), - identifier: text("identifier").notNull(), - value: text("value").notNull(), - expiresAt: timestamp("expires_at").notNull(), - createdAt: timestamp("created_at").$defaultFn( - () => /* @__PURE__ */ new Date(), - ), - updatedAt: timestamp("updated_at").$defaultFn( - () => /* @__PURE__ */ new Date(), - ), + id: text("id").primaryKey(), + identifier: text("identifier").notNull(), + value: text("value").notNull(), + expiresAt: timestamp("expires_at").notNull(), + createdAt: timestamp("created_at").$defaultFn( + () => /* @__PURE__ */ new Date() + ), + updatedAt: timestamp("updated_at").$defaultFn( + () => /* @__PURE__ */ new Date() + ), }).enableRLS(); export const waitlist = pgTable("waitlist", { - id: text("id").primaryKey(), - email: text("email").notNull().unique(), - createdAt: timestamp("created_at") - .$defaultFn(() => /* @__PURE__ */ new Date()) - .notNull(), -}).enableRLS(); + id: text("id").primaryKey(), + email: text("email").notNull().unique(), + createdAt: timestamp("created_at") + .$defaultFn(() => /* @__PURE__ */ new Date()) + .notNull(), +}).enableRLS();
\ No newline at end of file |
