diff --git a/apps/mail/drizzle.config.ts b/apps/mail/drizzle.config.ts index 4735656a74..4e245a940e 100644 --- a/apps/mail/drizzle.config.ts +++ b/apps/mail/drizzle.config.ts @@ -8,4 +8,5 @@ export default { }, out: './db/migrations', tablesFilter: ['mail0_*'], + casing: 'snake_case', } satisfies Config; diff --git a/packages/db/drizzle.config.ts b/packages/db/drizzle.config.ts index 1fec539c0b..494ee08699 100644 --- a/packages/db/drizzle.config.ts +++ b/packages/db/drizzle.config.ts @@ -1,11 +1,12 @@ -import { type Config } from "drizzle-kit"; +import { type Config } from 'drizzle-kit'; export default { - schema: "./src/schema.ts", - dialect: "postgresql", + schema: './src/schema.ts', + dialect: 'postgresql', dbCredentials: { url: process.env.DATABASE_URL!, }, - out: "./migrations", - tablesFilter: ["mail0_*"], + out: './migrations', + tablesFilter: ['mail0_*'], + casing: 'snake_case', } satisfies Config; diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 6b19faf1e1..758d41b5fd 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -1,7 +1,7 @@ -import { drizzle } from "drizzle-orm/postgres-js"; -import postgres from "postgres"; +import { drizzle } from 'drizzle-orm/postgres-js'; +import postgres from 'postgres'; -import * as schema from "./schema"; +import * as schema from './schema'; /** * Cache the database connection in development. This avoids creating a new connection on every HMR @@ -12,6 +12,6 @@ const globalForDb = globalThis as unknown as { }; const conn = globalForDb.conn ?? postgres(process.env.DATABASE_URL!); -if (process.env.NODE_ENV !== "production") globalForDb.conn = conn; +if (process.env.NODE_ENV !== 'production') globalForDb.conn = conn; -export const db = drizzle(conn, { schema }); \ No newline at end of file +export const db = drizzle(conn, { schema, casing: 'snake_case' }); diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index a829cf1a47..a95116ba99 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -1,103 +1,103 @@ -import { pgTableCreator, text, timestamp, boolean, integer } from "drizzle-orm/pg-core"; +import { pgTableCreator, text, timestamp, boolean, integer } from 'drizzle-orm/pg-core'; export const createTable = pgTableCreator((name) => `mail0_${name}`); -export const user = createTable("user", { - id: text("id").primaryKey(), - name: text("name").notNull(), - email: text("email").notNull().unique(), - emailVerified: boolean("email_verified").notNull(), - image: text("image"), - createdAt: timestamp("created_at").notNull(), - updatedAt: timestamp("updated_at").notNull(), - defaultConnectionId: text("default_connection_id"), +export const user = createTable('user', { + id: text().primaryKey(), + name: text().notNull(), + email: text().notNull().unique(), + emailVerified: boolean().notNull(), + image: text(), + createdAt: timestamp().notNull(), + updatedAt: timestamp().notNull(), + defaultConnectionId: text(), }); -export const session = createTable("session", { - 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") +export const session = createTable('session', { + id: text().primaryKey(), + expiresAt: timestamp().notNull(), + token: text().notNull().unique(), + createdAt: timestamp().notNull(), + updatedAt: timestamp().notNull(), + ipAddress: text(), + userAgent: text(), + userId: text() .notNull() .references(() => user.id), }); -export const account = createTable("account", { - id: text("id").primaryKey(), - accountId: text("account_id").notNull(), - providerId: text("provider_id").notNull(), - userId: text("user_id") +export const account = createTable('account', { + id: text().primaryKey(), + accountId: text().notNull(), + providerId: text().notNull(), + userId: text() .notNull() .references(() => user.id), - 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(), + accessToken: text(), + refreshToken: text(), + idToken: text(), + accessTokenExpiresAt: timestamp(), + refreshTokenExpiresAt: timestamp(), + scope: text(), + password: text(), + createdAt: timestamp().notNull(), + updatedAt: timestamp().notNull(), }); -export const verification = createTable("verification", { - id: text("id").primaryKey(), - identifier: text("identifier").notNull(), - value: text("value").notNull(), - expiresAt: timestamp("expires_at").notNull(), - createdAt: timestamp("created_at"), - updatedAt: timestamp("updated_at"), +export const verification = createTable('verification', { + id: text().primaryKey(), + identifier: text().notNull(), + value: text().notNull(), + expiresAt: timestamp().notNull(), + createdAt: timestamp(), + updatedAt: timestamp(), }); -export const earlyAccess = createTable("early_access", { - id: text("id").primaryKey(), - email: text("email").notNull().unique(), - createdAt: timestamp("created_at").notNull(), - updatedAt: timestamp("updated_at").notNull(), +export const earlyAccess = createTable('early_access', { + id: text().primaryKey(), + email: text().notNull().unique(), + createdAt: timestamp().notNull(), + updatedAt: timestamp().notNull(), }); -export const connection = createTable("connection", { - id: text("id").primaryKey(), - userId: text("user_id") +export const connection = createTable('connection', { + id: text().primaryKey(), + userId: text() .notNull() .references(() => user.id), - email: text("email").notNull().unique(), - name: text("name"), - picture: text("picture"), - accessToken: text("access_token").notNull(), - refreshToken: text("refresh_token"), - scope: text("scope").notNull(), - providerId: text("provider_id").notNull(), - expiresAt: timestamp("expires_at").notNull(), - createdAt: timestamp("created_at").notNull(), - updatedAt: timestamp("updated_at").notNull(), + email: text().notNull().unique(), + name: text(), + picture: text(), + accessToken: text().notNull(), + refreshToken: text(), + scope: text().notNull(), + providerId: text().notNull(), + expiresAt: timestamp().notNull(), + createdAt: timestamp().notNull(), + updatedAt: timestamp().notNull(), }); -export const summary = createTable("summary", { - messageId: text("message_id").primaryKey(), - content: text("content").notNull(), - createdAt: timestamp("created_at").notNull(), - updatedAt: timestamp("updated_at").notNull(), - connectionId: text("connection_id").notNull(), - saved: boolean("saved").notNull().default(false), - tags: text("tags"), - suggestedReply: text("suggested_reply") +export const summary = createTable('summary', { + messageId: text().primaryKey(), + content: text().notNull(), + createdAt: timestamp().notNull(), + updatedAt: timestamp().notNull(), + connectionId: text().notNull(), + saved: boolean().notNull().default(false), + tags: text(), + suggestedReply: text(), }); -export const note = createTable("note", { - id: text("id").primaryKey(), - userId: text("user_id") +export const note = createTable('note', { + id: text().primaryKey(), + userId: text() .notNull() - .references(() => user.id, { onDelete: "cascade" }), - threadId: text("thread_id").notNull(), - content: text("content").notNull(), - color: text("color").notNull().default("default"), - isPinned: boolean("is_pinned").default(false), - order: integer("order").notNull().default(0), - createdAt: timestamp("created_at").notNull().defaultNow(), - updatedAt: timestamp("updated_at").notNull().defaultNow(), + .references(() => user.id, { onDelete: 'cascade' }), + threadId: text().notNull(), + content: text().notNull(), + color: text().notNull().default('default'), + isPinned: boolean().default(false), + order: integer().notNull().default(0), + createdAt: timestamp().notNull().defaultNow(), + updatedAt: timestamp().notNull().defaultNow(), });