2024-11-15 12:18:17 -05:00
|
|
|
import type { InferSelectModel } from 'drizzle-orm';
|
2024-10-30 16:01:24 +05:30
|
|
|
import {
|
|
|
|
|
pgTable,
|
|
|
|
|
varchar,
|
|
|
|
|
timestamp,
|
|
|
|
|
json,
|
|
|
|
|
uuid,
|
|
|
|
|
text,
|
|
|
|
|
primaryKey,
|
|
|
|
|
foreignKey,
|
|
|
|
|
boolean,
|
|
|
|
|
} from 'drizzle-orm/pg-core';
|
|
|
|
|
|
|
|
|
|
export const user = pgTable('User', {
|
|
|
|
|
id: uuid('id').primaryKey().notNull().defaultRandom(),
|
|
|
|
|
email: varchar('email', { length: 64 }).notNull(),
|
|
|
|
|
password: varchar('password', { length: 64 }),
|
2024-10-11 18:00:22 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type User = InferSelectModel<typeof user>;
|
|
|
|
|
|
2024-10-30 16:01:24 +05:30
|
|
|
export const chat = pgTable('Chat', {
|
|
|
|
|
id: uuid('id').primaryKey().notNull().defaultRandom(),
|
|
|
|
|
createdAt: timestamp('createdAt').notNull(),
|
2024-11-05 17:15:51 +03:00
|
|
|
title: text('title').notNull(),
|
2024-10-30 16:01:24 +05:30
|
|
|
userId: uuid('userId')
|
2024-10-11 18:00:22 +05:30
|
|
|
.notNull()
|
|
|
|
|
.references(() => user.id),
|
2024-12-06 13:36:56 +03:00
|
|
|
visibility: varchar('visibility', { enum: ['public', 'private'] })
|
|
|
|
|
.notNull()
|
|
|
|
|
.default('private'),
|
2024-10-11 18:00:22 +05:30
|
|
|
});
|
|
|
|
|
|
2024-11-05 17:15:51 +03:00
|
|
|
export type Chat = InferSelectModel<typeof chat>;
|
|
|
|
|
|
2025-03-16 18:42:29 -07:00
|
|
|
// DEPRECATED: The following schema is deprecated and will be removed in the future.
|
|
|
|
|
// Read the migration guide at https://github.com/vercel/ai-chatbot/blob/main/docs/04-migrate-to-parts.md
|
|
|
|
|
export const messageDeprecated = pgTable('Message', {
|
2024-11-05 17:15:51 +03:00
|
|
|
id: uuid('id').primaryKey().notNull().defaultRandom(),
|
|
|
|
|
chatId: uuid('chatId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => chat.id),
|
|
|
|
|
role: varchar('role').notNull(),
|
|
|
|
|
content: json('content').notNull(),
|
|
|
|
|
createdAt: timestamp('createdAt').notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-16 18:42:29 -07:00
|
|
|
export type MessageDeprecated = InferSelectModel<typeof messageDeprecated>;
|
2024-11-05 17:15:51 +03:00
|
|
|
|
2025-03-16 18:42:29 -07:00
|
|
|
export const message = pgTable('Message_v2', {
|
|
|
|
|
id: uuid('id').primaryKey().notNull().defaultRandom(),
|
|
|
|
|
chatId: uuid('chatId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => chat.id),
|
|
|
|
|
role: varchar('role').notNull(),
|
|
|
|
|
parts: json('parts').notNull(),
|
|
|
|
|
attachments: json('attachments').notNull(),
|
|
|
|
|
createdAt: timestamp('createdAt').notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type DBMessage = InferSelectModel<typeof message>;
|
|
|
|
|
|
|
|
|
|
// DEPRECATED: The following schema is deprecated and will be removed in the future.
|
|
|
|
|
// Read the migration guide at https://github.com/vercel/ai-chatbot/blob/main/docs/04-migrate-to-parts.md
|
|
|
|
|
export const voteDeprecated = pgTable(
|
2024-11-05 17:15:51 +03:00
|
|
|
'Vote',
|
2025-03-16 18:42:29 -07:00
|
|
|
{
|
|
|
|
|
chatId: uuid('chatId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => chat.id),
|
|
|
|
|
messageId: uuid('messageId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => messageDeprecated.id),
|
|
|
|
|
isUpvoted: boolean('isUpvoted').notNull(),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
|
|
|
|
pk: primaryKey({ columns: [table.chatId, table.messageId] }),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type VoteDeprecated = InferSelectModel<typeof voteDeprecated>;
|
|
|
|
|
|
|
|
|
|
export const vote = pgTable(
|
|
|
|
|
'Vote_v2',
|
2024-11-05 17:15:51 +03:00
|
|
|
{
|
|
|
|
|
chatId: uuid('chatId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => chat.id),
|
|
|
|
|
messageId: uuid('messageId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => message.id),
|
|
|
|
|
isUpvoted: boolean('isUpvoted').notNull(),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
|
|
|
|
pk: primaryKey({ columns: [table.chatId, table.messageId] }),
|
|
|
|
|
};
|
2024-11-15 13:00:15 -05:00
|
|
|
},
|
2024-11-05 17:15:51 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type Vote = InferSelectModel<typeof vote>;
|
2024-10-30 16:01:24 +05:30
|
|
|
|
|
|
|
|
export const document = pgTable(
|
|
|
|
|
'Document',
|
|
|
|
|
{
|
|
|
|
|
id: uuid('id').notNull().defaultRandom(),
|
|
|
|
|
createdAt: timestamp('createdAt').notNull(),
|
|
|
|
|
title: text('title').notNull(),
|
|
|
|
|
content: text('content'),
|
2025-02-06 17:18:26 +03:00
|
|
|
kind: varchar('text', { enum: ['text', 'code', 'image', 'sheet'] })
|
|
|
|
|
.notNull()
|
|
|
|
|
.default('text'),
|
2024-10-30 16:01:24 +05:30
|
|
|
userId: uuid('userId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => user.id),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
|
|
|
|
pk: primaryKey({ columns: [table.id, table.createdAt] }),
|
|
|
|
|
};
|
2024-11-15 13:00:15 -05:00
|
|
|
},
|
2024-10-30 16:01:24 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type Document = InferSelectModel<typeof document>;
|
|
|
|
|
|
2024-11-06 20:24:18 +03:00
|
|
|
export const suggestion = pgTable(
|
2024-10-30 16:01:24 +05:30
|
|
|
'Suggestion',
|
|
|
|
|
{
|
|
|
|
|
id: uuid('id').notNull().defaultRandom(),
|
|
|
|
|
documentId: uuid('documentId').notNull(),
|
|
|
|
|
documentCreatedAt: timestamp('documentCreatedAt').notNull(),
|
|
|
|
|
originalText: text('originalText').notNull(),
|
|
|
|
|
suggestedText: text('suggestedText').notNull(),
|
|
|
|
|
description: text('description'),
|
|
|
|
|
isResolved: boolean('isResolved').notNull().default(false),
|
|
|
|
|
userId: uuid('userId')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => user.id),
|
|
|
|
|
createdAt: timestamp('createdAt').notNull(),
|
|
|
|
|
},
|
|
|
|
|
(table) => ({
|
|
|
|
|
pk: primaryKey({ columns: [table.id] }),
|
|
|
|
|
documentRef: foreignKey({
|
|
|
|
|
columns: [table.documentId, table.documentCreatedAt],
|
|
|
|
|
foreignColumns: [document.id, document.createdAt],
|
|
|
|
|
}),
|
2024-11-15 13:00:15 -05:00
|
|
|
}),
|
2024-10-30 16:01:24 +05:30
|
|
|
);
|
|
|
|
|
|
2024-11-06 20:24:18 +03:00
|
|
|
export type Suggestion = InferSelectModel<typeof suggestion>;
|
2025-05-01 12:36:52 -07:00
|
|
|
|
|
|
|
|
export const stream = pgTable(
|
|
|
|
|
'Stream',
|
|
|
|
|
{
|
|
|
|
|
id: uuid('id').notNull().defaultRandom(),
|
|
|
|
|
chatId: uuid('chatId').notNull(),
|
|
|
|
|
createdAt: timestamp('createdAt').notNull(),
|
|
|
|
|
},
|
|
|
|
|
(table) => ({
|
|
|
|
|
pk: primaryKey({ columns: [table.id] }),
|
|
|
|
|
chatRef: foreignKey({
|
|
|
|
|
columns: [table.chatId],
|
|
|
|
|
foreignColumns: [chat.id],
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type Stream = InferSelectModel<typeof stream>;
|