Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/mail/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export default {
},
out: './db/migrations',
tablesFilter: ['mail0_*'],
casing: 'snake_case',
} satisfies Config;
11 changes: 6 additions & 5 deletions packages/db/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 5 additions & 5 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 });
export const db = drizzle(conn, { schema, casing: 'snake_case' });
156 changes: 78 additions & 78 deletions packages/db/src/schema.ts
Original file line number Diff line number Diff line change
@@ -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(),
});