diff --git a/db/queries.ts b/db/queries.ts index 2315800..7a9da62 100644 --- a/db/queries.ts +++ b/db/queries.ts @@ -11,6 +11,7 @@ import { User, document, Suggestion, + suggestion, Message, message, vote, @@ -227,6 +228,15 @@ export async function deleteDocumentsByIdAfterTimestamp({ timestamp: Date; }) { try { + await db + .delete(suggestion) + .where( + and( + eq(suggestion.documentId, id), + gt(suggestion.documentCreatedAt, timestamp) + ) + ); + return await db .delete(document) .where(and(eq(document.id, id), gt(document.createdAt, timestamp))); @@ -244,7 +254,7 @@ export async function saveSuggestions({ suggestions: Array; }) { try { - return await db.insert(Suggestion).values(suggestions); + return await db.insert(suggestion).values(suggestions); } catch (error) { console.error('Failed to save suggestions in database'); throw error; @@ -259,8 +269,8 @@ export async function getSuggestionsByDocumentId({ try { return await db .select() - .from(Suggestion) - .where(and(eq(Suggestion.documentId, documentId))); + .from(suggestion) + .where(and(eq(suggestion.documentId, documentId))); } catch (error) { console.error( 'Failed to get suggestions by document version from database' diff --git a/db/schema.ts b/db/schema.ts index b2c0347..0b334c6 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -82,7 +82,7 @@ export const document = pgTable( export type Document = InferSelectModel; -export const Suggestion = pgTable( +export const suggestion = pgTable( 'Suggestion', { id: uuid('id').notNull().defaultRandom(), @@ -106,4 +106,4 @@ export const Suggestion = pgTable( }) ); -export type Suggestion = InferSelectModel; +export type Suggestion = InferSelectModel;