Skip to content

An AI-powered search engine with a generative UI

feat: remove updatedAt and add attachments field to messages

Yoshiki Miura6f4ef8515746
diff --git a/drizzle/migrations/0001_update_schema_drop_updated_at.sql b/drizzle/migrations/0001_update_schema_drop_updated_at.sql
new file mode 100644
index 00000000..e231d4ae
--- /dev/null
+++ b/drizzle/migrations/0001_update_schema_drop_updated_at.sql
@@ -0,0 +1,8 @@
+-- Drop updatedAt column from chats table
+ALTER TABLE "chats" DROP COLUMN "updated_at";
+
+-- Drop updatedAt column from messages table
+ALTER TABLE "messages" DROP COLUMN "updated_at";
+
+-- Add attachments column to messages table
+ALTER TABLE "messages" ADD COLUMN "attachments" jsonb NOT NULL DEFAULT '{}';
\ No newline at end of file
diff --git a/drizzle/migrations/meta/0001_snapshot.json b/drizzle/migrations/meta/0001_snapshot.json
new file mode 100644
index 00000000..c001db6a
--- /dev/null
+++ b/drizzle/migrations/meta/0001_snapshot.json
@@ -0,0 +1,127 @@
+{
+ "id": "74bfe8c4-6a83-4e8a-9d1c-2b5a7f31e0f4",
+ "prevId": "baef7eb3-6b14-444a-82ce-0d1a060c98ad",
+ "version": "7",
+ "dialect": "postgresql",
+ "tables": {
+ "public.chats": {
+ "name": "chats",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "visibility": {
+ "name": "visibility",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'private'"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.messages": {
+ "name": "messages",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "uuid",
+ "primaryKey": true,
+ "notNull": true,
+ "default": "gen_random_uuid()"
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "uuid",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "varchar(256)",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "parts": {
+ "name": "parts",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "attachments": {
+ "name": "attachments",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'{}'::jsonb"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "messages_chat_id_chats_id_fk": {
+ "name": "messages_chat_id_chats_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "chats",
+ "columnsFrom": ["chat_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "sequences": {},
+ "roles": {},
+ "policies": {},
+ "views": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
diff --git a/drizzle/migrations/meta/_journal.json b/drizzle/migrations/meta/_journal.json
index 5eabf1b5..7cc47ea0 100644
--- a/drizzle/migrations/meta/_journal.json
+++ b/drizzle/migrations/meta/_journal.json
@@ -8,6 +8,13 @@
"when": 1747030516658,
"tag": "0000_famous_gunslinger",
"breakpoints": true
+ },
+ {
+ "idx": 1,
+ "version": "7",
+ "when": 1747030781234,
+ "tag": "0001_update_schema_drop_updated_at",
+ "breakpoints": true
}
]
-}
\ No newline at end of file
+}
diff --git a/lib/db/chat.ts b/lib/db/chat.ts
index 33817f41..96af400f 100644
--- a/lib/db/chat.ts
+++ b/lib/db/chat.ts
@@ -85,8 +85,7 @@ export async function updateChat(
const [chat] = await db
.update(chats)
.set({
- ...data,
- updatedAt: new Date().toISOString()
+ ...data
})
.where(eq(chats.id, id))
.returning()
@@ -143,10 +142,12 @@ export async function addMessage({
chatId: string
role: string
parts: any
+ attachments: any
} = {
chatId,
role,
- parts
+ parts,
+ attachments: {}
}
if (id) {
@@ -244,8 +245,7 @@ export async function saveChat(chat: Chat, userId: string) {
.update(chats)
.set({
title: chat.title,
- visibility: chat.visibility,
- updatedAt: new Date().toISOString()
+ visibility: chat.visibility
})
.where(eq(chats.id, chat.id))
.returning()
@@ -301,8 +301,7 @@ export async function shareChat(id: string, userId: string) {
const [updatedChat] = await db
.update(chats)
.set({
- visibility: 'public',
- updatedAt: new Date().toISOString()
+ visibility: 'public'
})
.where(eq(chats.id, id))
.returning()
diff --git a/lib/db/schema.ts b/lib/db/schema.ts
index 5ae90ed0..a6e7106e 100644
--- a/lib/db/schema.ts
+++ b/lib/db/schema.ts
@@ -13,9 +13,6 @@ export const chats = pgTable('chats', {
createdAt: timestamp('created_at', { mode: 'string', withTimezone: true })
.notNull()
.defaultNow(),
- updatedAt: timestamp('updated_at', { mode: 'string', withTimezone: true })
- .notNull()
- .defaultNow(),
title: text('title').notNull(),
userId: uuid('user_id').notNull(), // User ID from the authentication system
visibility: varchar('visibility', {
@@ -35,10 +32,8 @@ export const messages = pgTable('messages', {
.references(() => chats.id, { onDelete: 'cascade' }),
role: varchar('role', { length: 256 }).notNull(),
parts: json('parts').notNull(), // Stores structured message content (e.g., Vercel AI SDK Message parts)
+ attachments: json('attachments').notNull(),
createdAt: timestamp('created_at', { mode: 'string', withTimezone: true })
- .notNull()
- .defaultNow(),
- updatedAt: timestamp('updated_at', { mode: 'string', withTimezone: true })
.notNull()
.defaultNow()
})
diff --git a/package.json b/package.json
index 0c22922a..05c98ae9 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,8 @@
"dev": "next dev --turbo",
"build": "next build",
"start": "next start",
- "lint": "next lint"
+ "lint": "next lint",
+ "migrate": "bun run lib/db/migrate.ts"
},
"dependencies": {
"@ai-sdk/anthropic": "^1.2.10",