summaryrefslogtreecommitdiff
path: root/packages/db/src
diff options
context:
space:
mode:
authorHyteq <DerpsDer.es@gmail.com>2025-07-20 10:48:40 +0300
committerHyteq <DerpsDer.es@gmail.com>2025-07-20 10:48:40 +0300
commiteab8ec3ba81b86fdd4ade920d999c28fb34785b1 (patch)
tree619fc6930f50fa36d6f1f94ee81fb8bf6d4bedef /packages/db/src
parentd040ca53cb4029c9c58bd7e6b6dfd1eed2694b31 (diff)
downloadopencut-eab8ec3ba81b86fdd4ade920d999c28fb34785b1.tar.gz
format, cleanup, deps
Diffstat (limited to 'packages/db/src')
-rw-r--r--packages/db/src/index.ts32
-rw-r--r--packages/db/src/keys.ts30
-rw-r--r--packages/db/src/schema.ts106
3 files changed, 83 insertions, 85 deletions
diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts
index 9b395ab6..26b3116e 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 65983416..49c682c0 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 c4af608d..aea5ec55 100644
--- a/packages/db/src/schema.ts
+++ b/packages/db/src/schema.ts
@@ -1,69 +1,67 @@
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(); \ No newline at end of file
+ id: text("id").primaryKey(),
+ email: text("email").notNull().unique(),
+ createdAt: timestamp("created_at")
+ .$defaultFn(() => /* @__PURE__ */ new Date())
+ .notNull(),
+}).enableRLS();