From 6e1d53e28a056e429c54e1e6af45eaa7939daa41 Mon Sep 17 00:00:00 2001 From: Kush Thaker Date: Wed, 31 Jul 2024 10:56:40 +0530 Subject: queues so far Co-authored-by: Dhravya Shah --- apps/web/app/actions/doers.ts | 481 ++--- apps/web/lib/get-metadata.ts | 40 - apps/web/migrations/0000_omniscient_stick.sql | 152 ++ .../web/migrations/0000_steep_moira_mactaggert.sql | 135 -- apps/web/migrations/meta/0000_snapshot.json | 1847 +++++++++++--------- apps/web/migrations/meta/_journal.json | 24 +- apps/web/server/db/schema.ts | 26 + 7 files changed, 1466 insertions(+), 1239 deletions(-) delete mode 100644 apps/web/lib/get-metadata.ts create mode 100644 apps/web/migrations/0000_omniscient_stick.sql delete mode 100644 apps/web/migrations/0000_steep_moira_mactaggert.sql (limited to 'apps/web') diff --git a/apps/web/app/actions/doers.ts b/apps/web/app/actions/doers.ts index 9a831921..910226a5 100644 --- a/apps/web/app/actions/doers.ts +++ b/apps/web/app/actions/doers.ts @@ -15,7 +15,7 @@ import { import { ServerActionReturnType } from "./types"; import { auth } from "../../server/auth"; import { Tweet } from "react-tweet/api"; -import { getMetaData } from "@/lib/get-metadata"; +// import { getMetaData } from "@/lib/get-metadata"; import { and, eq, inArray, sql } from "drizzle-orm"; import { LIMITS } from "@/lib/constants"; import { ChatHistory } from "@repo/shared-types"; @@ -197,122 +197,16 @@ export const createMemory = async (input: { return { error: "Not authenticated", success: false }; } - const type = typeDecider(input.content); - - let pageContent = input.content; - let metadata: Awaited>; - let vectorData: string; - - if (!(await limit(data.user.id, type))) { - return { - success: false, - data: 0, - error: `You have exceeded the limit of ${LIMITS[type as keyof typeof LIMITS]} ${type}s.`, - }; - } - - let noteId = 0; - - if (type === "page") { - const response = await fetch("https://md.dhr.wtf/?url=" + input.content, { - headers: { - Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, - }, - }); - pageContent = await response.text(); - vectorData = pageContent; - try { - metadata = await getMetaData(input.content); - } catch (e) { - return { - success: false, - error: "Failed to fetch metadata for the page. Please try again later.", - }; - } - } else if (type === "tweet") { - //Request the worker for the entire thread - - let thread: string; - let errorOccurred: boolean = false; - - try { - const cf_thread_endpoint = process.env.THREAD_CF_WORKER; - const authKey = process.env.THREAD_CF_AUTH; - const threadRequest = await fetch(cf_thread_endpoint, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: authKey, - }, - body: JSON.stringify({ url: input.content }), - }); - - if (threadRequest.status !== 200) { - throw new Error( - `Failed to fetch the thread: ${input.content}, Reason: ${threadRequest.statusText}`, - ); - } - - thread = await threadRequest.text(); - if (thread.trim().length === 2) { - console.log("Thread is an empty array"); - throw new Error( - "[THREAD FETCHING SERVICE] Got no content form thread worker", - ); - } - } catch (e) { - console.log("[THREAD FETCHING SERVICE] Failed to fetch the thread", e); - errorOccurred = true; - } - - const tweet = await getTweetData(input.content.split("/").pop() as string); - - pageContent = tweetToMd(tweet); - console.log("THis ishte page content!!", pageContent); - //@ts-ignore - vectorData = errorOccurred ? JSON.stringify(pageContent) : thread; - metadata = { - baseUrl: input.content, - description: tweet.text.slice(0, 200), - image: tweet.user.profile_image_url_https, - title: `Tweet by ${tweet.user.name}`, - }; - } else if (type === "note") { - pageContent = input.content; - vectorData = pageContent; - noteId = new Date().getTime(); - metadata = { - baseUrl: `https://supermemory.ai/note/${noteId}`, - description: `Note created at ${new Date().toLocaleString()}`, - image: "https://supermemory.ai/logo.png", - title: `${pageContent.slice(0, 20)} ${pageContent.length > 20 ? "..." : ""}`, - }; - } else { - return { - success: false, - data: 0, - error: "Invalid type", - }; - } - - let storeToSpaces = input.spaces; - - if (!storeToSpaces) { - storeToSpaces = []; - } - - const vectorSaveResponse = await fetch( + + // make the backend reqeust for the queue here + const vectorSaveResponses = await fetch( `${process.env.BACKEND_BASE_URL}/api/add`, { method: "POST", body: JSON.stringify({ - pageContent: vectorData, - title: metadata.title, - description: metadata.description, - url: metadata.baseUrl, - spaces: storeToSpaces.map((spaceId) => spaceId.toString()), + url: input.content, + spaces: input.spaces, user: data.user.id, - type, }), headers: { "Content-Type": "application/json", @@ -321,125 +215,249 @@ export const createMemory = async (input: { }, ); - if (!vectorSaveResponse.ok) { - const errorData = await vectorSaveResponse.text(); - console.error(errorData); - return { - success: false, - data: 0, - error: `Failed to save to vector store. Backend returned error: ${errorData}`, - }; - } - - let contentId: number; - - const response = (await vectorSaveResponse.json()) as { - status: string; - chunkedInput: string; - message?: string; - }; - - try { - if (response.status !== "ok") { - if (response.status === "error") { - return { - success: false, - data: 0, - error: response.message, - }; - } else { - return { - success: false, - data: 0, - error: `Failed to save to vector store. Backend returned error: ${response.message}`, - }; - } - } - } catch (e) { - return { - success: false, - data: 0, - error: `Failed to save to vector store. Backend returned error: ${e}`, - }; - } - - const saveToDbUrl = - (metadata.baseUrl.split("#supermemory-user-")[0] ?? metadata.baseUrl) + - "#supermemory-user-" + - data.user.id; - - // Insert into database - try { - const insertResponse = await db - .insert(storedContent) - .values({ - content: pageContent, - title: metadata.title, - description: metadata.description, - url: saveToDbUrl, - baseUrl: saveToDbUrl, - image: metadata.image, - savedAt: new Date(), - userId: data.user.id, - type, - noteId, - }) - .returning({ id: storedContent.id }); - revalidatePath("/memories"); - revalidatePath("/home"); - - if (!insertResponse[0]?.id) { - return { - success: false, - data: 0, - error: "Something went wrong while saving the document to the database", - }; - } - - contentId = insertResponse[0]?.id; - } catch (e) { - const error = e as Error; - console.log("Error: ", error.message); - - if ( - error.message.includes( - "D1_ERROR: UNIQUE constraint failed: storedContent.baseUrl", - ) - ) { - return { - success: false, - data: 0, - error: "Content already exists", - }; - } - - return { - success: false, - data: 0, - error: "Failed to save to database with error: " + error.message, - }; - } - - if (storeToSpaces.length > 0) { - // Adding the many-to-many relationship between content and spaces - const spaceData = await db - .select() - .from(space) - .where( - and(inArray(space.id, storeToSpaces), eq(space.user, data.user.id)), - ) - .all(); - - await Promise.all( - spaceData.map(async (s) => { - await db - .insert(contentToSpace) - .values({ contentId: contentId, spaceId: s.id }); - - await db.update(space).set({ numItems: s.numItems + 1 }); - }), - ); - } +// const type = typeDecider(input.content); + +// let pageContent = input.content; +// let metadata: Awaited>; +// let vectorData: string; + +// if (!(await limit(data.user.id, type))) { +// return { +// success: false, +// data: 0, +// error: `You have exceeded the limit of ${LIMITS[type as keyof typeof LIMITS]} ${type}s.`, +// }; +// } + +// let noteId = 0; + +// if (type === "page") { +// const response = await fetch("https://md.dhr.wtf/?url=" + input.content, { +// headers: { +// Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, +// }, +// }); +// pageContent = await response.text(); +// vectorData = pageContent; +// try { +// metadata = await getMetaData(input.content); +// } catch (e) { +// return { +// success: false, +// error: "Failed to fetch metadata for the page. Please try again later.", +// }; +// } +// } else if (type === "tweet") { +// //Request the worker for the entire thread + +// let thread: string; +// let errorOccurred: boolean = false; + +// try { +// const cf_thread_endpoint = process.env.THREAD_CF_WORKER; +// const authKey = process.env.THREAD_CF_AUTH; +// const threadRequest = await fetch(cf_thread_endpoint, { +// method: "POST", +// headers: { +// "Content-Type": "application/json", +// Authorization: authKey, +// }, +// body: JSON.stringify({ url: input.content }), +// }); + +// if (threadRequest.status !== 200) { +// throw new Error( +// `Failed to fetch the thread: ${input.content}, Reason: ${threadRequest.statusText}`, +// ); +// } + +// thread = await threadRequest.text(); +// if (thread.trim().length === 2) { +// console.log("Thread is an empty array"); +// throw new Error( +// "[THREAD FETCHING SERVICE] Got no content form thread worker", +// ); +// } +// } catch (e) { +// console.log("[THREAD FETCHING SERVICE] Failed to fetch the thread", e); +// errorOccurred = true; +// } + +// const tweet = await getTweetData(input.content.split("/").pop() as string); + +// pageContent = tweetToMd(tweet); +// console.log("THis ishte page content!!", pageContent); +// //@ts-ignore +// vectorData = errorOccurred ? JSON.stringify(pageContent) : thread; +// metadata = { +// baseUrl: input.content, +// description: tweet.text.slice(0, 200), +// image: tweet.user.profile_image_url_https, +// title: `Tweet by ${tweet.user.name}`, +// }; +// } else if (type === "note") { +// pageContent = input.content; +// vectorData = pageContent; +// noteId = new Date().getTime(); +// metadata = { +// baseUrl: `https://supermemory.ai/note/${noteId}`, +// description: `Note created at ${new Date().toLocaleString()}`, +// image: "https://supermemory.ai/logo.png", +// title: `${pageContent.slice(0, 20)} ${pageContent.length > 20 ? "..." : ""}`, +// }; +// } else { +// return { +// success: false, +// data: 0, +// error: "Invalid type", +// }; +// } + +// let storeToSpaces = input.spaces; + +// if (!storeToSpaces) { +// storeToSpaces = []; +// } + +// const vectorSaveResponse = await fetch( +// `${process.env.BACKEND_BASE_URL}/api/add`, +// { +// method: "POST", +// body: JSON.stringify({ +// pageContent: vectorData, +// title: metadata.title, +// description: metadata.description, +// url: metadata.baseUrl, +// spaces: storeToSpaces.map((spaceId) => spaceId.toString()), +// user: data.user.id, +// type, +// }), +// headers: { +// "Content-Type": "application/json", +// Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, +// }, +// }, +// ); + +// if (!vectorSaveResponse.ok) { +// const errorData = await vectorSaveResponse.text(); +// console.error(errorData); +// return { +// success: false, +// data: 0, +// error: `Failed to save to vector store. Backend returned error: ${errorData}`, +// }; +// } + +// let contentId: number; + +// const response = (await vectorSaveResponse.json()) as { +// status: string; +// chunkedInput: string; +// message?: string; +// }; + +// try { +// if (response.status !== "ok") { +// if (response.status === "error") { +// return { +// success: false, +// data: 0, +// error: response.message, +// }; +// } else { +// return { +// success: false, +// data: 0, +// error: `Failed to save to vector store. Backend returned error: ${response.message}`, +// }; +// } +// } +// } catch (e) { +// return { +// success: false, +// data: 0, +// error: `Failed to save to vector store. Backend returned error: ${e}`, +// }; +// } + +// const saveToDbUrl = +// (metadata.baseUrl.split("#supermemory-user-")[0] ?? metadata.baseUrl) + +// "#supermemory-user-" + +// data.user.id; + +// // Insert into database +// try { +// const insertResponse = await db +// .insert(storedContent) +// .values({ +// content: pageContent, +// title: metadata.title, +// description: metadata.description, +// url: saveToDbUrl, +// baseUrl: saveToDbUrl, +// image: metadata.image, +// savedAt: new Date(), +// userId: data.user.id, +// type, +// noteId, +// }) +// .returning({ id: storedContent.id }); +// revalidatePath("/memories"); +// revalidatePath("/home"); + +// if (!insertResponse[0]?.id) { +// return { +// success: false, +// data: 0, +// error: "Something went wrong while saving the document to the database", +// }; +// } + +// contentId = insertResponse[0]?.id; +// } catch (e) { +// const error = e as Error; +// console.log("Error: ", error.message); + +// if ( +// error.message.includes( +// "D1_ERROR: UNIQUE constraint failed: storedContent.baseUrl", +// ) +// ) { +// return { +// success: false, +// data: 0, +// error: "Content already exists", +// }; +// } + +// return { +// success: false, +// data: 0, +// error: "Failed to save to database with error: " + error.message, +// }; +// } + +// if (storeToSpaces.length > 0) { +// // Adding the many-to-many relationship between content and spaces +// const spaceData = await db +// .select() +// .from(space) +// .where( +// and(inArray(space.id, storeToSpaces), eq(space.user, data.user.id)), +// ) +// .all(); + +// await Promise.all( +// spaceData.map(async (s) => { +// await db +// .insert(contentToSpace) +// .values({ contentId: contentId, spaceId: s.id }); + +// await db.update(space).set({ numItems: s.numItems + 1 }); +// }), +// ); +// } return { success: true, @@ -457,6 +475,7 @@ export const createChatThread = async ( return { error: "Not authenticated", success: false }; } + const thread = await db .insert(chatThreads) .values({ diff --git a/apps/web/lib/get-metadata.ts b/apps/web/lib/get-metadata.ts deleted file mode 100644 index c81397ff..00000000 --- a/apps/web/lib/get-metadata.ts +++ /dev/null @@ -1,40 +0,0 @@ -"use server"; -import * as cheerio from "cheerio"; - -// TODO: THIS SHOULD PROBABLY ALSO FETCH THE OG-IMAGE -export async function getMetaData(url: string) { - const response = await fetch(url); - const html = await response.text(); - - const $ = cheerio.load(html); - - // Extract the base URL - const baseUrl = url; - - // Extract title - const title = $("title").text().trim(); - - const description = $("meta[name=description]").attr("content") ?? ""; - - const _favicon = - $("link[rel=icon]").attr("href") ?? "https://supermemory.dhr.wtf/web.svg"; - - let favicon = - _favicon.trim().length > 0 - ? _favicon.trim() - : "https://supermemory.dhr.wtf/web.svg"; - if (favicon.startsWith("/")) { - favicon = baseUrl + favicon; - } else if (favicon.startsWith("./")) { - favicon = baseUrl + favicon.slice(1); - } - - // Prepare the metadata object - const metadata = { - title, - description, - image: favicon, - baseUrl, - }; - return metadata; -} diff --git a/apps/web/migrations/0000_omniscient_stick.sql b/apps/web/migrations/0000_omniscient_stick.sql new file mode 100644 index 00000000..542d6d0e --- /dev/null +++ b/apps/web/migrations/0000_omniscient_stick.sql @@ -0,0 +1,152 @@ +CREATE TABLE `account` ( + `userId` text NOT NULL, + `type` text NOT NULL, + `provider` text NOT NULL, + `providerAccountId` text NOT NULL, + `refresh_token` text, + `access_token` text, + `expires_at` integer, + `token_type` text, + `scope` text, + `id_token` text, + `session_state` text, + PRIMARY KEY(`provider`, `providerAccountId`), + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `authenticator` ( + `credentialID` text NOT NULL, + `userId` text NOT NULL, + `providerAccountId` text NOT NULL, + `credentialPublicKey` text NOT NULL, + `counter` integer NOT NULL, + `credentialDeviceType` text NOT NULL, + `credentialBackedUp` integer NOT NULL, + `transports` text, + PRIMARY KEY(`credentialID`, `userId`), + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `canvas` ( + `id` text PRIMARY KEY NOT NULL, + `title` text DEFAULT 'Untitled' NOT NULL, + `description` text DEFAULT 'Untitled' NOT NULL, + `url` text DEFAULT '' NOT NULL, + `userId` text NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `chatHistory` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `threadId` text NOT NULL, + `question` text NOT NULL, + `answerParts` text, + `answerSources` text, + `answerJustification` text, + `createdAt` integer DEFAULT '"2024-07-29T17:06:56.122Z"' NOT NULL, + FOREIGN KEY (`threadId`) REFERENCES `chatThread`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `chatThread` ( + `id` text PRIMARY KEY NOT NULL, + `firstMessage` text NOT NULL, + `userId` text NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `contentToSpace` ( + `contentId` integer NOT NULL, + `spaceId` integer NOT NULL, + PRIMARY KEY(`contentId`, `spaceId`), + FOREIGN KEY (`contentId`) REFERENCES `storedContent`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `jobs` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `userId` text NOT NULL, + `url` text NOT NULL, + `status` text NOT NULL, + `attempts` integer DEFAULT 0 NOT NULL, + `lastAttemptAt` integer, + `error` blob, + `createdAt` integer NOT NULL, + `updatedAt` integer NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `session` ( + `sessionToken` text PRIMARY KEY NOT NULL, + `userId` text NOT NULL, + `expires` integer NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `space` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text DEFAULT 'none' NOT NULL, + `user` text(255), + `createdAt` integer NOT NULL, + `numItems` integer DEFAULT 0 NOT NULL, + FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `spacesAccess` ( + `spaceId` integer NOT NULL, + `userEmail` text NOT NULL, + PRIMARY KEY(`spaceId`, `userEmail`), + FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `storedContent` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `content` text NOT NULL, + `title` text(255), + `description` text(255), + `url` text NOT NULL, + `savedAt` integer NOT NULL, + `baseUrl` text(255), + `ogImage` text(255), + `type` text DEFAULT 'page', + `image` text(255), + `user` text, + `noteId` integer, + FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `user` ( + `id` text PRIMARY KEY NOT NULL, + `name` text, + `email` text NOT NULL, + `emailVerified` integer, + `image` text, + `telegramId` text, + `hasOnboarded` integer DEFAULT false +); +--> statement-breakpoint +CREATE TABLE `verificationToken` ( + `identifier` text NOT NULL, + `token` text NOT NULL, + `expires` integer NOT NULL, + PRIMARY KEY(`identifier`, `token`) +); +--> statement-breakpoint +CREATE UNIQUE INDEX `authenticator_credentialID_unique` ON `authenticator` (`credentialID`);--> statement-breakpoint +CREATE INDEX `canvas_user_userId` ON `canvas` (`userId`);--> statement-breakpoint +CREATE INDEX `chatHistory_thread_idx` ON `chatHistory` (`threadId`);--> statement-breakpoint +CREATE INDEX `chatThread_user_idx` ON `chatThread` (`userId`);--> statement-breakpoint +CREATE INDEX `jobs_userId_idx` ON `jobs` (`userId`);--> statement-breakpoint +CREATE INDEX `jobs_status_idx` ON `jobs` (`status`);--> statement-breakpoint +CREATE INDEX `jobs_createdAt_idx` ON `jobs` (`createdAt`);--> statement-breakpoint +CREATE INDEX `jobs_url_idx` ON `jobs` (`url`);--> statement-breakpoint +CREATE UNIQUE INDEX `space_name_unique` ON `space` (`name`);--> statement-breakpoint +CREATE INDEX `spaces_name_idx` ON `space` (`name`);--> statement-breakpoint +CREATE INDEX `spaces_user_idx` ON `space` (`user`);--> statement-breakpoint +CREATE UNIQUE INDEX `storedContent_baseUrl_unique` ON `storedContent` (`baseUrl`);--> statement-breakpoint +CREATE INDEX `storedContent_url_idx` ON `storedContent` (`url`);--> statement-breakpoint +CREATE INDEX `storedContent_savedAt_idx` ON `storedContent` (`savedAt`);--> statement-breakpoint +CREATE INDEX `storedContent_title_idx` ON `storedContent` (`title`);--> statement-breakpoint +CREATE INDEX `storedContent_user_idx` ON `storedContent` (`user`);--> statement-breakpoint +CREATE INDEX `users_email_idx` ON `user` (`email`);--> statement-breakpoint +CREATE INDEX `users_telegram_idx` ON `user` (`telegramId`);--> statement-breakpoint +CREATE INDEX `users_id_idx` ON `user` (`id`); \ No newline at end of file diff --git a/apps/web/migrations/0000_steep_moira_mactaggert.sql b/apps/web/migrations/0000_steep_moira_mactaggert.sql deleted file mode 100644 index 5813639d..00000000 --- a/apps/web/migrations/0000_steep_moira_mactaggert.sql +++ /dev/null @@ -1,135 +0,0 @@ -CREATE TABLE `account` ( - `userId` text NOT NULL, - `type` text NOT NULL, - `provider` text NOT NULL, - `providerAccountId` text NOT NULL, - `refresh_token` text, - `access_token` text, - `expires_at` integer, - `token_type` text, - `scope` text, - `id_token` text, - `session_state` text, - PRIMARY KEY(`provider`, `providerAccountId`), - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `authenticator` ( - `credentialID` text NOT NULL, - `userId` text NOT NULL, - `providerAccountId` text NOT NULL, - `credentialPublicKey` text NOT NULL, - `counter` integer NOT NULL, - `credentialDeviceType` text NOT NULL, - `credentialBackedUp` integer NOT NULL, - `transports` text, - PRIMARY KEY(`credentialID`, `userId`), - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `canvas` ( - `id` text PRIMARY KEY NOT NULL, - `title` text DEFAULT 'Untitled' NOT NULL, - `description` text DEFAULT 'Untitled' NOT NULL, - `url` text DEFAULT '' NOT NULL, - `userId` text NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `chatHistory` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `threadId` text NOT NULL, - `question` text NOT NULL, - `answerParts` text, - `answerSources` text, - `answerJustification` text, - `createdAt` integer DEFAULT '"2024-07-25T22:31:50.848Z"' NOT NULL, - FOREIGN KEY (`threadId`) REFERENCES `chatThread`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `chatThread` ( - `id` text PRIMARY KEY NOT NULL, - `firstMessage` text NOT NULL, - `userId` text NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `contentToSpace` ( - `contentId` integer NOT NULL, - `spaceId` integer NOT NULL, - PRIMARY KEY(`contentId`, `spaceId`), - FOREIGN KEY (`contentId`) REFERENCES `storedContent`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `session` ( - `sessionToken` text PRIMARY KEY NOT NULL, - `userId` text NOT NULL, - `expires` integer NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `space` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `name` text DEFAULT 'none' NOT NULL, - `user` text(255), - `createdAt` integer NOT NULL, - `numItems` integer DEFAULT 0 NOT NULL, - FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `spacesAccess` ( - `spaceId` integer NOT NULL, - `userEmail` text NOT NULL, - PRIMARY KEY(`spaceId`, `userEmail`), - FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `storedContent` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `content` text NOT NULL, - `title` text(255), - `description` text(255), - `url` text NOT NULL, - `savedAt` integer NOT NULL, - `baseUrl` text(255), - `ogImage` text(255), - `type` text DEFAULT 'page', - `image` text(255), - `user` text, - `noteId` integer, - FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `user` ( - `id` text PRIMARY KEY NOT NULL, - `name` text, - `email` text NOT NULL, - `emailVerified` integer, - `image` text, - `telegramId` text, - `hasOnboarded` integer DEFAULT false -); ---> statement-breakpoint -CREATE TABLE `verificationToken` ( - `identifier` text NOT NULL, - `token` text NOT NULL, - `expires` integer NOT NULL, - PRIMARY KEY(`identifier`, `token`) -); ---> statement-breakpoint -CREATE UNIQUE INDEX `authenticator_credentialID_unique` ON `authenticator` (`credentialID`);--> statement-breakpoint -CREATE INDEX `canvas_user_userId` ON `canvas` (`userId`);--> statement-breakpoint -CREATE INDEX `chatHistory_thread_idx` ON `chatHistory` (`threadId`);--> statement-breakpoint -CREATE INDEX `chatThread_user_idx` ON `chatThread` (`userId`);--> statement-breakpoint -CREATE UNIQUE INDEX `space_name_unique` ON `space` (`name`);--> statement-breakpoint -CREATE INDEX `spaces_name_idx` ON `space` (`name`);--> statement-breakpoint -CREATE INDEX `spaces_user_idx` ON `space` (`user`);--> statement-breakpoint -CREATE UNIQUE INDEX `storedContent_baseUrl_unique` ON `storedContent` (`baseUrl`);--> statement-breakpoint -CREATE INDEX `storedContent_url_idx` ON `storedContent` (`url`);--> statement-breakpoint -CREATE INDEX `storedContent_savedAt_idx` ON `storedContent` (`savedAt`);--> statement-breakpoint -CREATE INDEX `storedContent_title_idx` ON `storedContent` (`title`);--> statement-breakpoint -CREATE INDEX `storedContent_user_idx` ON `storedContent` (`user`);--> statement-breakpoint -CREATE INDEX `users_email_idx` ON `user` (`email`);--> statement-breakpoint -CREATE INDEX `users_telegram_idx` ON `user` (`telegramId`);--> statement-breakpoint -CREATE INDEX `users_id_idx` ON `user` (`id`); \ No newline at end of file diff --git a/apps/web/migrations/meta/0000_snapshot.json b/apps/web/migrations/meta/0000_snapshot.json index a7689010..8141d674 100644 --- a/apps/web/migrations/meta/0000_snapshot.json +++ b/apps/web/migrations/meta/0000_snapshot.json @@ -1,822 +1,1027 @@ { - "version": "6", - "dialect": "sqlite", - "id": "8705302a-eae7-4fbf-9ce8-8ae23df228a2", - "prevId": "00000000-0000-0000-0000-000000000000", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": ["userId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": ["provider", "providerAccountId"], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "authenticator": { - "name": "authenticator", - "columns": { - "credentialID": { - "name": "credentialID", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "credentialPublicKey": { - "name": "credentialPublicKey", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "counter": { - "name": "counter", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "credentialDeviceType": { - "name": "credentialDeviceType", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "credentialBackedUp": { - "name": "credentialBackedUp", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "transports": { - "name": "transports", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "authenticator_credentialID_unique": { - "name": "authenticator_credentialID_unique", - "columns": ["credentialID"], - "isUnique": true - } - }, - "foreignKeys": { - "authenticator_userId_user_id_fk": { - "name": "authenticator_userId_user_id_fk", - "tableFrom": "authenticator", - "tableTo": "user", - "columnsFrom": ["userId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "authenticator_userId_credentialID_pk": { - "columns": ["credentialID", "userId"], - "name": "authenticator_userId_credentialID_pk" - } - }, - "uniqueConstraints": {} - }, - "canvas": { - "name": "canvas", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'Untitled'" - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'Untitled'" - }, - "url": { - "name": "url", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "''" - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "canvas_user_userId": { - "name": "canvas_user_userId", - "columns": ["userId"], - "isUnique": false - } - }, - "foreignKeys": { - "canvas_userId_user_id_fk": { - "name": "canvas_userId_user_id_fk", - "tableFrom": "canvas", - "tableTo": "user", - "columnsFrom": ["userId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "chatHistory": { - "name": "chatHistory", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "threadId": { - "name": "threadId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "question": { - "name": "question", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "answerParts": { - "name": "answerParts", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "answerSources": { - "name": "answerSources", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "answerJustification": { - "name": "answerJustification", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'\"2024-07-25T22:31:50.848Z\"'" - } - }, - "indexes": { - "chatHistory_thread_idx": { - "name": "chatHistory_thread_idx", - "columns": ["threadId"], - "isUnique": false - } - }, - "foreignKeys": { - "chatHistory_threadId_chatThread_id_fk": { - "name": "chatHistory_threadId_chatThread_id_fk", - "tableFrom": "chatHistory", - "tableTo": "chatThread", - "columnsFrom": ["threadId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "chatThread": { - "name": "chatThread", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "firstMessage": { - "name": "firstMessage", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "chatThread_user_idx": { - "name": "chatThread_user_idx", - "columns": ["userId"], - "isUnique": false - } - }, - "foreignKeys": { - "chatThread_userId_user_id_fk": { - "name": "chatThread_userId_user_id_fk", - "tableFrom": "chatThread", - "tableTo": "user", - "columnsFrom": ["userId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "contentToSpace": { - "name": "contentToSpace", - "columns": { - "contentId": { - "name": "contentId", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "spaceId": { - "name": "spaceId", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "contentToSpace_contentId_storedContent_id_fk": { - "name": "contentToSpace_contentId_storedContent_id_fk", - "tableFrom": "contentToSpace", - "tableTo": "storedContent", - "columnsFrom": ["contentId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "contentToSpace_spaceId_space_id_fk": { - "name": "contentToSpace_spaceId_space_id_fk", - "tableFrom": "contentToSpace", - "tableTo": "space", - "columnsFrom": ["spaceId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "contentToSpace_contentId_spaceId_pk": { - "columns": ["contentId", "spaceId"], - "name": "contentToSpace_contentId_spaceId_pk" - } - }, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": ["userId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "space": { - "name": "space", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'none'" - }, - "user": { - "name": "user", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "numItems": { - "name": "numItems", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "space_name_unique": { - "name": "space_name_unique", - "columns": ["name"], - "isUnique": true - }, - "spaces_name_idx": { - "name": "spaces_name_idx", - "columns": ["name"], - "isUnique": false - }, - "spaces_user_idx": { - "name": "spaces_user_idx", - "columns": ["user"], - "isUnique": false - } - }, - "foreignKeys": { - "space_user_user_id_fk": { - "name": "space_user_user_id_fk", - "tableFrom": "space", - "tableTo": "user", - "columnsFrom": ["user"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "spacesAccess": { - "name": "spacesAccess", - "columns": { - "spaceId": { - "name": "spaceId", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userEmail": { - "name": "userEmail", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "spacesAccess_spaceId_space_id_fk": { - "name": "spacesAccess_spaceId_space_id_fk", - "tableFrom": "spacesAccess", - "tableTo": "space", - "columnsFrom": ["spaceId"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "spacesAccess_spaceId_userEmail_pk": { - "columns": ["spaceId", "userEmail"], - "name": "spacesAccess_spaceId_userEmail_pk" - } - }, - "uniqueConstraints": {} - }, - "storedContent": { - "name": "storedContent", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "url": { - "name": "url", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "savedAt": { - "name": "savedAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "baseUrl": { - "name": "baseUrl", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "ogImage": { - "name": "ogImage", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'page'" - }, - "image": { - "name": "image", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "user": { - "name": "user", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "noteId": { - "name": "noteId", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "storedContent_baseUrl_unique": { - "name": "storedContent_baseUrl_unique", - "columns": ["baseUrl"], - "isUnique": true - }, - "storedContent_url_idx": { - "name": "storedContent_url_idx", - "columns": ["url"], - "isUnique": false - }, - "storedContent_savedAt_idx": { - "name": "storedContent_savedAt_idx", - "columns": ["savedAt"], - "isUnique": false - }, - "storedContent_title_idx": { - "name": "storedContent_title_idx", - "columns": ["title"], - "isUnique": false - }, - "storedContent_user_idx": { - "name": "storedContent_user_idx", - "columns": ["user"], - "isUnique": false - } - }, - "foreignKeys": { - "storedContent_user_user_id_fk": { - "name": "storedContent_user_user_id_fk", - "tableFrom": "storedContent", - "tableTo": "user", - "columnsFrom": ["user"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "telegramId": { - "name": "telegramId", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "hasOnboarded": { - "name": "hasOnboarded", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": false - } - }, - "indexes": { - "users_email_idx": { - "name": "users_email_idx", - "columns": ["email"], - "isUnique": false - }, - "users_telegram_idx": { - "name": "users_telegram_idx", - "columns": ["telegramId"], - "isUnique": false - }, - "users_id_idx": { - "name": "users_id_idx", - "columns": ["id"], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": ["identifier", "token"], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - } -} + "version": "6", + "dialect": "sqlite", + "id": "1197a463-b72a-47c8-b018-ddce31ef9c31", + "prevId": "00000000-0000-0000-0000-000000000000", + "tables": { + "account": { + "name": "account", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_userId_user_id_fk": { + "name": "account_userId_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "account_provider_providerAccountId_pk": { + "columns": [ + "provider", + "providerAccountId" + ], + "name": "account_provider_providerAccountId_pk" + } + }, + "uniqueConstraints": {} + }, + "authenticator": { + "name": "authenticator", + "columns": { + "credentialID": { + "name": "credentialID", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialPublicKey": { + "name": "credentialPublicKey", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "counter": { + "name": "counter", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialDeviceType": { + "name": "credentialDeviceType", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialBackedUp": { + "name": "credentialBackedUp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "transports": { + "name": "transports", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "authenticator_credentialID_unique": { + "name": "authenticator_credentialID_unique", + "columns": [ + "credentialID" + ], + "isUnique": true + } + }, + "foreignKeys": { + "authenticator_userId_user_id_fk": { + "name": "authenticator_userId_user_id_fk", + "tableFrom": "authenticator", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "authenticator_userId_credentialID_pk": { + "columns": [ + "credentialID", + "userId" + ], + "name": "authenticator_userId_credentialID_pk" + } + }, + "uniqueConstraints": {} + }, + "canvas": { + "name": "canvas", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Untitled'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Untitled'" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "canvas_user_userId": { + "name": "canvas_user_userId", + "columns": [ + "userId" + ], + "isUnique": false + } + }, + "foreignKeys": { + "canvas_userId_user_id_fk": { + "name": "canvas_userId_user_id_fk", + "tableFrom": "canvas", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "chatHistory": { + "name": "chatHistory", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "threadId": { + "name": "threadId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "answerParts": { + "name": "answerParts", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "answerSources": { + "name": "answerSources", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "answerJustification": { + "name": "answerJustification", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'\"2024-07-29T17:06:56.122Z\"'" + } + }, + "indexes": { + "chatHistory_thread_idx": { + "name": "chatHistory_thread_idx", + "columns": [ + "threadId" + ], + "isUnique": false + } + }, + "foreignKeys": { + "chatHistory_threadId_chatThread_id_fk": { + "name": "chatHistory_threadId_chatThread_id_fk", + "tableFrom": "chatHistory", + "tableTo": "chatThread", + "columnsFrom": [ + "threadId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "chatThread": { + "name": "chatThread", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "firstMessage": { + "name": "firstMessage", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "chatThread_user_idx": { + "name": "chatThread_user_idx", + "columns": [ + "userId" + ], + "isUnique": false + } + }, + "foreignKeys": { + "chatThread_userId_user_id_fk": { + "name": "chatThread_userId_user_id_fk", + "tableFrom": "chatThread", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "contentToSpace": { + "name": "contentToSpace", + "columns": { + "contentId": { + "name": "contentId", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "spaceId": { + "name": "spaceId", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "contentToSpace_contentId_storedContent_id_fk": { + "name": "contentToSpace_contentId_storedContent_id_fk", + "tableFrom": "contentToSpace", + "tableTo": "storedContent", + "columnsFrom": [ + "contentId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contentToSpace_spaceId_space_id_fk": { + "name": "contentToSpace_spaceId_space_id_fk", + "tableFrom": "contentToSpace", + "tableTo": "space", + "columnsFrom": [ + "spaceId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "contentToSpace_contentId_spaceId_pk": { + "columns": [ + "contentId", + "spaceId" + ], + "name": "contentToSpace_contentId_spaceId_pk" + } + }, + "uniqueConstraints": {} + }, + "jobs": { + "name": "jobs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "lastAttemptAt": { + "name": "lastAttemptAt", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "blob", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updatedAt": { + "name": "updatedAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "jobs_userId_idx": { + "name": "jobs_userId_idx", + "columns": [ + "userId" + ], + "isUnique": false + }, + "jobs_status_idx": { + "name": "jobs_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "jobs_createdAt_idx": { + "name": "jobs_createdAt_idx", + "columns": [ + "createdAt" + ], + "isUnique": false + }, + "jobs_url_idx": { + "name": "jobs_url_idx", + "columns": [ + "url" + ], + "isUnique": false + } + }, + "foreignKeys": { + "jobs_userId_user_id_fk": { + "name": "jobs_userId_user_id_fk", + "tableFrom": "jobs", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "sessionToken": { + "name": "sessionToken", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "session_userId_user_id_fk": { + "name": "session_userId_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "space": { + "name": "space", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'none'" + }, + "user": { + "name": "user", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "numItems": { + "name": "numItems", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "space_name_unique": { + "name": "space_name_unique", + "columns": [ + "name" + ], + "isUnique": true + }, + "spaces_name_idx": { + "name": "spaces_name_idx", + "columns": [ + "name" + ], + "isUnique": false + }, + "spaces_user_idx": { + "name": "spaces_user_idx", + "columns": [ + "user" + ], + "isUnique": false + } + }, + "foreignKeys": { + "space_user_user_id_fk": { + "name": "space_user_user_id_fk", + "tableFrom": "space", + "tableTo": "user", + "columnsFrom": [ + "user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "spacesAccess": { + "name": "spacesAccess", + "columns": { + "spaceId": { + "name": "spaceId", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userEmail": { + "name": "userEmail", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "spacesAccess_spaceId_space_id_fk": { + "name": "spacesAccess_spaceId_space_id_fk", + "tableFrom": "spacesAccess", + "tableTo": "space", + "columnsFrom": [ + "spaceId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "spacesAccess_spaceId_userEmail_pk": { + "columns": [ + "spaceId", + "userEmail" + ], + "name": "spacesAccess_spaceId_userEmail_pk" + } + }, + "uniqueConstraints": {} + }, + "storedContent": { + "name": "storedContent", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "savedAt": { + "name": "savedAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "baseUrl": { + "name": "baseUrl", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ogImage": { + "name": "ogImage", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'page'" + }, + "image": { + "name": "image", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user": { + "name": "user", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "noteId": { + "name": "noteId", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "storedContent_baseUrl_unique": { + "name": "storedContent_baseUrl_unique", + "columns": [ + "baseUrl" + ], + "isUnique": true + }, + "storedContent_url_idx": { + "name": "storedContent_url_idx", + "columns": [ + "url" + ], + "isUnique": false + }, + "storedContent_savedAt_idx": { + "name": "storedContent_savedAt_idx", + "columns": [ + "savedAt" + ], + "isUnique": false + }, + "storedContent_title_idx": { + "name": "storedContent_title_idx", + "columns": [ + "title" + ], + "isUnique": false + }, + "storedContent_user_idx": { + "name": "storedContent_user_idx", + "columns": [ + "user" + ], + "isUnique": false + } + }, + "foreignKeys": { + "storedContent_user_user_id_fk": { + "name": "storedContent_user_user_id_fk", + "tableFrom": "storedContent", + "tableTo": "user", + "columnsFrom": [ + "user" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "emailVerified": { + "name": "emailVerified", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "telegramId": { + "name": "telegramId", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hasOnboarded": { + "name": "hasOnboarded", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + } + }, + "indexes": { + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + "email" + ], + "isUnique": false + }, + "users_telegram_idx": { + "name": "users_telegram_idx", + "columns": [ + "telegramId" + ], + "isUnique": false + }, + "users_id_idx": { + "name": "users_id_idx", + "columns": [ + "id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "verificationToken": { + "name": "verificationToken", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verificationToken_identifier_token_pk": { + "columns": [ + "identifier", + "token" + ], + "name": "verificationToken_identifier_token_pk" + } + }, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/apps/web/migrations/meta/_journal.json b/apps/web/migrations/meta/_journal.json index d79e2607..254b90c6 100644 --- a/apps/web/migrations/meta/_journal.json +++ b/apps/web/migrations/meta/_journal.json @@ -1,13 +1,13 @@ { - "version": "6", - "dialect": "sqlite", - "entries": [ - { - "idx": 0, - "version": "6", - "when": 1721946710900, - "tag": "0000_steep_moira_mactaggert", - "breakpoints": true - } - ] -} + "version": "6", + "dialect": "sqlite", + "entries": [ + { + "idx": 0, + "version": "6", + "when": 1722272816127, + "tag": "0000_omniscient_stick", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/apps/web/server/db/schema.ts b/apps/web/server/db/schema.ts index 32b80719..11711997 100644 --- a/apps/web/server/db/schema.ts +++ b/apps/web/server/db/schema.ts @@ -7,6 +7,7 @@ import { sqliteTableCreator, text, integer, + blob, } from "drizzle-orm/sqlite-core"; import type { AdapterAccountType } from "next-auth/adapters"; @@ -242,3 +243,28 @@ export const canvas = createTable( export type ChatThread = typeof chatThreads.$inferSelect; export type ChatHistory = typeof chatHistory.$inferSelect; + +export const jobs = createTable( + "jobs", + { + id: integer("id").notNull().primaryKey({ autoIncrement: true }), + userId: text("userId") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + url: text("url").notNull(), + status: text("status").notNull(), + attempts: integer("attempts").notNull().default(0), + lastAttemptAt: integer("lastAttemptAt"), + error: blob("error"), + createdAt: integer("createdAt").notNull(), + updatedAt: integer("updatedAt").notNull(), + }, + (job) => ({ + userIdx: index("jobs_userId_idx").on(job.userId), + statusIdx: index("jobs_status_idx").on(job.status), + createdAtIdx: index("jobs_createdAt_idx").on(job.createdAt), + urlIdx: index("jobs_url_idx").on(job.url), + }), +); + +export type Job = typeof jobs.$inferSelect; -- cgit v1.2.3 From 241276be588312aec4f9e09a23c7951379238da8 Mon Sep 17 00:00:00 2001 From: Kush Thaker Date: Wed, 31 Jul 2024 11:37:54 +0530 Subject: db schema in packages --- apps/web/app/(dash)/(memories)/content.tsx | 2 +- .../app/(dash)/(memories)/space/[spaceid]/page.tsx | 2 +- apps/web/app/(dash)/dialogContentContainer.tsx | 2 +- apps/web/app/(dash)/menu.tsx | 2 +- apps/web/app/actions/doers.ts | 5 +- apps/web/app/actions/fetchers.ts | 2 +- apps/web/app/api/chat/history/route.ts | 2 +- apps/web/app/api/chat/route.ts | 2 +- apps/web/app/api/ensureAuth.ts | 2 +- apps/web/app/api/getCount/route.ts | 2 +- apps/web/app/api/me/route.ts | 2 +- apps/web/app/api/memories/route.ts | 2 +- apps/web/app/api/spaces/route.ts | 2 +- apps/web/app/api/store/friend/route.ts | 44 - apps/web/app/api/store/helper.ts | 2 +- apps/web/app/api/telegram/route.ts | 2 +- apps/web/app/ref/page.tsx | 2 +- apps/web/drizzle.config.ts | 12 - apps/web/migrations/0000_omniscient_stick.sql | 152 --- apps/web/migrations/meta/0000_snapshot.json | 1027 -------------------- apps/web/migrations/meta/_journal.json | 13 - apps/web/next.config.mjs | 3 + apps/web/package.json | 1 - apps/web/server/auth.ts | 2 +- apps/web/server/db/index.ts | 2 +- apps/web/server/db/schema.ts | 270 ----- apps/web/wrangler.toml | 5 +- 27 files changed, 25 insertions(+), 1541 deletions(-) delete mode 100644 apps/web/app/api/store/friend/route.ts delete mode 100644 apps/web/drizzle.config.ts delete mode 100644 apps/web/migrations/0000_omniscient_stick.sql delete mode 100644 apps/web/migrations/meta/0000_snapshot.json delete mode 100644 apps/web/migrations/meta/_journal.json delete mode 100644 apps/web/server/db/schema.ts (limited to 'apps/web') diff --git a/apps/web/app/(dash)/(memories)/content.tsx b/apps/web/app/(dash)/(memories)/content.tsx index 4514d851..431109be 100644 --- a/apps/web/app/(dash)/(memories)/content.tsx +++ b/apps/web/app/(dash)/(memories)/content.tsx @@ -1,6 +1,6 @@ "use client"; -import { Content, StoredSpace } from "@/server/db/schema"; +import { Content, StoredSpace } from "@repo/db/schema"; import { MemoriesIcon, NextIcon, SearchIcon, UrlIcon } from "@repo/ui/icons"; import { ArrowLeftIcon, diff --git a/apps/web/app/(dash)/(memories)/space/[spaceid]/page.tsx b/apps/web/app/(dash)/(memories)/space/[spaceid]/page.tsx index ed1ea1cc..8ad9d9cc 100644 --- a/apps/web/app/(dash)/(memories)/space/[spaceid]/page.tsx +++ b/apps/web/app/(dash)/(memories)/space/[spaceid]/page.tsx @@ -3,7 +3,7 @@ import { redirect } from "next/navigation"; import MemoriesPage from "../../content"; import { db } from "@/server/db"; import { and, eq } from "drizzle-orm"; -import { spacesAccess } from "@/server/db/schema"; +import { spacesAccess } from "@repo/db/schema"; import { auth } from "@/server/auth"; async function Page({ params: { spaceid } }: { params: { spaceid: number } }) { diff --git a/apps/web/app/(dash)/dialogContentContainer.tsx b/apps/web/app/(dash)/dialogContentContainer.tsx index 4e8d81ef..c6cacd35 100644 --- a/apps/web/app/(dash)/dialogContentContainer.tsx +++ b/apps/web/app/(dash)/dialogContentContainer.tsx @@ -1,4 +1,4 @@ -import { StoredSpace } from "@/server/db/schema"; +import { StoredSpace } from "@repo/db/schema"; import { useEffect, useMemo, useState } from "react"; import { createMemory, createSpace } from "../actions/doers"; import ComboboxWithCreate from "@repo/ui/shadcn/combobox"; diff --git a/apps/web/app/(dash)/menu.tsx b/apps/web/app/(dash)/menu.tsx index 70439c7d..1acab2c8 100644 --- a/apps/web/app/(dash)/menu.tsx +++ b/apps/web/app/(dash)/menu.tsx @@ -28,7 +28,7 @@ import { getSpaces } from "../actions/fetchers"; import { HomeIcon } from "@heroicons/react/24/solid"; import { createMemory, createSpace } from "../actions/doers"; import ComboboxWithCreate from "@repo/ui/shadcn/combobox"; -import { StoredSpace } from "@/server/db/schema"; +import { StoredSpace } from "@repo/db/schema"; import useMeasure from "react-use-measure"; function Menu() { diff --git a/apps/web/app/actions/doers.ts b/apps/web/app/actions/doers.ts index 910226a5..f17032b9 100644 --- a/apps/web/app/actions/doers.ts +++ b/apps/web/app/actions/doers.ts @@ -11,7 +11,7 @@ import { spacesAccess, storedContent, users, -} from "../../server/db/schema"; +} from "@repo/db/schema"; import { ServerActionReturnType } from "./types"; import { auth } from "../../server/auth"; import { Tweet } from "react-tweet/api"; @@ -836,8 +836,7 @@ export async function getQuerySuggestions() { }; } - const fullQuery = content - .map((c) => `${c.title} \n\n${c.content}`) + const fullQuery = (content?.map((c) => `${c.title} \n\n${c.content}`) ?? []) .join(" "); const suggestionsCall = (await env.AI.run( diff --git a/apps/web/app/actions/fetchers.ts b/apps/web/app/actions/fetchers.ts index 5f72089a..f00feb3c 100644 --- a/apps/web/app/actions/fetchers.ts +++ b/apps/web/app/actions/fetchers.ts @@ -15,7 +15,7 @@ import { StoredSpace, User, users, -} from "../../server/db/schema"; +} from "@repo/db/schema"; import { ServerActionReturnType } from "./types"; import { auth } from "../../server/auth"; import { ChatHistory, SourceZod } from "@repo/shared-types"; diff --git a/apps/web/app/api/chat/history/route.ts b/apps/web/app/api/chat/history/route.ts index 98b66064..197b8ee6 100644 --- a/apps/web/app/api/chat/history/route.ts +++ b/apps/web/app/api/chat/history/route.ts @@ -2,7 +2,7 @@ import { NextRequest } from "next/server"; import { ensureAuth } from "../../ensureAuth"; import { db } from "@/server/db"; import { eq } from "drizzle-orm"; -import { chatThreads } from "@/server/db/schema"; +import { chatThreads } from "@repo/db/schema"; export const runtime = "edge"; diff --git a/apps/web/app/api/chat/route.ts b/apps/web/app/api/chat/route.ts index a14c96df..78878e40 100644 --- a/apps/web/app/api/chat/route.ts +++ b/apps/web/app/api/chat/route.ts @@ -8,7 +8,7 @@ import { import { ensureAuth } from "../ensureAuth"; import { z } from "zod"; import { db } from "@/server/db"; -import { chatHistory as chatHistoryDb, chatThreads } from "@/server/db/schema"; +import { chatHistory as chatHistoryDb, chatThreads } from "@repo/db/schema"; import { and, eq, gt, sql } from "drizzle-orm"; import { join } from "path"; diff --git a/apps/web/app/api/ensureAuth.ts b/apps/web/app/api/ensureAuth.ts index 1fcd2914..92a5e3e8 100644 --- a/apps/web/app/api/ensureAuth.ts +++ b/apps/web/app/api/ensureAuth.ts @@ -1,6 +1,6 @@ import { NextRequest } from "next/server"; import { db } from "../../server/db"; -import { accounts, sessions, users } from "../../server/db/schema"; +import { accounts, sessions, users } from "@repo/db/schema"; import { eq } from "drizzle-orm"; export async function ensureAuth(req: NextRequest) { diff --git a/apps/web/app/api/getCount/route.ts b/apps/web/app/api/getCount/route.ts index f91b7b94..4fd77efd 100644 --- a/apps/web/app/api/getCount/route.ts +++ b/apps/web/app/api/getCount/route.ts @@ -1,6 +1,6 @@ import { db } from "@/server/db"; import { and, eq, ne, sql } from "drizzle-orm"; -import { sessions, storedContent, users } from "@/server/db/schema"; +import { sessions, storedContent, users } from "@repo/db/schema"; import { type NextRequest, NextResponse } from "next/server"; import { ensureAuth } from "../ensureAuth"; diff --git a/apps/web/app/api/me/route.ts b/apps/web/app/api/me/route.ts index ab408f3e..25aa27bc 100644 --- a/apps/web/app/api/me/route.ts +++ b/apps/web/app/api/me/route.ts @@ -1,6 +1,6 @@ import { db } from "@/server/db"; import { eq } from "drizzle-orm"; -import { sessions, users } from "@/server/db/schema"; +import { sessions, users } from "@repo/db/schema"; import { type NextRequest, NextResponse } from "next/server"; export const runtime = "edge"; diff --git a/apps/web/app/api/memories/route.ts b/apps/web/app/api/memories/route.ts index acb43b5d..0084524e 100644 --- a/apps/web/app/api/memories/route.ts +++ b/apps/web/app/api/memories/route.ts @@ -6,7 +6,7 @@ import { contentToSpace, storedContent, users, -} from "@/server/db/schema"; +} from "@repo/db/schema"; import { ensureAuth } from "../ensureAuth"; export const runtime = "edge"; diff --git a/apps/web/app/api/spaces/route.ts b/apps/web/app/api/spaces/route.ts index e85e07ed..27ff0dfb 100644 --- a/apps/web/app/api/spaces/route.ts +++ b/apps/web/app/api/spaces/route.ts @@ -1,5 +1,5 @@ import { db } from "@/server/db"; -import { space } from "@/server/db/schema"; +import { space } from "@repo/db/schema"; import { eq } from "drizzle-orm"; import { NextRequest, NextResponse } from "next/server"; import { ensureAuth } from "../ensureAuth"; diff --git a/apps/web/app/api/store/friend/route.ts b/apps/web/app/api/store/friend/route.ts deleted file mode 100644 index 554b1cee..00000000 --- a/apps/web/app/api/store/friend/route.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { type NextRequest } from "next/server"; -import { createMemoryFromAPI } from "../helper"; - -type FriendData = { - id: string; - created_at: string; - transcript: string; - structured: { - title: string; - overview: string; - action_items: [ - { - description: string; - }, - ]; - }; -}; - -export async function POST(req: NextRequest) { - const body: FriendData = await req.json(); - - const userId = new URL(req.url).searchParams.get("uid"); - - if (!userId) { - return new Response( - JSON.stringify({ status: 400, body: "Missing user ID" }), - ); - } - - await createMemoryFromAPI({ - data: { - title: "Friend: " + body.structured.title, - description: body.structured.overview, - pageContent: - body.transcript + "\n\n" + JSON.stringify(body.structured.action_items), - spaces: [], - type: "note", - url: "https://basedhardware.com", - }, - userId: userId, - }); - - return new Response(JSON.stringify({ status: 200, body: "success" })); -} diff --git a/apps/web/app/api/store/helper.ts b/apps/web/app/api/store/helper.ts index f8833970..2dc42125 100644 --- a/apps/web/app/api/store/helper.ts +++ b/apps/web/app/api/store/helper.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import { db } from "@/server/db"; -import { contentToSpace, space, storedContent } from "@/server/db/schema"; +import { contentToSpace, space, storedContent } from "@repo/db/schema"; import { and, eq, inArray } from "drizzle-orm"; import { LIMITS } from "@/lib/constants"; import { limit } from "@/app/actions/doers"; diff --git a/apps/web/app/api/telegram/route.ts b/apps/web/app/api/telegram/route.ts index 78837e5f..dddfa2f4 100644 --- a/apps/web/app/api/telegram/route.ts +++ b/apps/web/app/api/telegram/route.ts @@ -1,5 +1,5 @@ import { db } from "@/server/db"; -import { storedContent, users } from "@/server/db/schema"; +import { storedContent, users } from "@repo/db/schema"; import { cipher } from "@/server/encrypt"; import { eq } from "drizzle-orm"; import { Bot, webhookCallback } from "grammy"; diff --git a/apps/web/app/ref/page.tsx b/apps/web/app/ref/page.tsx index f61e9616..c582fe5c 100644 --- a/apps/web/app/ref/page.tsx +++ b/apps/web/app/ref/page.tsx @@ -2,7 +2,7 @@ import { Button } from "@repo/ui/shadcn/button"; import { auth, signIn, signOut } from "../../server/auth"; import { db } from "../../server/db"; import { sql } from "drizzle-orm"; -import { users } from "../../server/db/schema"; +import { users } from "@repo/db/schema"; import { getThemeToggler } from "../../lib/get-theme-button"; export const runtime = "edge"; diff --git a/apps/web/drizzle.config.ts b/apps/web/drizzle.config.ts deleted file mode 100644 index 58116123..00000000 --- a/apps/web/drizzle.config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { type Config } from "drizzle-kit"; - -export default { - schema: "./server/db/schema.ts", - dialect: "sqlite", - driver: "d1", - dbCredentials: { - wranglerConfigPath: "./wrangler.toml", - dbName: "", - }, - out: "migrations", -} satisfies Config; diff --git a/apps/web/migrations/0000_omniscient_stick.sql b/apps/web/migrations/0000_omniscient_stick.sql deleted file mode 100644 index 542d6d0e..00000000 --- a/apps/web/migrations/0000_omniscient_stick.sql +++ /dev/null @@ -1,152 +0,0 @@ -CREATE TABLE `account` ( - `userId` text NOT NULL, - `type` text NOT NULL, - `provider` text NOT NULL, - `providerAccountId` text NOT NULL, - `refresh_token` text, - `access_token` text, - `expires_at` integer, - `token_type` text, - `scope` text, - `id_token` text, - `session_state` text, - PRIMARY KEY(`provider`, `providerAccountId`), - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `authenticator` ( - `credentialID` text NOT NULL, - `userId` text NOT NULL, - `providerAccountId` text NOT NULL, - `credentialPublicKey` text NOT NULL, - `counter` integer NOT NULL, - `credentialDeviceType` text NOT NULL, - `credentialBackedUp` integer NOT NULL, - `transports` text, - PRIMARY KEY(`credentialID`, `userId`), - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `canvas` ( - `id` text PRIMARY KEY NOT NULL, - `title` text DEFAULT 'Untitled' NOT NULL, - `description` text DEFAULT 'Untitled' NOT NULL, - `url` text DEFAULT '' NOT NULL, - `userId` text NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `chatHistory` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `threadId` text NOT NULL, - `question` text NOT NULL, - `answerParts` text, - `answerSources` text, - `answerJustification` text, - `createdAt` integer DEFAULT '"2024-07-29T17:06:56.122Z"' NOT NULL, - FOREIGN KEY (`threadId`) REFERENCES `chatThread`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `chatThread` ( - `id` text PRIMARY KEY NOT NULL, - `firstMessage` text NOT NULL, - `userId` text NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `contentToSpace` ( - `contentId` integer NOT NULL, - `spaceId` integer NOT NULL, - PRIMARY KEY(`contentId`, `spaceId`), - FOREIGN KEY (`contentId`) REFERENCES `storedContent`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `jobs` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `userId` text NOT NULL, - `url` text NOT NULL, - `status` text NOT NULL, - `attempts` integer DEFAULT 0 NOT NULL, - `lastAttemptAt` integer, - `error` blob, - `createdAt` integer NOT NULL, - `updatedAt` integer NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `session` ( - `sessionToken` text PRIMARY KEY NOT NULL, - `userId` text NOT NULL, - `expires` integer NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `space` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `name` text DEFAULT 'none' NOT NULL, - `user` text(255), - `createdAt` integer NOT NULL, - `numItems` integer DEFAULT 0 NOT NULL, - FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `spacesAccess` ( - `spaceId` integer NOT NULL, - `userEmail` text NOT NULL, - PRIMARY KEY(`spaceId`, `userEmail`), - FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `storedContent` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `content` text NOT NULL, - `title` text(255), - `description` text(255), - `url` text NOT NULL, - `savedAt` integer NOT NULL, - `baseUrl` text(255), - `ogImage` text(255), - `type` text DEFAULT 'page', - `image` text(255), - `user` text, - `noteId` integer, - FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `user` ( - `id` text PRIMARY KEY NOT NULL, - `name` text, - `email` text NOT NULL, - `emailVerified` integer, - `image` text, - `telegramId` text, - `hasOnboarded` integer DEFAULT false -); ---> statement-breakpoint -CREATE TABLE `verificationToken` ( - `identifier` text NOT NULL, - `token` text NOT NULL, - `expires` integer NOT NULL, - PRIMARY KEY(`identifier`, `token`) -); ---> statement-breakpoint -CREATE UNIQUE INDEX `authenticator_credentialID_unique` ON `authenticator` (`credentialID`);--> statement-breakpoint -CREATE INDEX `canvas_user_userId` ON `canvas` (`userId`);--> statement-breakpoint -CREATE INDEX `chatHistory_thread_idx` ON `chatHistory` (`threadId`);--> statement-breakpoint -CREATE INDEX `chatThread_user_idx` ON `chatThread` (`userId`);--> statement-breakpoint -CREATE INDEX `jobs_userId_idx` ON `jobs` (`userId`);--> statement-breakpoint -CREATE INDEX `jobs_status_idx` ON `jobs` (`status`);--> statement-breakpoint -CREATE INDEX `jobs_createdAt_idx` ON `jobs` (`createdAt`);--> statement-breakpoint -CREATE INDEX `jobs_url_idx` ON `jobs` (`url`);--> statement-breakpoint -CREATE UNIQUE INDEX `space_name_unique` ON `space` (`name`);--> statement-breakpoint -CREATE INDEX `spaces_name_idx` ON `space` (`name`);--> statement-breakpoint -CREATE INDEX `spaces_user_idx` ON `space` (`user`);--> statement-breakpoint -CREATE UNIQUE INDEX `storedContent_baseUrl_unique` ON `storedContent` (`baseUrl`);--> statement-breakpoint -CREATE INDEX `storedContent_url_idx` ON `storedContent` (`url`);--> statement-breakpoint -CREATE INDEX `storedContent_savedAt_idx` ON `storedContent` (`savedAt`);--> statement-breakpoint -CREATE INDEX `storedContent_title_idx` ON `storedContent` (`title`);--> statement-breakpoint -CREATE INDEX `storedContent_user_idx` ON `storedContent` (`user`);--> statement-breakpoint -CREATE INDEX `users_email_idx` ON `user` (`email`);--> statement-breakpoint -CREATE INDEX `users_telegram_idx` ON `user` (`telegramId`);--> statement-breakpoint -CREATE INDEX `users_id_idx` ON `user` (`id`); \ No newline at end of file diff --git a/apps/web/migrations/meta/0000_snapshot.json b/apps/web/migrations/meta/0000_snapshot.json deleted file mode 100644 index 8141d674..00000000 --- a/apps/web/migrations/meta/0000_snapshot.json +++ /dev/null @@ -1,1027 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "1197a463-b72a-47c8-b018-ddce31ef9c31", - "prevId": "00000000-0000-0000-0000-000000000000", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "authenticator": { - "name": "authenticator", - "columns": { - "credentialID": { - "name": "credentialID", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "credentialPublicKey": { - "name": "credentialPublicKey", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "counter": { - "name": "counter", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "credentialDeviceType": { - "name": "credentialDeviceType", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "credentialBackedUp": { - "name": "credentialBackedUp", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "transports": { - "name": "transports", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "authenticator_credentialID_unique": { - "name": "authenticator_credentialID_unique", - "columns": [ - "credentialID" - ], - "isUnique": true - } - }, - "foreignKeys": { - "authenticator_userId_user_id_fk": { - "name": "authenticator_userId_user_id_fk", - "tableFrom": "authenticator", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "authenticator_userId_credentialID_pk": { - "columns": [ - "credentialID", - "userId" - ], - "name": "authenticator_userId_credentialID_pk" - } - }, - "uniqueConstraints": {} - }, - "canvas": { - "name": "canvas", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'Untitled'" - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'Untitled'" - }, - "url": { - "name": "url", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "''" - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "canvas_user_userId": { - "name": "canvas_user_userId", - "columns": [ - "userId" - ], - "isUnique": false - } - }, - "foreignKeys": { - "canvas_userId_user_id_fk": { - "name": "canvas_userId_user_id_fk", - "tableFrom": "canvas", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "chatHistory": { - "name": "chatHistory", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "threadId": { - "name": "threadId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "question": { - "name": "question", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "answerParts": { - "name": "answerParts", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "answerSources": { - "name": "answerSources", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "answerJustification": { - "name": "answerJustification", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'\"2024-07-29T17:06:56.122Z\"'" - } - }, - "indexes": { - "chatHistory_thread_idx": { - "name": "chatHistory_thread_idx", - "columns": [ - "threadId" - ], - "isUnique": false - } - }, - "foreignKeys": { - "chatHistory_threadId_chatThread_id_fk": { - "name": "chatHistory_threadId_chatThread_id_fk", - "tableFrom": "chatHistory", - "tableTo": "chatThread", - "columnsFrom": [ - "threadId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "chatThread": { - "name": "chatThread", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "firstMessage": { - "name": "firstMessage", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "chatThread_user_idx": { - "name": "chatThread_user_idx", - "columns": [ - "userId" - ], - "isUnique": false - } - }, - "foreignKeys": { - "chatThread_userId_user_id_fk": { - "name": "chatThread_userId_user_id_fk", - "tableFrom": "chatThread", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "contentToSpace": { - "name": "contentToSpace", - "columns": { - "contentId": { - "name": "contentId", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "spaceId": { - "name": "spaceId", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "contentToSpace_contentId_storedContent_id_fk": { - "name": "contentToSpace_contentId_storedContent_id_fk", - "tableFrom": "contentToSpace", - "tableTo": "storedContent", - "columnsFrom": [ - "contentId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "contentToSpace_spaceId_space_id_fk": { - "name": "contentToSpace_spaceId_space_id_fk", - "tableFrom": "contentToSpace", - "tableTo": "space", - "columnsFrom": [ - "spaceId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "contentToSpace_contentId_spaceId_pk": { - "columns": [ - "contentId", - "spaceId" - ], - "name": "contentToSpace_contentId_spaceId_pk" - } - }, - "uniqueConstraints": {} - }, - "jobs": { - "name": "jobs", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "url": { - "name": "url", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "attempts": { - "name": "attempts", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "lastAttemptAt": { - "name": "lastAttemptAt", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "error": { - "name": "error", - "type": "blob", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "updatedAt": { - "name": "updatedAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "jobs_userId_idx": { - "name": "jobs_userId_idx", - "columns": [ - "userId" - ], - "isUnique": false - }, - "jobs_status_idx": { - "name": "jobs_status_idx", - "columns": [ - "status" - ], - "isUnique": false - }, - "jobs_createdAt_idx": { - "name": "jobs_createdAt_idx", - "columns": [ - "createdAt" - ], - "isUnique": false - }, - "jobs_url_idx": { - "name": "jobs_url_idx", - "columns": [ - "url" - ], - "isUnique": false - } - }, - "foreignKeys": { - "jobs_userId_user_id_fk": { - "name": "jobs_userId_user_id_fk", - "tableFrom": "jobs", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "space": { - "name": "space", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'none'" - }, - "user": { - "name": "user", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "numItems": { - "name": "numItems", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "space_name_unique": { - "name": "space_name_unique", - "columns": [ - "name" - ], - "isUnique": true - }, - "spaces_name_idx": { - "name": "spaces_name_idx", - "columns": [ - "name" - ], - "isUnique": false - }, - "spaces_user_idx": { - "name": "spaces_user_idx", - "columns": [ - "user" - ], - "isUnique": false - } - }, - "foreignKeys": { - "space_user_user_id_fk": { - "name": "space_user_user_id_fk", - "tableFrom": "space", - "tableTo": "user", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "spacesAccess": { - "name": "spacesAccess", - "columns": { - "spaceId": { - "name": "spaceId", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userEmail": { - "name": "userEmail", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "spacesAccess_spaceId_space_id_fk": { - "name": "spacesAccess_spaceId_space_id_fk", - "tableFrom": "spacesAccess", - "tableTo": "space", - "columnsFrom": [ - "spaceId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "spacesAccess_spaceId_userEmail_pk": { - "columns": [ - "spaceId", - "userEmail" - ], - "name": "spacesAccess_spaceId_userEmail_pk" - } - }, - "uniqueConstraints": {} - }, - "storedContent": { - "name": "storedContent", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "url": { - "name": "url", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "savedAt": { - "name": "savedAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "baseUrl": { - "name": "baseUrl", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "ogImage": { - "name": "ogImage", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'page'" - }, - "image": { - "name": "image", - "type": "text(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "user": { - "name": "user", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "noteId": { - "name": "noteId", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "storedContent_baseUrl_unique": { - "name": "storedContent_baseUrl_unique", - "columns": [ - "baseUrl" - ], - "isUnique": true - }, - "storedContent_url_idx": { - "name": "storedContent_url_idx", - "columns": [ - "url" - ], - "isUnique": false - }, - "storedContent_savedAt_idx": { - "name": "storedContent_savedAt_idx", - "columns": [ - "savedAt" - ], - "isUnique": false - }, - "storedContent_title_idx": { - "name": "storedContent_title_idx", - "columns": [ - "title" - ], - "isUnique": false - }, - "storedContent_user_idx": { - "name": "storedContent_user_idx", - "columns": [ - "user" - ], - "isUnique": false - } - }, - "foreignKeys": { - "storedContent_user_user_id_fk": { - "name": "storedContent_user_user_id_fk", - "tableFrom": "storedContent", - "tableTo": "user", - "columnsFrom": [ - "user" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "telegramId": { - "name": "telegramId", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "hasOnboarded": { - "name": "hasOnboarded", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": false - } - }, - "indexes": { - "users_email_idx": { - "name": "users_email_idx", - "columns": [ - "email" - ], - "isUnique": false - }, - "users_telegram_idx": { - "name": "users_telegram_idx", - "columns": [ - "telegramId" - ], - "isUnique": false - }, - "users_id_idx": { - "name": "users_id_idx", - "columns": [ - "id" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - } -} \ No newline at end of file diff --git a/apps/web/migrations/meta/_journal.json b/apps/web/migrations/meta/_journal.json deleted file mode 100644 index 254b90c6..00000000 --- a/apps/web/migrations/meta/_journal.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "entries": [ - { - "idx": 0, - "version": "6", - "when": 1722272816127, - "tag": "0000_omniscient_stick", - "breakpoints": true - } - ] -} \ No newline at end of file diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs index c0001fa5..934f39ae 100644 --- a/apps/web/next.config.mjs +++ b/apps/web/next.config.mjs @@ -9,6 +9,9 @@ const baseNextConfig = { env: { TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN, }, + eslint: { + disableDuringBuilds: true + } }; let selectedCofig = baseNextConfig; diff --git a/apps/web/package.json b/apps/web/package.json index 98016d8c..a5332157 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -45,7 +45,6 @@ "@types/node": "^20.11.24", "@types/react": "^18.2.61", "@types/react-dom": "^18.2.19", - "drizzle-kit": "0.21.2", "eslint": "^8.57.0", "postcss": "^8.4.38", "typescript": "^5.3.3", diff --git a/apps/web/server/auth.ts b/apps/web/server/auth.ts index 78671551..5d8b15d1 100644 --- a/apps/web/server/auth.ts +++ b/apps/web/server/auth.ts @@ -2,7 +2,7 @@ import NextAuth, { NextAuthResult } from "next-auth"; import Google from "next-auth/providers/google"; import { DrizzleAdapter } from "@auth/drizzle-adapter"; import { db } from "./db"; -import { accounts, sessions, users, verificationTokens } from "./db/schema"; +import { accounts, sessions, users, verificationTokens } from "@repo/db/schema"; export const { handlers: { GET, POST }, diff --git a/apps/web/server/db/index.ts b/apps/web/server/db/index.ts index a9ec9106..52f3e350 100644 --- a/apps/web/server/db/index.ts +++ b/apps/web/server/db/index.ts @@ -1,6 +1,6 @@ import { drizzle } from "drizzle-orm/d1"; -import * as schema from "./schema"; +import * as schema from "@repo/db/schema"; export const db = drizzle(process.env.DATABASE, { schema, diff --git a/apps/web/server/db/schema.ts b/apps/web/server/db/schema.ts deleted file mode 100644 index 11711997..00000000 --- a/apps/web/server/db/schema.ts +++ /dev/null @@ -1,270 +0,0 @@ -import { create } from "domain"; -import { relations, sql } from "drizzle-orm"; -import { - index, - int, - primaryKey, - sqliteTableCreator, - text, - integer, - blob, -} from "drizzle-orm/sqlite-core"; -import type { AdapterAccountType } from "next-auth/adapters"; - -export const createTable = sqliteTableCreator((name) => `${name}`); - -export const users = createTable( - "user", - { - id: text("id") - .primaryKey() - .$defaultFn(() => crypto.randomUUID()), - name: text("name"), - email: text("email").notNull(), - emailVerified: integer("emailVerified", { mode: "timestamp_ms" }), - image: text("image"), - telegramId: text("telegramId"), - hasOnboarded: integer("hasOnboarded", { mode: "boolean" }).default(false), - }, - (user) => ({ - emailIdx: index("users_email_idx").on(user.email), - telegramIdx: index("users_telegram_idx").on(user.telegramId), - idIdx: index("users_id_idx").on(user.id), - }), -); - -export type User = typeof users.$inferSelect; - -export const accounts = createTable( - "account", - { - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - type: text("type").$type().notNull(), - provider: text("provider").notNull(), - providerAccountId: text("providerAccountId").notNull(), - refresh_token: text("refresh_token"), - access_token: text("access_token"), - expires_at: integer("expires_at"), - token_type: text("token_type"), - scope: text("scope"), - id_token: text("id_token"), - session_state: text("session_state"), - }, - (account) => ({ - compoundKey: primaryKey({ - columns: [account.provider, account.providerAccountId], - }), - }), -); - -export const sessions = createTable("session", { - sessionToken: text("sessionToken").primaryKey(), - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - expires: integer("expires", { mode: "timestamp_ms" }).notNull(), -}); - -export const verificationTokens = createTable( - "verificationToken", - { - identifier: text("identifier").notNull(), - token: text("token").notNull(), - expires: integer("expires", { mode: "timestamp_ms" }).notNull(), - }, - (verificationToken) => ({ - compositePk: primaryKey({ - columns: [verificationToken.identifier, verificationToken.token], - }), - }), -); - -export const authenticators = createTable( - "authenticator", - { - credentialID: text("credentialID").notNull().unique(), - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - providerAccountId: text("providerAccountId").notNull(), - credentialPublicKey: text("credentialPublicKey").notNull(), - counter: integer("counter").notNull(), - credentialDeviceType: text("credentialDeviceType").notNull(), - credentialBackedUp: integer("credentialBackedUp", { - mode: "boolean", - }).notNull(), - transports: text("transports"), - }, - (authenticator) => ({ - compositePK: primaryKey({ - columns: [authenticator.userId, authenticator.credentialID], - }), - }), -); - -export const storedContent = createTable( - "storedContent", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - content: text("content").notNull(), - title: text("title", { length: 255 }), - description: text("description", { length: 255 }), - url: text("url").notNull(), - savedAt: int("savedAt", { mode: "timestamp" }).notNull(), - baseUrl: text("baseUrl", { length: 255 }).unique(), - ogImage: text("ogImage", { length: 255 }), - type: text("type").default("page"), - image: text("image", { length: 255 }), - userId: text("user").references(() => users.id, { - onDelete: "cascade", - }), - noteId: integer("noteId"), - }, - (sc) => ({ - urlIdx: index("storedContent_url_idx").on(sc.url), - savedAtIdx: index("storedContent_savedAt_idx").on(sc.savedAt), - titleInx: index("storedContent_title_idx").on(sc.title), - userIdx: index("storedContent_user_idx").on(sc.userId), - }), -); - -export type Content = typeof storedContent.$inferSelect; - -export const contentToSpace = createTable( - "contentToSpace", - { - contentId: integer("contentId") - .notNull() - .references(() => storedContent.id, { onDelete: "cascade" }), - spaceId: integer("spaceId") - .notNull() - .references(() => space.id, { onDelete: "cascade" }), - }, - (cts) => ({ - compoundKey: primaryKey({ columns: [cts.contentId, cts.spaceId] }), - }), -); - -export const space = createTable( - "space", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - name: text("name").notNull().unique().default("none"), - user: text("user", { length: 255 }).references(() => users.id, { - onDelete: "cascade", - }), - createdAt: int("createdAt", { mode: "timestamp" }).notNull(), - numItems: integer("numItems").notNull().default(0), - }, - (space) => ({ - nameIdx: index("spaces_name_idx").on(space.name), - userIdx: index("spaces_user_idx").on(space.user), - }), -); - -export const spacesAccess = createTable( - "spacesAccess", - { - spaceId: integer("spaceId") - .notNull() - .references(() => space.id, { onDelete: "cascade" }), - userEmail: text("userEmail").notNull(), - }, - (spaceAccess) => ({ - compoundKey: primaryKey({ - columns: [spaceAccess.spaceId, spaceAccess.userEmail], - }), - }), -); - -export type StoredContent = Omit; -export type StoredSpace = typeof space.$inferSelect; -export type ChachedSpaceContent = StoredContent & { - space: number; -}; - -export const chatThreads = createTable( - "chatThread", - { - id: text("id") - .notNull() - .primaryKey() - .$defaultFn(() => crypto.randomUUID()), - firstMessage: text("firstMessage").notNull(), - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - }, - (thread) => ({ - userIdx: index("chatThread_user_idx").on(thread.userId), - }), -); - -export const chatHistory = createTable( - "chatHistory", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - threadId: text("threadId") - .notNull() - .references(() => chatThreads.id, { onDelete: "cascade" }), - question: text("question").notNull(), - answer: text("answerParts"), // Single answer part as string - answerSources: text("answerSources"), // JSON stringified array of objects - answerJustification: text("answerJustification"), - createdAt: int("createdAt", { mode: "timestamp" }) - .notNull() - .default(new Date()), - }, - (history) => ({ - threadIdx: index("chatHistory_thread_idx").on(history.threadId), - }), -); - -export const canvas = createTable( - "canvas", - { - id: text("id") - .notNull() - .primaryKey() - .$defaultFn(() => crypto.randomUUID()), - title: text("title").default("Untitled").notNull(), - description: text("description").default("Untitled").notNull(), - imageUrl: text("url").default("").notNull(), - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - }, - (canvas) => ({ - userIdx: index("canvas_user_userId").on(canvas.userId), - }), -); - -export type ChatThread = typeof chatThreads.$inferSelect; -export type ChatHistory = typeof chatHistory.$inferSelect; - -export const jobs = createTable( - "jobs", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - url: text("url").notNull(), - status: text("status").notNull(), - attempts: integer("attempts").notNull().default(0), - lastAttemptAt: integer("lastAttemptAt"), - error: blob("error"), - createdAt: integer("createdAt").notNull(), - updatedAt: integer("updatedAt").notNull(), - }, - (job) => ({ - userIdx: index("jobs_userId_idx").on(job.userId), - statusIdx: index("jobs_status_idx").on(job.status), - createdAtIdx: index("jobs_createdAt_idx").on(job.createdAt), - urlIdx: index("jobs_url_idx").on(job.url), - }), -); - -export type Job = typeof jobs.$inferSelect; diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 7f3fa047..7c4f63c8 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -26,8 +26,9 @@ bucket_name = "dev-r2-anycontext" [[d1_databases]] binding = "DATABASE" -database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" +database_name = "supermemlocal" +database_id = "0f93c990-72fb-489c-8563-57a7bb18dc43" + [[env.production.d1_databases]] -- cgit v1.2.3 From 4e018fb3465d5e418efda627401fa0d21c03290e Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Wed, 31 Jul 2024 00:48:03 -0700 Subject: drizzle logic back in apps/web other stuff in the same place. --- apps/web/drizzle.config.ts | 12 + apps/web/migrations/0000_fixed_pandemic.sql | 152 +++++ apps/web/migrations/meta/0000_snapshot.json | 926 ++++++++++++++++++++++++++++ apps/web/migrations/meta/_journal.json | 13 + apps/web/next.config.mjs | 40 +- apps/web/wrangler.toml | 6 +- 6 files changed, 1107 insertions(+), 42 deletions(-) create mode 100644 apps/web/drizzle.config.ts create mode 100644 apps/web/migrations/0000_fixed_pandemic.sql create mode 100644 apps/web/migrations/meta/0000_snapshot.json create mode 100644 apps/web/migrations/meta/_journal.json (limited to 'apps/web') diff --git a/apps/web/drizzle.config.ts b/apps/web/drizzle.config.ts new file mode 100644 index 00000000..5df2ca29 --- /dev/null +++ b/apps/web/drizzle.config.ts @@ -0,0 +1,12 @@ +import { type Config } from "drizzle-kit"; + +export default { + schema: "../../packages/db/schema.ts", + dialect: "sqlite", + driver: "d1", + dbCredentials: { + wranglerConfigPath: "./wrangler.toml", + dbName: "", + }, + out: "migrations", +} satisfies Config; diff --git a/apps/web/migrations/0000_fixed_pandemic.sql b/apps/web/migrations/0000_fixed_pandemic.sql new file mode 100644 index 00000000..09b5431a --- /dev/null +++ b/apps/web/migrations/0000_fixed_pandemic.sql @@ -0,0 +1,152 @@ +CREATE TABLE `account` ( + `userId` text NOT NULL, + `type` text NOT NULL, + `provider` text NOT NULL, + `providerAccountId` text NOT NULL, + `refresh_token` text, + `access_token` text, + `expires_at` integer, + `token_type` text, + `scope` text, + `id_token` text, + `session_state` text, + PRIMARY KEY(`provider`, `providerAccountId`), + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `authenticator` ( + `credentialID` text NOT NULL, + `userId` text NOT NULL, + `providerAccountId` text NOT NULL, + `credentialPublicKey` text NOT NULL, + `counter` integer NOT NULL, + `credentialDeviceType` text NOT NULL, + `credentialBackedUp` integer NOT NULL, + `transports` text, + PRIMARY KEY(`credentialID`, `userId`), + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `canvas` ( + `id` text PRIMARY KEY NOT NULL, + `title` text DEFAULT 'Untitled' NOT NULL, + `description` text DEFAULT 'Untitled' NOT NULL, + `url` text DEFAULT '' NOT NULL, + `userId` text NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `chatHistory` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `threadId` text NOT NULL, + `question` text NOT NULL, + `answerParts` text, + `answerSources` text, + `answerJustification` text, + `createdAt` integer DEFAULT '"2024-07-31T07:35:53.819Z"' NOT NULL, + FOREIGN KEY (`threadId`) REFERENCES `chatThread`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `chatThread` ( + `id` text PRIMARY KEY NOT NULL, + `firstMessage` text NOT NULL, + `userId` text NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `contentToSpace` ( + `contentId` integer NOT NULL, + `spaceId` integer NOT NULL, + PRIMARY KEY(`contentId`, `spaceId`), + FOREIGN KEY (`contentId`) REFERENCES `storedContent`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `jobs` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `userId` text NOT NULL, + `url` text NOT NULL, + `status` text NOT NULL, + `attempts` integer DEFAULT 0 NOT NULL, + `lastAttemptAt` integer, + `error` blob, + `createdAt` integer NOT NULL, + `updatedAt` integer NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `session` ( + `sessionToken` text PRIMARY KEY NOT NULL, + `userId` text NOT NULL, + `expires` integer NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `space` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text DEFAULT 'none' NOT NULL, + `user` text(255), + `createdAt` integer NOT NULL, + `numItems` integer DEFAULT 0 NOT NULL, + FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `spacesAccess` ( + `spaceId` integer NOT NULL, + `userEmail` text NOT NULL, + PRIMARY KEY(`spaceId`, `userEmail`), + FOREIGN KEY (`spaceId`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `storedContent` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `content` text NOT NULL, + `title` text(255), + `description` text(255), + `url` text NOT NULL, + `savedAt` integer NOT NULL, + `baseUrl` text(255), + `ogImage` text(255), + `type` text DEFAULT 'page', + `image` text(255), + `user` text, + `noteId` integer, + FOREIGN KEY (`user`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `user` ( + `id` text PRIMARY KEY NOT NULL, + `name` text, + `email` text NOT NULL, + `emailVerified` integer, + `image` text, + `telegramId` text, + `hasOnboarded` integer DEFAULT false +); +--> statement-breakpoint +CREATE TABLE `verificationToken` ( + `identifier` text NOT NULL, + `token` text NOT NULL, + `expires` integer NOT NULL, + PRIMARY KEY(`identifier`, `token`) +); +--> statement-breakpoint +CREATE UNIQUE INDEX `authenticator_credentialID_unique` ON `authenticator` (`credentialID`);--> statement-breakpoint +CREATE INDEX `canvas_user_userId` ON `canvas` (`userId`);--> statement-breakpoint +CREATE INDEX `chatHistory_thread_idx` ON `chatHistory` (`threadId`);--> statement-breakpoint +CREATE INDEX `chatThread_user_idx` ON `chatThread` (`userId`);--> statement-breakpoint +CREATE INDEX `jobs_userId_idx` ON `jobs` (`userId`);--> statement-breakpoint +CREATE INDEX `jobs_status_idx` ON `jobs` (`status`);--> statement-breakpoint +CREATE INDEX `jobs_createdAt_idx` ON `jobs` (`createdAt`);--> statement-breakpoint +CREATE INDEX `jobs_url_idx` ON `jobs` (`url`);--> statement-breakpoint +CREATE UNIQUE INDEX `space_name_unique` ON `space` (`name`);--> statement-breakpoint +CREATE INDEX `spaces_name_idx` ON `space` (`name`);--> statement-breakpoint +CREATE INDEX `spaces_user_idx` ON `space` (`user`);--> statement-breakpoint +CREATE UNIQUE INDEX `storedContent_baseUrl_unique` ON `storedContent` (`baseUrl`);--> statement-breakpoint +CREATE INDEX `storedContent_url_idx` ON `storedContent` (`url`);--> statement-breakpoint +CREATE INDEX `storedContent_savedAt_idx` ON `storedContent` (`savedAt`);--> statement-breakpoint +CREATE INDEX `storedContent_title_idx` ON `storedContent` (`title`);--> statement-breakpoint +CREATE INDEX `storedContent_user_idx` ON `storedContent` (`user`);--> statement-breakpoint +CREATE INDEX `users_email_idx` ON `user` (`email`);--> statement-breakpoint +CREATE INDEX `users_telegram_idx` ON `user` (`telegramId`);--> statement-breakpoint +CREATE INDEX `users_id_idx` ON `user` (`id`); \ No newline at end of file diff --git a/apps/web/migrations/meta/0000_snapshot.json b/apps/web/migrations/meta/0000_snapshot.json new file mode 100644 index 00000000..3bb8617f --- /dev/null +++ b/apps/web/migrations/meta/0000_snapshot.json @@ -0,0 +1,926 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "3fbdb153-2764-4b09-ac22-05c3a131ec35", + "prevId": "00000000-0000-0000-0000-000000000000", + "tables": { + "account": { + "name": "account", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_userId_user_id_fk": { + "name": "account_userId_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "account_provider_providerAccountId_pk": { + "columns": ["provider", "providerAccountId"], + "name": "account_provider_providerAccountId_pk" + } + }, + "uniqueConstraints": {} + }, + "authenticator": { + "name": "authenticator", + "columns": { + "credentialID": { + "name": "credentialID", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialPublicKey": { + "name": "credentialPublicKey", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "counter": { + "name": "counter", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialDeviceType": { + "name": "credentialDeviceType", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialBackedUp": { + "name": "credentialBackedUp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "transports": { + "name": "transports", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "authenticator_credentialID_unique": { + "name": "authenticator_credentialID_unique", + "columns": ["credentialID"], + "isUnique": true + } + }, + "foreignKeys": { + "authenticator_userId_user_id_fk": { + "name": "authenticator_userId_user_id_fk", + "tableFrom": "authenticator", + "tableTo": "user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "authenticator_userId_credentialID_pk": { + "columns": ["credentialID", "userId"], + "name": "authenticator_userId_credentialID_pk" + } + }, + "uniqueConstraints": {} + }, + "canvas": { + "name": "canvas", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Untitled'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Untitled'" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "canvas_user_userId": { + "name": "canvas_user_userId", + "columns": ["userId"], + "isUnique": false + } + }, + "foreignKeys": { + "canvas_userId_user_id_fk": { + "name": "canvas_userId_user_id_fk", + "tableFrom": "canvas", + "tableTo": "user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "chatHistory": { + "name": "chatHistory", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "threadId": { + "name": "threadId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "answerParts": { + "name": "answerParts", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "answerSources": { + "name": "answerSources", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "answerJustification": { + "name": "answerJustification", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'\"2024-07-31T07:35:53.819Z\"'" + } + }, + "indexes": { + "chatHistory_thread_idx": { + "name": "chatHistory_thread_idx", + "columns": ["threadId"], + "isUnique": false + } + }, + "foreignKeys": { + "chatHistory_threadId_chatThread_id_fk": { + "name": "chatHistory_threadId_chatThread_id_fk", + "tableFrom": "chatHistory", + "tableTo": "chatThread", + "columnsFrom": ["threadId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "chatThread": { + "name": "chatThread", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "firstMessage": { + "name": "firstMessage", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "chatThread_user_idx": { + "name": "chatThread_user_idx", + "columns": ["userId"], + "isUnique": false + } + }, + "foreignKeys": { + "chatThread_userId_user_id_fk": { + "name": "chatThread_userId_user_id_fk", + "tableFrom": "chatThread", + "tableTo": "user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "contentToSpace": { + "name": "contentToSpace", + "columns": { + "contentId": { + "name": "contentId", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "spaceId": { + "name": "spaceId", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "contentToSpace_contentId_storedContent_id_fk": { + "name": "contentToSpace_contentId_storedContent_id_fk", + "tableFrom": "contentToSpace", + "tableTo": "storedContent", + "columnsFrom": ["contentId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contentToSpace_spaceId_space_id_fk": { + "name": "contentToSpace_spaceId_space_id_fk", + "tableFrom": "contentToSpace", + "tableTo": "space", + "columnsFrom": ["spaceId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "contentToSpace_contentId_spaceId_pk": { + "columns": ["contentId", "spaceId"], + "name": "contentToSpace_contentId_spaceId_pk" + } + }, + "uniqueConstraints": {} + }, + "jobs": { + "name": "jobs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "lastAttemptAt": { + "name": "lastAttemptAt", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "blob", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updatedAt": { + "name": "updatedAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "jobs_userId_idx": { + "name": "jobs_userId_idx", + "columns": ["userId"], + "isUnique": false + }, + "jobs_status_idx": { + "name": "jobs_status_idx", + "columns": ["status"], + "isUnique": false + }, + "jobs_createdAt_idx": { + "name": "jobs_createdAt_idx", + "columns": ["createdAt"], + "isUnique": false + }, + "jobs_url_idx": { + "name": "jobs_url_idx", + "columns": ["url"], + "isUnique": false + } + }, + "foreignKeys": { + "jobs_userId_user_id_fk": { + "name": "jobs_userId_user_id_fk", + "tableFrom": "jobs", + "tableTo": "user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "sessionToken": { + "name": "sessionToken", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "session_userId_user_id_fk": { + "name": "session_userId_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "space": { + "name": "space", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'none'" + }, + "user": { + "name": "user", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "numItems": { + "name": "numItems", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "space_name_unique": { + "name": "space_name_unique", + "columns": ["name"], + "isUnique": true + }, + "spaces_name_idx": { + "name": "spaces_name_idx", + "columns": ["name"], + "isUnique": false + }, + "spaces_user_idx": { + "name": "spaces_user_idx", + "columns": ["user"], + "isUnique": false + } + }, + "foreignKeys": { + "space_user_user_id_fk": { + "name": "space_user_user_id_fk", + "tableFrom": "space", + "tableTo": "user", + "columnsFrom": ["user"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "spacesAccess": { + "name": "spacesAccess", + "columns": { + "spaceId": { + "name": "spaceId", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userEmail": { + "name": "userEmail", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "spacesAccess_spaceId_space_id_fk": { + "name": "spacesAccess_spaceId_space_id_fk", + "tableFrom": "spacesAccess", + "tableTo": "space", + "columnsFrom": ["spaceId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "spacesAccess_spaceId_userEmail_pk": { + "columns": ["spaceId", "userEmail"], + "name": "spacesAccess_spaceId_userEmail_pk" + } + }, + "uniqueConstraints": {} + }, + "storedContent": { + "name": "storedContent", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "savedAt": { + "name": "savedAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "baseUrl": { + "name": "baseUrl", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ogImage": { + "name": "ogImage", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'page'" + }, + "image": { + "name": "image", + "type": "text(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user": { + "name": "user", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "noteId": { + "name": "noteId", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "storedContent_baseUrl_unique": { + "name": "storedContent_baseUrl_unique", + "columns": ["baseUrl"], + "isUnique": true + }, + "storedContent_url_idx": { + "name": "storedContent_url_idx", + "columns": ["url"], + "isUnique": false + }, + "storedContent_savedAt_idx": { + "name": "storedContent_savedAt_idx", + "columns": ["savedAt"], + "isUnique": false + }, + "storedContent_title_idx": { + "name": "storedContent_title_idx", + "columns": ["title"], + "isUnique": false + }, + "storedContent_user_idx": { + "name": "storedContent_user_idx", + "columns": ["user"], + "isUnique": false + } + }, + "foreignKeys": { + "storedContent_user_user_id_fk": { + "name": "storedContent_user_user_id_fk", + "tableFrom": "storedContent", + "tableTo": "user", + "columnsFrom": ["user"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "emailVerified": { + "name": "emailVerified", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "telegramId": { + "name": "telegramId", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hasOnboarded": { + "name": "hasOnboarded", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + } + }, + "indexes": { + "users_email_idx": { + "name": "users_email_idx", + "columns": ["email"], + "isUnique": false + }, + "users_telegram_idx": { + "name": "users_telegram_idx", + "columns": ["telegramId"], + "isUnique": false + }, + "users_id_idx": { + "name": "users_id_idx", + "columns": ["id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "verificationToken": { + "name": "verificationToken", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verificationToken_identifier_token_pk": { + "columns": ["identifier", "token"], + "name": "verificationToken_identifier_token_pk" + } + }, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} diff --git a/apps/web/migrations/meta/_journal.json b/apps/web/migrations/meta/_journal.json new file mode 100644 index 00000000..59ab4ea6 --- /dev/null +++ b/apps/web/migrations/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "6", + "dialect": "sqlite", + "entries": [ + { + "idx": 0, + "version": "6", + "when": 1722411353835, + "tag": "0000_fixed_pandemic", + "breakpoints": true + } + ] +} diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs index 934f39ae..307d5bdc 100644 --- a/apps/web/next.config.mjs +++ b/apps/web/next.config.mjs @@ -1,6 +1,5 @@ import MillionLint from "@million/lint"; import { setupDevPlatform } from "@cloudflare/next-on-pages/next-dev"; -import { withSentryConfig } from "@sentry/nextjs"; /** @type {import('next').NextConfig} */ const baseNextConfig = { @@ -10,8 +9,8 @@ const baseNextConfig = { TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN, }, eslint: { - disableDuringBuilds: true - } + disableDuringBuilds: true, + }, }; let selectedCofig = baseNextConfig; @@ -24,41 +23,6 @@ if (process.env.NODE_ENV === "development") { export default selectedCofig; -//! Disabled sentry for now because of unreasonably large bundle size -// export default withSentryConfig(selectedCofig, { -// // For all available options, see: -// // https://github.com/getsentry/sentry-webpack-plugin#options - -// org: "none-h00", -// project: "javascript-nextjs", -// // Only print logs for uploading source maps in CI -// silent: !process.env.CI, - -// // For all available options, see: -// // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ - -// // Upload a larger set of source maps for prettier stack traces (increases build time) -// widenClientFileUpload: true, - -// // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. -// // This can increase your server load as well as your hosting bill. -// // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- -// // side errors will fail. -// tunnelRoute: "/monitoring", - -// // Hides source maps from generated client bundles -// hideSourceMaps: true, - -// // Automatically tree-shake Sentry logger statements to reduce bundle size -// disableLogger: true, - -// // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.) -// // See the following for more information: -// // https://docs.sentry.io/product/crons/ -// // https://vercel.com/docs/cron-jobs -// automaticVercelMonitors: true, -// }); - // we only need to use the utility during development so we can check NODE_ENV // (note: this check is recommended but completely optional) if (process.env.NODE_ENV === "development") { diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 7c4f63c8..a6232450 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -26,10 +26,8 @@ bucket_name = "dev-r2-anycontext" [[d1_databases]] binding = "DATABASE" -database_name = "supermemlocal" -database_id = "0f93c990-72fb-489c-8563-57a7bb18dc43" - - +database_name = "dev-d1-anycontext" +database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" [[env.production.d1_databases]] binding = "DATABASE" -- cgit v1.2.3 From e4fd7f5aacc3c9f7f000e1858248d49aa4d3410e Mon Sep 17 00:00:00 2001 From: Kush Thaker Date: Mon, 5 Aug 2024 21:25:11 +0530 Subject: move limit to backend and thread service binding --- apps/web/app/actions/doers.ts | 526 +++++++++++++++++++-------------------- apps/web/app/api/store/helper.ts | 18 +- apps/web/lib/constants.ts | 6 - 3 files changed, 268 insertions(+), 282 deletions(-) (limited to 'apps/web') diff --git a/apps/web/app/actions/doers.ts b/apps/web/app/actions/doers.ts index f17032b9..500a8608 100644 --- a/apps/web/app/actions/doers.ts +++ b/apps/web/app/actions/doers.ts @@ -17,7 +17,7 @@ import { auth } from "../../server/auth"; import { Tweet } from "react-tweet/api"; // import { getMetaData } from "@/lib/get-metadata"; import { and, eq, inArray, sql } from "drizzle-orm"; -import { LIMITS } from "@/lib/constants"; +import { LIMITS } from "@repo/shared-types"; import { ChatHistory } from "@repo/shared-types"; import { decipher } from "@/server/encrypt"; import { redirect } from "next/navigation"; @@ -104,25 +104,6 @@ const typeDecider = (content: string): "page" | "tweet" | "note" => { } }; -export const limit = async ( - userId: string, - type = "page", - items: number = 1, -) => { - const countResult = await db - .select({ - count: sql`count(*)`.mapWith(Number), - }) - .from(storedContent) - .where(and(eq(storedContent.userId, userId), eq(storedContent.type, type))); - - const currentCount = countResult[0]?.count || 0; - const totalLimit = LIMITS[type as keyof typeof LIMITS]; - const remainingLimit = totalLimit - currentCount; - - return items <= remainingLimit; -}; - export const addUserToSpace = async (userEmail: string, spaceId: number) => { const data = await auth(); @@ -197,7 +178,6 @@ export const createMemory = async (input: { return { error: "Not authenticated", success: false }; } - // make the backend reqeust for the queue here const vectorSaveResponses = await fetch( `${process.env.BACKEND_BASE_URL}/api/add`, @@ -214,250 +194,262 @@ export const createMemory = async (input: { }, }, ); + const response = (await vectorSaveResponses.json()) as { + status: string; + message?: string; + }; + + if (response.status !== "ok") { + return { + success: false, + data: 0, + error: response.message, + }; + } -// const type = typeDecider(input.content); - -// let pageContent = input.content; -// let metadata: Awaited>; -// let vectorData: string; - -// if (!(await limit(data.user.id, type))) { -// return { -// success: false, -// data: 0, -// error: `You have exceeded the limit of ${LIMITS[type as keyof typeof LIMITS]} ${type}s.`, -// }; -// } - -// let noteId = 0; - -// if (type === "page") { -// const response = await fetch("https://md.dhr.wtf/?url=" + input.content, { -// headers: { -// Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, -// }, -// }); -// pageContent = await response.text(); -// vectorData = pageContent; -// try { -// metadata = await getMetaData(input.content); -// } catch (e) { -// return { -// success: false, -// error: "Failed to fetch metadata for the page. Please try again later.", -// }; -// } -// } else if (type === "tweet") { -// //Request the worker for the entire thread - -// let thread: string; -// let errorOccurred: boolean = false; - -// try { -// const cf_thread_endpoint = process.env.THREAD_CF_WORKER; -// const authKey = process.env.THREAD_CF_AUTH; -// const threadRequest = await fetch(cf_thread_endpoint, { -// method: "POST", -// headers: { -// "Content-Type": "application/json", -// Authorization: authKey, -// }, -// body: JSON.stringify({ url: input.content }), -// }); - -// if (threadRequest.status !== 200) { -// throw new Error( -// `Failed to fetch the thread: ${input.content}, Reason: ${threadRequest.statusText}`, -// ); -// } - -// thread = await threadRequest.text(); -// if (thread.trim().length === 2) { -// console.log("Thread is an empty array"); -// throw new Error( -// "[THREAD FETCHING SERVICE] Got no content form thread worker", -// ); -// } -// } catch (e) { -// console.log("[THREAD FETCHING SERVICE] Failed to fetch the thread", e); -// errorOccurred = true; -// } - -// const tweet = await getTweetData(input.content.split("/").pop() as string); - -// pageContent = tweetToMd(tweet); -// console.log("THis ishte page content!!", pageContent); -// //@ts-ignore -// vectorData = errorOccurred ? JSON.stringify(pageContent) : thread; -// metadata = { -// baseUrl: input.content, -// description: tweet.text.slice(0, 200), -// image: tweet.user.profile_image_url_https, -// title: `Tweet by ${tweet.user.name}`, -// }; -// } else if (type === "note") { -// pageContent = input.content; -// vectorData = pageContent; -// noteId = new Date().getTime(); -// metadata = { -// baseUrl: `https://supermemory.ai/note/${noteId}`, -// description: `Note created at ${new Date().toLocaleString()}`, -// image: "https://supermemory.ai/logo.png", -// title: `${pageContent.slice(0, 20)} ${pageContent.length > 20 ? "..." : ""}`, -// }; -// } else { -// return { -// success: false, -// data: 0, -// error: "Invalid type", -// }; -// } - -// let storeToSpaces = input.spaces; - -// if (!storeToSpaces) { -// storeToSpaces = []; -// } - -// const vectorSaveResponse = await fetch( -// `${process.env.BACKEND_BASE_URL}/api/add`, -// { -// method: "POST", -// body: JSON.stringify({ -// pageContent: vectorData, -// title: metadata.title, -// description: metadata.description, -// url: metadata.baseUrl, -// spaces: storeToSpaces.map((spaceId) => spaceId.toString()), -// user: data.user.id, -// type, -// }), -// headers: { -// "Content-Type": "application/json", -// Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, -// }, -// }, -// ); - -// if (!vectorSaveResponse.ok) { -// const errorData = await vectorSaveResponse.text(); -// console.error(errorData); -// return { -// success: false, -// data: 0, -// error: `Failed to save to vector store. Backend returned error: ${errorData}`, -// }; -// } - -// let contentId: number; - -// const response = (await vectorSaveResponse.json()) as { -// status: string; -// chunkedInput: string; -// message?: string; -// }; - -// try { -// if (response.status !== "ok") { -// if (response.status === "error") { -// return { -// success: false, -// data: 0, -// error: response.message, -// }; -// } else { -// return { -// success: false, -// data: 0, -// error: `Failed to save to vector store. Backend returned error: ${response.message}`, -// }; -// } -// } -// } catch (e) { -// return { -// success: false, -// data: 0, -// error: `Failed to save to vector store. Backend returned error: ${e}`, -// }; -// } - -// const saveToDbUrl = -// (metadata.baseUrl.split("#supermemory-user-")[0] ?? metadata.baseUrl) + -// "#supermemory-user-" + -// data.user.id; - -// // Insert into database -// try { -// const insertResponse = await db -// .insert(storedContent) -// .values({ -// content: pageContent, -// title: metadata.title, -// description: metadata.description, -// url: saveToDbUrl, -// baseUrl: saveToDbUrl, -// image: metadata.image, -// savedAt: new Date(), -// userId: data.user.id, -// type, -// noteId, -// }) -// .returning({ id: storedContent.id }); -// revalidatePath("/memories"); -// revalidatePath("/home"); - -// if (!insertResponse[0]?.id) { -// return { -// success: false, -// data: 0, -// error: "Something went wrong while saving the document to the database", -// }; -// } - -// contentId = insertResponse[0]?.id; -// } catch (e) { -// const error = e as Error; -// console.log("Error: ", error.message); - -// if ( -// error.message.includes( -// "D1_ERROR: UNIQUE constraint failed: storedContent.baseUrl", -// ) -// ) { -// return { -// success: false, -// data: 0, -// error: "Content already exists", -// }; -// } - -// return { -// success: false, -// data: 0, -// error: "Failed to save to database with error: " + error.message, -// }; -// } - -// if (storeToSpaces.length > 0) { -// // Adding the many-to-many relationship between content and spaces -// const spaceData = await db -// .select() -// .from(space) -// .where( -// and(inArray(space.id, storeToSpaces), eq(space.user, data.user.id)), -// ) -// .all(); - -// await Promise.all( -// spaceData.map(async (s) => { -// await db -// .insert(contentToSpace) -// .values({ contentId: contentId, spaceId: s.id }); - -// await db.update(space).set({ numItems: s.numItems + 1 }); -// }), -// ); -// } + // const type = typeDecider(input.content); + + // let pageContent = input.content; + // let metadata: Awaited>; + // let vectorData: string; + + // if (!(await limit(data.user.id, type))) { + // return { + // success: false, + // data: 0, + // error: `You have exceeded the limit of ${LIMITS[type as keyof typeof LIMITS]} ${type}s.`, + // }; + // } --> How would this fit in the backend??? + + // let noteId = 0; + + // if (type === "page") { + // const response = await fetch("https://md.dhr.wtf/?url=" + input.content, { + // headers: { + // Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, + // }, + // }); + // pageContent = await response.text(); + // vectorData = pageContent; + // try { + // metadata = await getMetaData(input.content); + // } catch (e) { + // return { + // success: false, + // error: "Failed to fetch metadata for the page. Please try again later.", + // }; + // } + // } else if (type === "tweet") { + // //Request the worker for the entire thread + + // let thread: string; + // let errorOccurred: boolean = false; + + // try { + // const cf_thread_endpoint = process.env.THREAD_CF_WORKER; + // const authKey = process.env.THREAD_CF_AUTH; + // const threadRequest = await fetch(cf_thread_endpoint, { + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: authKey, + // }, + // body: JSON.stringify({ url: input.content }), + // }); + + // if (threadRequest.status !== 200) { + // throw new Error( + // `Failed to fetch the thread: ${input.content}, Reason: ${threadRequest.statusText}`, + // ); + // } + + // thread = await threadRequest.text(); + // if (thread.trim().length === 2) { + // console.log("Thread is an empty array"); + // throw new Error( + // "[THREAD FETCHING SERVICE] Got no content form thread worker", + // ); + // } + // } catch (e) { + // console.log("[THREAD FETCHING SERVICE] Failed to fetch the thread", e); + // errorOccurred = true; + // } + + // const tweet = await getTweetData(input.content.split("/").pop() as string); + + // pageContent = tweetToMd(tweet); + // console.log("THis ishte page content!!", pageContent); + // //@ts-ignore + // vectorData = errorOccurred ? JSON.stringify(pageContent) : thread; + // metadata = { + // baseUrl: input.content, + // description: tweet.text.slice(0, 200), + // image: tweet.user.profile_image_url_https, + // title: `Tweet by ${tweet.user.name}`, + // }; + // } else if (type === "note") { + // pageContent = input.content; + // vectorData = pageContent; + // noteId = new Date().getTime(); + // metadata = { + // baseUrl: `https://supermemory.ai/note/${noteId}`, + // description: `Note created at ${new Date().toLocaleString()}`, + // image: "https://supermemory.ai/logo.png", + // title: `${pageContent.slice(0, 20)} ${pageContent.length > 20 ? "..." : ""}`, + // }; + // } else { + // return { + // success: false, + // data: 0, + // error: "Invalid type", + // }; + // } + + // let storeToSpaces = input.spaces; + + // if (!storeToSpaces) { + // storeToSpaces = []; + // } + + // const vectorSaveResponse = await fetch( + // `${process.env.BACKEND_BASE_URL}/api/add`, + // { + // method: "POST", + // body: JSON.stringify({ + // pageContent: vectorData, + // title: metadata.title, + // description: metadata.description, + // url: metadata.baseUrl, + // spaces: storeToSpaces.map((spaceId) => spaceId.toString()), + // user: data.user.id, + // type, + // }), + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY, + // }, + // }, + // ); + + // if (!vectorSaveResponse.ok) { + // const errorData = await vectorSaveResponse.text(); + // console.error(errorData); + // return { + // success: false, + // data: 0, + // error: `Failed to save to vector store. Backend returned error: ${errorData}`, + // }; + // } + + // let contentId: number; + + // const response = (await vectorSaveResponse.json()) as { + // status: string; + // chunkedInput: string; + // message?: string; + // }; + + // try { + // if (response.status !== "ok") { + // if (response.status === "error") { + // return { + // success: false, + // data: 0, + // error: response.message, + // }; + // } else { + // return { + // success: false, + // data: 0, + // error: `Failed to save to vector store. Backend returned error: ${response.message}`, + // }; + // } + // } + // } catch (e) { + // return { + // success: false, + // data: 0, + // error: `Failed to save to vector store. Backend returned error: ${e}`, + // }; + // } + + // const saveToDbUrl = + // (metadata.baseUrl.split("#supermemory-user-")[0] ?? metadata.baseUrl) + + // "#supermemory-user-" + + // data.user.id; + + // // Insert into database + // try { + // const insertResponse = await db + // .insert(storedContent) + // .values({ + // content: pageContent, + // title: metadata.title, + // description: metadata.description, + // url: saveToDbUrl, + // baseUrl: saveToDbUrl, + // image: metadata.image, + // savedAt: new Date(), + // userId: data.user.id, + // type, + // noteId, + // }) + // .returning({ id: storedContent.id }); + // revalidatePath("/memories"); + // revalidatePath("/home"); + + // if (!insertResponse[0]?.id) { + // return { + // success: false, + // data: 0, + // error: "Something went wrong while saving the document to the database", + // }; + // } + + // contentId = insertResponse[0]?.id; + // } catch (e) { + // const error = e as Error; + // console.log("Error: ", error.message); + + // if ( + // error.message.includes( + // "D1_ERROR: UNIQUE constraint failed: storedContent.baseUrl", + // ) + // ) { + // return { + // success: false, + // data: 0, + // error: "Content already exists", + // }; + // } + + // return { + // success: false, + // data: 0, + // error: "Failed to save to database with error: " + error.message, + // }; + // } + + // if (storeToSpaces.length > 0) { + // // Adding the many-to-many relationship between content and spaces + // const spaceData = await db + // .select() + // .from(space) + // .where( + // and(inArray(space.id, storeToSpaces), eq(space.user, data.user.id)), + // ) + // .all(); + + // await Promise.all( + // spaceData.map(async (s) => { + // await db + // .insert(contentToSpace) + // .values({ contentId: contentId, spaceId: s.id }); + + // await db.update(space).set({ numItems: s.numItems + 1 }); + // }), + // ); + // } return { success: true, @@ -475,7 +467,6 @@ export const createChatThread = async ( return { error: "Not authenticated", success: false }; } - const thread = await db .insert(chatThreads) .values({ @@ -836,8 +827,9 @@ export async function getQuerySuggestions() { }; } - const fullQuery = (content?.map((c) => `${c.title} \n\n${c.content}`) ?? []) - .join(" "); + const fullQuery = ( + content?.map((c) => `${c.title} \n\n${c.content}`) ?? [] + ).join(" "); const suggestionsCall = (await env.AI.run( // @ts-ignore diff --git a/apps/web/app/api/store/helper.ts b/apps/web/app/api/store/helper.ts index 2dc42125..6ab7fb23 100644 --- a/apps/web/app/api/store/helper.ts +++ b/apps/web/app/api/store/helper.ts @@ -2,21 +2,21 @@ import { z } from "zod"; import { db } from "@/server/db"; import { contentToSpace, space, storedContent } from "@repo/db/schema"; import { and, eq, inArray } from "drizzle-orm"; -import { LIMITS } from "@/lib/constants"; -import { limit } from "@/app/actions/doers"; +// import { LIMITS } from "@repo/shared-types"; +// import { limit } from "@/app/actions/doers"; import { type AddFromAPIType } from "@repo/shared-types"; export const createMemoryFromAPI = async (input: { data: AddFromAPIType; userId: string; }) => { - if (!(await limit(input.userId, input.data.type))) { - return { - success: false, - data: 0, - error: `You have exceeded the limit of ${LIMITS[input.data.type as keyof typeof LIMITS]} ${input.data.type}s.`, - }; - } + // if (!(await limit(input.userId, input.data.type))) { + // return { + // success: false, + // data: 0, + // error: `You have exceeded the limit of ${LIMITS[input.data.type as keyof typeof LIMITS]} ${input.data.type}s.`, + // }; + // } const vectorSaveResponse = await fetch( `${process.env.BACKEND_BASE_URL}/api/add`, diff --git a/apps/web/lib/constants.ts b/apps/web/lib/constants.ts index 241a6a1d..73f9a83d 100644 --- a/apps/web/lib/constants.ts +++ b/apps/web/lib/constants.ts @@ -1,9 +1,3 @@ -export const LIMITS = { - page: 100, - tweet: 1000, - note: 1000, -}; - export const codeLanguageSubset = [ "python", "javascript", -- cgit v1.2.3 From 4a9565f91d67cbc57be5bb4370c3e640daf643fb Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Mon, 5 Aug 2024 18:36:26 -0700 Subject: changes for staging --- apps/web/app/(auth)/onboarding/page.tsx | 14 ++++++++------ apps/web/app/(dash)/dialogContentContainer.tsx | 2 +- apps/web/app/(dash)/menu.tsx | 2 +- apps/web/migrations/0001_Adding_jobs_table.sql | 19 +++++++++++++++++++ apps/web/wrangler.toml | 6 +++--- 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 apps/web/migrations/0001_Adding_jobs_table.sql (limited to 'apps/web') diff --git a/apps/web/app/(auth)/onboarding/page.tsx b/apps/web/app/(auth)/onboarding/page.tsx index 5b728928..c311ea13 100644 --- a/apps/web/app/(auth)/onboarding/page.tsx +++ b/apps/web/app/(auth)/onboarding/page.tsx @@ -26,11 +26,13 @@ export default function Home() { await completeOnboarding(); }; if (currStep > 3) { - updateDb().then(() => { - push("/home?q=what%20is%20supermemory"); - }).catch((e) => { - console.error(e); - }); + updateDb() + .then(() => { + push("/home?q=what%20is%20supermemory"); + }) + .catch((e) => { + console.error(e); + }); } }, [currStep]); @@ -292,7 +294,7 @@ function StepThree({ currStep }: { currStep: number }) { }); if (cont.success) { - toast.success("Memory created", { + toast.success("Memory queued", { richColors: true, }); } else { diff --git a/apps/web/app/(dash)/dialogContentContainer.tsx b/apps/web/app/(dash)/dialogContentContainer.tsx index c6cacd35..1a11ac6d 100644 --- a/apps/web/app/(dash)/dialogContentContainer.tsx +++ b/apps/web/app/(dash)/dialogContentContainer.tsx @@ -76,7 +76,7 @@ export function DialogContentContainer({ setSelectedSpaces([]); if (cont.success) { - toast.success("Memory created", { + toast.success("Memory queued", { richColors: true, }); } else { diff --git a/apps/web/app/(dash)/menu.tsx b/apps/web/app/(dash)/menu.tsx index 1acab2c8..783a4780 100644 --- a/apps/web/app/(dash)/menu.tsx +++ b/apps/web/app/(dash)/menu.tsx @@ -128,7 +128,7 @@ function Menu() { setSelectedSpaces([]); if (cont.success) { - toast.success("Memory created", { + toast.success("Memory queued", { richColors: true, }); } else { diff --git a/apps/web/migrations/0001_Adding_jobs_table.sql b/apps/web/migrations/0001_Adding_jobs_table.sql new file mode 100644 index 00000000..7a687f72 --- /dev/null +++ b/apps/web/migrations/0001_Adding_jobs_table.sql @@ -0,0 +1,19 @@ +-- Migration number: 0001 2024-08-05T18:05:16.793Z +CREATE TABLE `jobs` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `userId` text NOT NULL, + `url` text NOT NULL, + `status` text NOT NULL, + `attempts` integer DEFAULT 0 NOT NULL, + `lastAttemptAt` integer, + `error` blob, + `createdAt` integer NOT NULL, + `updatedAt` integer NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); + + +CREATE INDEX `jobs_userId_idx` ON `jobs` (`userId`);--> statement-breakpoint +CREATE INDEX `jobs_status_idx` ON `jobs` (`status`);--> statement-breakpoint +CREATE INDEX `jobs_createdAt_idx` ON `jobs` (`createdAt`);--> statement-breakpoint +CREATE INDEX `jobs_url_idx` ON `jobs` (`url`);--> statement-breakpoint \ No newline at end of file diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index a6232450..2e991ad9 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -1,4 +1,4 @@ -name = "supermemory" +name = "dev-supermemory" compatibility_date = "2024-03-29" compatibility_flags = [ "nodejs_compat" ] pages_build_output_dir = ".vercel/output/static" @@ -31,8 +31,8 @@ database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" [[env.production.d1_databases]] binding = "DATABASE" -database_name = "prod-d1-supermemory" -database_id = "f527a727-c472-41d4-8eaf-3d7ba0f2f395" +database_name = "staging-d1-supermemory" +database_id = "40a3bb06-82bd-42f1-aef4-fde04f3635c5" [env.preview.ai] binding = "AI" -- cgit v1.2.3 From 1336da8aae05a0acdb3e03561fa7378f238d3eda Mon Sep 17 00:00:00 2001 From: Kush Thaker Date: Tue, 6 Aug 2024 20:48:13 +0530 Subject: Fix job errors not reflecting in D1; add delays on document insert in vectorize to help with open ai rate limits --- apps/web/wrangler.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apps/web') diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index a6232450..54b27325 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -26,8 +26,9 @@ bucket_name = "dev-r2-anycontext" [[d1_databases]] binding = "DATABASE" -database_name = "dev-d1-anycontext" -database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" +database_name = "supermemlocal" +database_id = "0f93c990-72fb-489c-8563-57a7bb18dc43" + [[env.production.d1_databases]] binding = "DATABASE" -- cgit v1.2.3 From 34451a7ad79d39da57dabfd36225f34200e41503 Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Tue, 6 Aug 2024 10:55:07 -0700 Subject: changes for prod --- apps/web/wrangler.toml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'apps/web') diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 6abe527d..a6232450 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -1,4 +1,4 @@ -name = "dev-supermemory" +name = "supermemory" compatibility_date = "2024-03-29" compatibility_flags = [ "nodejs_compat" ] pages_build_output_dir = ".vercel/output/static" @@ -26,14 +26,13 @@ bucket_name = "dev-r2-anycontext" [[d1_databases]] binding = "DATABASE" -database_name = "supermemlocal" -database_id = "0f93c990-72fb-489c-8563-57a7bb18dc43" - +database_name = "dev-d1-anycontext" +database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" [[env.production.d1_databases]] binding = "DATABASE" -database_name = "staging-d1-supermemory" -database_id = "40a3bb06-82bd-42f1-aef4-fde04f3635c5" +database_name = "prod-d1-supermemory" +database_id = "f527a727-c472-41d4-8eaf-3d7ba0f2f395" [env.preview.ai] binding = "AI" -- cgit v1.2.3