diff options
| author | Maze <167211895+mazeincoding@users.noreply.github.com> | 2026-01-31 00:20:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-31 00:20:04 +0100 |
| commit | 7bf0984698e43b9aa2dd879f65951318ed410390 (patch) | |
| tree | ccf2cd590a47d550152afc07129cb55c71a9ec35 /packages/db/src | |
| parent | 0173db99448d1c4c6415dcf15272e17551b48b04 (diff) | |
| download | opencut-7bf0984698e43b9aa2dd879f65951318ed410390.tar.gz | |
codebase overhaul (#697)
Diffstat (limited to 'packages/db/src')
| -rw-r--r-- | packages/db/src/index.ts | 38 | ||||
| -rw-r--r-- | packages/db/src/keys.ts | 19 | ||||
| -rw-r--r-- | packages/db/src/schema.ts | 70 |
3 files changed, 0 insertions, 127 deletions
diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts deleted file mode 100644 index 9b395ab6..00000000 --- a/packages/db/src/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { drizzle } from "drizzle-orm/postgres-js"; -import postgres from "postgres"; -import * as schema from "./schema"; -import { keys } from "./keys"; - -const { DATABASE_URL } = keys(); -// Create a lazy database instance that only initializes when accessed -let _db: ReturnType<typeof drizzle> | null = null; - -function getDb() { - if (!_db) { - const client = postgres(DATABASE_URL); - _db = drizzle(client, { schema }); - } - - return _db; -} - -// Export a proxy that forwards all calls to the actual db instance -export const db = getDb(); - -// Re-export schema for convenience -export * from "./schema"; - -// Re-export drizzle-orm functions to ensure version consistency -export { - 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 deleted file mode 100644 index 65983416..00000000 --- a/packages/db/src/keys.ts +++ /dev/null @@ -1,19 +0,0 @@ -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, - }, - }); diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts deleted file mode 100644 index a1a69e6d..00000000 --- a/packages/db/src/schema.ts +++ /dev/null @@ -1,70 +0,0 @@ -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(), -}).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" }), -}).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(), -}).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() - ), -}).enableRLS(); - -export const exportWaitlist = pgTable("export_waitlist", { - id: text("id").primaryKey(), - email: text("email").notNull().unique(), - createdAt: timestamp("created_at") - .$defaultFn(() => /* @__PURE__ */ new Date()) - .notNull(), - updatedAt: timestamp("updated_at") - .$defaultFn(() => /* @__PURE__ */ new Date()) - .notNull(), -}).enableRLS(); |
