diff --git a/apps/mail/app/api/auth/early-access/route.ts b/apps/mail/app/api/auth/early-access/route.ts index 002c252bfa..683449f2fb 100644 --- a/apps/mail/app/api/auth/early-access/route.ts +++ b/apps/mail/app/api/auth/early-access/route.ts @@ -1,8 +1,8 @@ -import { type NextRequest, NextResponse } from 'next/server'; -import { Ratelimit } from '@upstash/ratelimit'; -import { earlyAccess } from '@zero/db/schema'; -import { redis } from '@/lib/redis'; -import { db } from '@zero/db'; +import { type NextRequest, NextResponse } from "next/server"; +import { Ratelimit } from "@upstash/ratelimit"; +import { earlyAccess } from "@zero/db/schema"; +import { redis } from "@/lib/redis"; +import { db } from "@zero/db"; type PostgresError = { code: string; @@ -11,9 +11,9 @@ type PostgresError = { const ratelimit = new Ratelimit({ redis, - limiter: Ratelimit.slidingWindow(2, '30m'), + limiter: Ratelimit.slidingWindow(2, "30m"), analytics: true, - prefix: 'ratelimit:early-access', + prefix: "ratelimit:early-access", }); function isEmail(email: string): boolean { @@ -22,7 +22,7 @@ function isEmail(email: string): boolean { } const emailRegex = new RegExp( - /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, + /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ); return emailRegex.test(email); @@ -30,90 +30,86 @@ function isEmail(email: string): boolean { export async function POST(req: NextRequest) { try { - const ip = req.headers.get('CF-Connecting-IP'); + const ip = req.headers.get("CF-Connecting-IP"); if (!ip) { - console.log('No IP detected'); - return NextResponse.json({ error: 'No IP detected' }, { status: 400 }); + console.log("No IP detected"); + return NextResponse.json({ error: "No IP detected" }, { status: 400 }); } - console.log( - 'Request from IP:', - ip, - req.headers.get('x-forwarded-for'), - req.headers.get('CF-Connecting-IP'), - ); + console.log("Request from IP:", ip, req.headers.get("x-forwarded-for"), req.headers.get('CF-Connecting-IP')); const { success, limit, reset, remaining } = await ratelimit.limit(ip); const headers = { - 'X-RateLimit-Limit': limit.toString(), - 'X-RateLimit-Remaining': remaining.toString(), - 'X-RateLimit-Reset': reset.toString(), + "X-RateLimit-Limit": limit.toString(), + "X-RateLimit-Remaining": remaining.toString(), + "X-RateLimit-Reset": reset.toString(), }; if (!success) { console.log(`Rate limit exceeded for IP ${ip}. Remaining: ${remaining}`); return NextResponse.json( - { error: 'Too many requests. Please try again later.' }, + { error: "Too many requests. Please try again later." }, { status: 429, headers }, ); } const body = await req.json(); - console.log('Request body:', body); + console.log("Request body:", body); const { email } = body; if (!email) { - console.log('Email missing from request'); - return NextResponse.json({ error: 'Email is required' }, { status: 400 }); + console.log("Email missing from request"); + return NextResponse.json({ error: "Email is required" }, { status: 400 }); } if (!isEmail(email)) { - console.log('Invalid email format'); - return NextResponse.json({ error: 'Invalid email format' }, { status: 400 }); + console.log("Invalid email format"); + return NextResponse.json({ error: "Invalid email format" }, { status: 400 }); } const nowDate = new Date(); try { - console.log('Attempting to insert email:', email); + console.log("Attempting to insert email:", email); const result = await db.insert(earlyAccess).values({ + id: crypto.randomUUID(), email, createdAt: nowDate, updatedAt: nowDate, }); - console.log('Insert successful:', result); + console.log("Insert successful:", result); return NextResponse.json( - { message: 'Successfully joined early access' }, + { message: "Successfully joined early access" }, { status: 201, headers: { - 'X-RateLimit-Limit': limit.toString(), - 'X-RateLimit-Remaining': remaining.toString(), - 'X-RateLimit-Reset': reset.toString(), + "X-RateLimit-Limit": limit.toString(), + "X-RateLimit-Remaining": remaining.toString(), + "X-RateLimit-Reset": reset.toString(), }, }, ); } catch (err) { const pgError = err as PostgresError; - console.error('Database error:', { + console.error("Database error:", { code: pgError.code, message: pgError.message, fullError: err, }); - if (pgError.code === '23505') { + if (pgError.code === "23505") { // Return 200 for existing emails return NextResponse.json( - { message: 'Email already registered for early access' }, + { message: "Email already registered for early access" }, { status: 200, headers: { - 'X-RateLimit-Limit': limit.toString(), - 'X-RateLimit-Remaining': remaining.toString(), - 'X-RateLimit-Reset': reset.toString(), + "X-RateLimit-Limit": limit.toString(), + "X-RateLimit-Remaining": remaining.toString(), + "X-RateLimit-Reset": reset.toString(), }, }, ); @@ -124,21 +120,21 @@ export async function POST(req: NextRequest) { // This line is now unreachable due to the returns in the try/catch above } catch (error) { - console.error('Early access registration error:', { + console.error("Early access registration error:", { error, stack: error instanceof Error ? error.stack : undefined, }); - if (process.env.NODE_ENV === 'development') { + if (process.env.NODE_ENV === "development") { return NextResponse.json( { - error: 'Internal server error', + error: "Internal server error", details: error instanceof Error ? error.message : String(error), }, { status: 500 }, ); } - return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); + return NextResponse.json({ error: "Internal server error" }, { status: 500 }); } } diff --git a/apps/mail/app/api/notes/db.ts b/apps/mail/app/api/notes/db.ts index 7361abffa0..ce729494fe 100644 --- a/apps/mail/app/api/notes/db.ts +++ b/apps/mail/app/api/notes/db.ts @@ -1,7 +1,7 @@ -import { eq, and, desc, asc, sql } from 'drizzle-orm'; -import type { Note, NotesManager } from './types'; -import { note } from '@zero/db/schema'; -import { db } from '@zero/db'; +import { eq, and, desc, asc, sql } from "drizzle-orm"; +import { db } from "@zero/db"; +import { note } from "@zero/db/schema"; +import type { Note, NotesManager } from "./types"; export const notesManager: NotesManager = { async getNotes(userId: string): Promise { @@ -24,8 +24,8 @@ export const notesManager: NotesManager = { userId: string, threadId: string, content: string, - color: string = 'default', - isPinned: boolean = false, + color: string = "default", + isPinned: boolean = false ): Promise { const userNotes = await db .select() @@ -34,10 +34,11 @@ export const notesManager: NotesManager = { .orderBy(desc(note.order)); const highestOrder = userNotes[0]?.order ?? -1; - + const result = await db .insert(note) .values({ + id: sql`gen_random_uuid()`, userId, threadId, content, @@ -48,7 +49,7 @@ export const notesManager: NotesManager = { .returning(); if (!result[0]) { - throw new Error('Failed to create note'); + throw new Error("Failed to create note"); } return result[0]; }, @@ -56,7 +57,7 @@ export const notesManager: NotesManager = { async updateNote( userId: string, noteId: string, - data: Partial>, + data: Partial> ): Promise { const existingNote = await db .select() @@ -65,7 +66,7 @@ export const notesManager: NotesManager = { .limit(1); if (existingNote.length === 0) { - throw new Error('Note not found or unauthorized'); + throw new Error("Note not found or unauthorized"); } const result = await db @@ -78,7 +79,7 @@ export const notesManager: NotesManager = { .returning(); if (!result[0]) { - throw new Error('Failed to update note'); + throw new Error("Failed to update note"); } return result[0]; }, @@ -91,68 +92,66 @@ export const notesManager: NotesManager = { .limit(1); if (existingNote.length === 0) { - throw new Error('Note not found or unauthorized'); + throw new Error("Note not found or unauthorized"); } - await db.delete(note).where(eq(note.id, noteId)); + await db + .delete(note) + .where(eq(note.id, noteId)); return true; }, async reorderNotes( userId: string, - notes: { id: string; order: number; isPinned?: boolean }[], + notes: { id: string; order: number; isPinned?: boolean }[] ): Promise { if (!notes || notes.length === 0) { return true; } - - const noteIds = notes.map((n) => n.id); - + + const noteIds = notes.map(n => n.id); + const userNotes = await db .select({ id: note.id }) .from(note) - .where( - and( - eq(note.userId, userId), - sql`${note.id} IN (${sql.join( - noteIds.map((id) => sql`${id}`), - sql`, `, - )})`, - ), - ); - - const foundNoteIds = new Set(userNotes.map((n) => n.id)); - + .where(and( + eq(note.userId, userId), + sql`${note.id} IN (${sql.join(noteIds.map(id => sql`${id}`), sql`, `)})` + )); + + const foundNoteIds = new Set(userNotes.map(n => n.id)); + if (foundNoteIds.size !== noteIds.length) { - const missingNotes = noteIds.filter((id) => !foundNoteIds.has(id)); + const missingNotes = noteIds.filter(id => !foundNoteIds.has(id)); console.error(`Notes not found or unauthorized: ${missingNotes.join(', ')}`); - throw new Error('One or more notes not found or unauthorized'); + throw new Error("One or more notes not found or unauthorized"); } - - return await db - .transaction(async (tx) => { - for (const n of notes) { - const updateData: Record = { - order: n.order, - updatedAt: new Date(), - }; - - if (n.isPinned !== undefined) { - updateData.isPinned = n.isPinned; - } - - await tx - .update(note) - .set(updateData) - .where(and(eq(note.id, n.id), eq(note.userId, userId))); + + return await db.transaction(async (tx) => { + for (const n of notes) { + const updateData: Record = { + order: n.order, + updatedAt: new Date(), + }; + + if (n.isPinned !== undefined) { + updateData.isPinned = n.isPinned; } - - return true; - }) - .catch((error) => { - console.error('Error in reorderNotes transaction:', error); - throw new Error('Failed to reorder notes: ' + error.message); - }); - }, -}; + + await tx + .update(note) + .set(updateData) + .where(and( + eq(note.id, n.id), + eq(note.userId, userId) + )); + } + + return true; + }).catch(error => { + console.error("Error in reorderNotes transaction:", error); + throw new Error("Failed to reorder notes: " + error.message); + }); + } +}; \ No newline at end of file diff --git a/apps/mail/app/api/v1/mail/auth/[providerId]/callback/route.ts b/apps/mail/app/api/v1/mail/auth/[providerId]/callback/route.ts index 15e3e260cf..83eec556f2 100644 --- a/apps/mail/app/api/v1/mail/auth/[providerId]/callback/route.ts +++ b/apps/mail/app/api/v1/mail/auth/[providerId]/callback/route.ts @@ -1,15 +1,15 @@ -import { type NextRequest, NextResponse } from 'next/server'; -import { createDriver } from '@/app/api/driver'; -import { connection } from '@zero/db/schema'; -import { db } from '@zero/db'; +import { type NextRequest, NextResponse } from "next/server"; +import { createDriver } from "@/app/api/driver"; +import { connection } from "@zero/db/schema"; +import { db } from "@zero/db"; export async function GET( request: NextRequest, { params }: { params: Promise<{ providerId: string }> }, ) { const searchParams = request.nextUrl.searchParams; - const code = searchParams.get('code'); - const state = searchParams.get('state'); + const code = searchParams.get("code"); + const state = searchParams.get("state"); if (!code || !state) { return NextResponse.redirect( @@ -26,8 +26,8 @@ export async function GET( const { tokens } = await driver.getTokens(code); if (!tokens.access_token || !tokens.refresh_token) { - console.error('Missing tokens:', tokens); - return new NextResponse(JSON.stringify({ error: 'Could not get token' }), { status: 400 }); + console.error("Missing tokens:", tokens); + return new NextResponse(JSON.stringify({ error: "Could not get token" }), { status: 400 }); } // Get user info using the access token @@ -37,7 +37,7 @@ export async function GET( }); if (!userInfo.data?.emailAddresses?.[0]?.value) { - console.error('Missing email in user info:', userInfo); + console.error("Missing email in user info:", userInfo); return new NextResponse(JSON.stringify({ error: 'Missing "email" in user info' }), { status: 400, }); @@ -46,10 +46,11 @@ export async function GET( // Store the connection in the database await db.insert(connection).values({ providerId, + id: crypto.randomUUID(), userId: state, email: userInfo.data.emailAddresses[0].value, - name: userInfo.data.names?.[0]?.displayName || 'Unknown', - picture: userInfo.data.photos?.[0]?.url || '', + name: userInfo.data.names?.[0]?.displayName || "Unknown", + picture: userInfo.data.photos?.[0]?.url || "", accessToken: tokens.access_token, refreshToken: tokens.refresh_token, scope: driver.getScope(), diff --git a/apps/mail/lib/auth.ts b/apps/mail/lib/auth.ts index ad38ecd5e7..0c9557b88c 100644 --- a/apps/mail/lib/auth.ts +++ b/apps/mail/lib/auth.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { connection, user as _user, account } from '@zero/db/schema'; -import { betterAuth, type BetterAuthOptions } from 'better-auth'; -import { drizzleAdapter } from 'better-auth/adapters/drizzle'; -import { getSocialProviders } from './auth-providers'; -import { customSession } from 'better-auth/plugins'; -import { eq } from 'drizzle-orm'; -import { Resend } from 'resend'; -import { db } from '@zero/db'; +import { connection, user as _user, account } from "@zero/db/schema"; +import { drizzleAdapter } from "better-auth/adapters/drizzle"; +import { betterAuth, type BetterAuthOptions } from "better-auth"; +import { customSession } from "better-auth/plugins"; +import { eq } from "drizzle-orm"; +import { Resend } from "resend"; +import { db } from "@zero/db"; +import { getSocialProviders } from "./auth-providers"; // If there is no resend key, it might be a local dev environment // In that case, we don't want to send emails and just log them @@ -16,7 +16,7 @@ const resend = process.env.RESEND_API_KEY const options = { database: drizzleAdapter(db, { - provider: 'pg', + provider: "pg", }), advanced: { ipAddress: { @@ -33,9 +33,9 @@ const options = { requireEmailVerification: true, sendResetPassword: async ({ user, url }) => { await resend.emails.send({ - from: '0.email ', + from: "0.email ", to: user.email, - subject: 'Reset your password', + subject: "Reset your password", html: `

Reset Your Password

Click the link below to reset your password:

@@ -52,9 +52,9 @@ const options = { const verificationUrl = `${process.env.NEXT_PUBLIC_APP_URL}/api/auth/verify-email?token=${token}&callbackURL=/settings/connections`; await resend.emails.send({ - from: '0.email ', + from: "0.email ", to: user.email, - subject: 'Verify your 0.email account', + subject: "Verify your 0.email account", html: `

Verify Your 0.email Account

Click the link below to verify your email:

@@ -74,7 +74,7 @@ const options = { .limit(1); let activeConnection = null; - + if (foundUser?.activeConnectionId) { // Get the active connection details const [connectionDetails] = await db @@ -82,7 +82,7 @@ const options = { .from(connection) .where(eq(connection.id, foundUser.activeConnectionId)) .limit(1); - + if (connectionDetails) { activeConnection = { id: connectionDetails.id, @@ -119,6 +119,7 @@ const options = { if (userAccount) { // create a new connection const [newConnection] = await db.insert(connection).values({ + id: crypto.randomUUID(), userId: user.id, email: user.email, name: user.name, @@ -135,7 +136,7 @@ const options = { } as any); // this type error is pissing me tf off if (newConnection) { - console.log('Created new connection for user', newConnection); + console.log("Created new connection for user", newConnection); } } } @@ -153,5 +154,5 @@ const options = { export const auth = betterAuth({ ...options, - trustedOrigins: process.env.BETTER_AUTH_TRUSTED_ORIGINS?.split(',') ?? [], + trustedOrigins: process.env.BETTER_AUTH_TRUSTED_ORIGINS?.split(",") ?? [], }); diff --git a/bun.lock b/bun.lock index 801e07c5b4..8b2494cf9c 100644 --- a/bun.lock +++ b/bun.lock @@ -146,7 +146,6 @@ "dependencies": { "drizzle-orm": "0.39.3", "postgres": "3.4.5", - "uuidv7": "^1.0.2", }, "devDependencies": { "@types/node": "22.13.8", @@ -2018,8 +2017,6 @@ "uuid": ["uuid@9.0.1", "", { "bin": { "uuid": "dist/bin/uuid" } }, "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA=="], - "uuidv7": ["uuidv7@1.0.2", "", { "bin": { "uuidv7": "cli.js" } }, "sha512-8JQkH4ooXnm1JCIhqTMbtmdnYEn6oKukBxHn1Ic9878jMkL7daTI7anTExfY18VRCX7tcdn5quzvCb6EWrR8PA=="], - "valibot": ["valibot@1.0.0-beta.15", "", { "peerDependencies": { "typescript": ">=5" }, "optionalPeers": ["typescript"] }, "sha512-BKy8XosZkDHWmYC+cJG74LBzP++Gfntwi33pP3D3RKztz2XV9jmFWnkOi21GoqARP8wAWARwhV6eTr1JcWzjGw=="], "vaul": ["vaul@1.1.2", "", { "dependencies": { "@radix-ui/react-dialog": "^1.1.1" }, "peerDependencies": { "react": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc" } }, "sha512-ZFkClGpWyI2WUQjdLJ/BaGuV6AVQiJ3uELGk3OYtP+B6yCO7Cmn9vPFXVJkRaGkOJu3m8bQMgtyzNHixULceQA=="], diff --git a/packages/db/drizzle.config.ts b/packages/db/drizzle.config.ts index 494ee08699..1fec539c0b 100644 --- a/packages/db/drizzle.config.ts +++ b/packages/db/drizzle.config.ts @@ -1,12 +1,11 @@ -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_*'], - casing: 'snake_case', + out: "./migrations", + tablesFilter: ["mail0_*"], } satisfies Config; diff --git a/packages/db/migrations/0017_familiar_dark_beast.sql b/packages/db/migrations/0017_familiar_dark_beast.sql deleted file mode 100644 index 114df88ad6..0000000000 --- a/packages/db/migrations/0017_familiar_dark_beast.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE "mail0_note" ( - "id" text PRIMARY KEY NOT NULL, - "user_id" text NOT NULL, - "thread_id" text NOT NULL, - "content" text NOT NULL, - "color" text DEFAULT 'default' NOT NULL, - "is_pinned" boolean DEFAULT false, - "order" integer DEFAULT 0 NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL -); ---> statement-breakpoint -ALTER TABLE "mail0_note" ADD CONSTRAINT "mail0_note_user_id_mail0_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."mail0_user"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/packages/db/migrations/0018_wet_slipstream.sql b/packages/db/migrations/0018_wet_slipstream.sql deleted file mode 100644 index 7ea853d954..0000000000 --- a/packages/db/migrations/0018_wet_slipstream.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE "mail0_account" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint -ALTER TABLE "mail0_connection" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint -ALTER TABLE "mail0_early_access" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint -ALTER TABLE "mail0_note" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint -ALTER TABLE "mail0_session" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint -ALTER TABLE "mail0_user" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint -ALTER TABLE "mail0_verification" ALTER COLUMN "id" SET DATA TYPE uuid; \ No newline at end of file diff --git a/packages/db/migrations/meta/0017_snapshot.json b/packages/db/migrations/meta/0017_snapshot.json deleted file mode 100644 index b1ce376801..0000000000 --- a/packages/db/migrations/meta/0017_snapshot.json +++ /dev/null @@ -1,625 +0,0 @@ -{ - "id": "f6a7111e-cd17-4de6-971d-f8a877e0de0d", - "prevId": "cb215514-4b6a-4789-9023-479a41961b78", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.mail0_account": { - "name": "mail0_account", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "account_id": { - "name": "account_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "access_token_expires_at": { - "name": "access_token_expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "refresh_token_expires_at": { - "name": "refresh_token_expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_account_user_id_mail0_user_id_fk": { - "name": "mail0_account_user_id_mail0_user_id_fk", - "tableFrom": "mail0_account", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_connection": { - "name": "mail0_connection", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "picture": { - "name": "picture", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "expires_at": { - "name": "expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_connection_user_id_mail0_user_id_fk": { - "name": "mail0_connection_user_id_mail0_user_id_fk", - "tableFrom": "mail0_connection", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_connection_email_unique": { - "name": "mail0_connection_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_early_access": { - "name": "mail0_early_access", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_early_access_email_unique": { - "name": "mail0_early_access_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_note": { - "name": "mail0_note", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "thread_id": { - "name": "thread_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "color": { - "name": "color", - "type": "text", - "primaryKey": false, - "notNull": true, - "default": "'default'" - }, - "is_pinned": { - "name": "is_pinned", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": false - }, - "order": { - "name": "order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_note_user_id_mail0_user_id_fk": { - "name": "mail0_note_user_id_mail0_user_id_fk", - "tableFrom": "mail0_note", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_session": { - "name": "mail0_session", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "expires_at": { - "name": "expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "ip_address": { - "name": "ip_address", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "user_agent": { - "name": "user_agent", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_session_user_id_mail0_user_id_fk": { - "name": "mail0_session_user_id_mail0_user_id_fk", - "tableFrom": "mail0_session", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_session_token_unique": { - "name": "mail0_session_token_unique", - "nullsNotDistinct": false, - "columns": [ - "token" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_summary": { - "name": "mail0_summary", - "schema": "", - "columns": { - "message_id": { - "name": "message_id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "connection_id": { - "name": "connection_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "saved": { - "name": "saved", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "tags": { - "name": "tags", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "suggested_reply": { - "name": "suggested_reply", - "type": "text", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_user": { - "name": "mail0_user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email_verified": { - "name": "email_verified", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "default_connection_id": { - "name": "default_connection_id", - "type": "text", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_user_email_unique": { - "name": "mail0_user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_verification": { - "name": "mail0_verification", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "expires_at": { - "name": "expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": {}, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0018_snapshot.json b/packages/db/migrations/meta/0018_snapshot.json deleted file mode 100644 index 56f6221e37..0000000000 --- a/packages/db/migrations/meta/0018_snapshot.json +++ /dev/null @@ -1,625 +0,0 @@ -{ - "id": "e06dd2ea-e64a-4f66-a5f2-a824a3dab57a", - "prevId": "f6a7111e-cd17-4de6-971d-f8a877e0de0d", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.mail0_account": { - "name": "mail0_account", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "account_id": { - "name": "account_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "access_token_expires_at": { - "name": "access_token_expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "refresh_token_expires_at": { - "name": "refresh_token_expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_account_user_id_mail0_user_id_fk": { - "name": "mail0_account_user_id_mail0_user_id_fk", - "tableFrom": "mail0_account", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_connection": { - "name": "mail0_connection", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "picture": { - "name": "picture", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "provider_id": { - "name": "provider_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "expires_at": { - "name": "expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_connection_user_id_mail0_user_id_fk": { - "name": "mail0_connection_user_id_mail0_user_id_fk", - "tableFrom": "mail0_connection", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_connection_email_unique": { - "name": "mail0_connection_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_early_access": { - "name": "mail0_early_access", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_early_access_email_unique": { - "name": "mail0_early_access_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_note": { - "name": "mail0_note", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "thread_id": { - "name": "thread_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "color": { - "name": "color", - "type": "text", - "primaryKey": false, - "notNull": true, - "default": "'default'" - }, - "is_pinned": { - "name": "is_pinned", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": false - }, - "order": { - "name": "order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_note_user_id_mail0_user_id_fk": { - "name": "mail0_note_user_id_mail0_user_id_fk", - "tableFrom": "mail0_note", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_session": { - "name": "mail0_session", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "expires_at": { - "name": "expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "ip_address": { - "name": "ip_address", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "user_agent": { - "name": "user_agent", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "mail0_session_user_id_mail0_user_id_fk": { - "name": "mail0_session_user_id_mail0_user_id_fk", - "tableFrom": "mail0_session", - "tableTo": "mail0_user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_session_token_unique": { - "name": "mail0_session_token_unique", - "nullsNotDistinct": false, - "columns": [ - "token" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_summary": { - "name": "mail0_summary", - "schema": "", - "columns": { - "message_id": { - "name": "message_id", - "type": "text", - "primaryKey": true, - "notNull": true - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "connection_id": { - "name": "connection_id", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "saved": { - "name": "saved", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "tags": { - "name": "tags", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "suggested_reply": { - "name": "suggested_reply", - "type": "text", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_user": { - "name": "mail0_user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email_verified": { - "name": "email_verified", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "default_connection_id": { - "name": "default_connection_id", - "type": "text", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "mail0_user_email_unique": { - "name": "mail0_user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.mail0_verification": { - "name": "mail0_verification", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "expires_at": { - "name": "expires_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": {}, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index 9f846cba59..5ec4c7ac96 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -120,20 +120,6 @@ "when": 1740597012602, "tag": "0016_neat_ogun", "breakpoints": true - }, - { - "idx": 17, - "version": "7", - "when": 1742580771348, - "tag": "0017_familiar_dark_beast", - "breakpoints": true - }, - { - "idx": 18, - "version": "7", - "when": 1742583324840, - "tag": "0018_wet_slipstream", - "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/package.json b/packages/db/package.json index d39e6e8e57..6b5b5e3411 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -4,8 +4,7 @@ "private": true, "dependencies": { "drizzle-orm": "0.39.3", - "postgres": "3.4.5", - "uuidv7": "^1.0.2" + "postgres": "3.4.5" }, "scripts": { "db:generate": "drizzle-kit generate", diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 0cc036cc7f..6b19faf1e1 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 }); +export const db = drizzle(conn, { schema }); \ No newline at end of file diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index 047e54fc9f..a829cf1a47 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -1,104 +1,103 @@ -import { pgTableCreator, text, timestamp, boolean, integer, uuid } from 'drizzle-orm/pg-core'; -import { uuidv7 } from 'uuidv7'; +import { pgTableCreator, text, timestamp, boolean, integer } from "drizzle-orm/pg-core"; export const createTable = pgTableCreator((name) => `mail0_${name}`); -export const user = createTable('user', { - id: uuid().primaryKey().$defaultFn(uuidv7), - name: text().notNull(), - email: text().notNull().unique(), - emailVerified: boolean().notNull(), - image: text(), - createdAt: timestamp().notNull(), - updatedAt: timestamp().notNull(), - defaultConnectionId: text(), +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 session = createTable('session', { - id: uuid().primaryKey().$defaultFn(uuidv7), - expiresAt: timestamp().notNull(), - token: text().notNull().unique(), - createdAt: timestamp().notNull(), - updatedAt: timestamp().notNull(), - ipAddress: text(), - userAgent: text(), - userId: 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") .notNull() .references(() => user.id), }); -export const account = createTable('account', { - id: uuid().primaryKey().$defaultFn(uuidv7), - accountId: text().notNull(), - providerId: text().notNull(), - userId: text() +export const account = createTable("account", { + id: text("id").primaryKey(), + accountId: text("account_id").notNull(), + providerId: text("provider_id").notNull(), + userId: text("user_id") .notNull() .references(() => user.id), - accessToken: text(), - refreshToken: text(), - idToken: text(), - accessTokenExpiresAt: timestamp(), - refreshTokenExpiresAt: timestamp(), - scope: text(), - password: text(), - createdAt: timestamp().notNull(), - updatedAt: timestamp().notNull(), + 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(), }); -export const verification = createTable('verification', { - id: uuid().primaryKey().$defaultFn(uuidv7), - identifier: text().notNull(), - value: text().notNull(), - expiresAt: timestamp().notNull(), - createdAt: timestamp(), - updatedAt: timestamp(), +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 earlyAccess = createTable('early_access', { - id: uuid().primaryKey().$defaultFn(uuidv7), - email: text().notNull().unique(), - createdAt: timestamp().notNull(), - updatedAt: timestamp().notNull(), +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 connection = createTable('connection', { - id: uuid().primaryKey().$defaultFn(uuidv7), - userId: text() +export const connection = createTable("connection", { + id: text("id").primaryKey(), + userId: text("user_id") .notNull() .references(() => user.id), - 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(), + 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(), }); -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 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 note = createTable('note', { - id: uuid().primaryKey().$defaultFn(uuidv7), - userId: text() +export const note = createTable("note", { + id: text("id").primaryKey(), + userId: text("user_id") .notNull() - .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(), + .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(), });