Skip to content

An AI-powered search engine with a generative UI

fix: rebuild drizzle migrations from clean state

Yoshiki Miura4fb6c9aae21e
diff --git a/CLAUDE.md b/CLAUDE.md
index e8fc830b..9ce819db 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -133,6 +133,6 @@ Models are defined in `public/config/models.json` with:
## Database Management
- Run `bun migrate` to apply database migrations
-- Migrations are located in `/lib/db/migrations/`
+- Migrations are located in `/drizzle/` directory
- Schema changes should be made in `/lib/db/schema.ts`
- Use Drizzle Kit for generating migrations
diff --git a/drizzle/0000_black_lifeguard.sql b/drizzle/0000_black_lifeguard.sql
new file mode 100644
index 00000000..5b449809
--- /dev/null
+++ b/drizzle/0000_black_lifeguard.sql
@@ -0,0 +1,69 @@
+CREATE TABLE "chats" (
+ "id" varchar(191) PRIMARY KEY NOT NULL,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "title" text NOT NULL,
+ "user_id" varchar(255) NOT NULL,
+ "visibility" varchar(256) DEFAULT 'private' NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "messages" (
+ "id" varchar(191) PRIMARY KEY NOT NULL,
+ "chat_id" varchar(191) NOT NULL,
+ "role" varchar(256) NOT NULL,
+ "created_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "parts" (
+ "id" varchar(191) PRIMARY KEY NOT NULL,
+ "message_id" varchar(191) NOT NULL,
+ "order" integer NOT NULL,
+ "type" varchar(256) NOT NULL,
+ "text_text" text,
+ "reasoning_text" text,
+ "file_media_type" varchar(256),
+ "file_filename" varchar(1024),
+ "file_url" text,
+ "source_url_source_id" varchar(256),
+ "source_url_url" text,
+ "source_url_title" text,
+ "source_document_source_id" varchar(256),
+ "source_document_media_type" varchar(256),
+ "source_document_title" text,
+ "source_document_filename" varchar(1024),
+ "source_document_url" text,
+ "source_document_snippet" text,
+ "tool_tool_call_id" varchar(256),
+ "tool_state" varchar(256),
+ "tool_error_text" text,
+ "tool_search_input" json,
+ "tool_search_output" json,
+ "tool_fetch_input" json,
+ "tool_fetch_output" json,
+ "tool_question_input" json,
+ "tool_question_output" json,
+ "tool_todoWrite_input" json,
+ "tool_todoWrite_output" json,
+ "tool_todoRead_input" json,
+ "tool_todoRead_output" json,
+ "tool_dynamic_input" json,
+ "tool_dynamic_output" json,
+ "tool_dynamic_name" varchar(256),
+ "tool_dynamic_type" varchar(256),
+ "data_prefix" varchar(256),
+ "data_content" json,
+ "data_id" varchar(256),
+ "provider_metadata" json,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ CONSTRAINT "text_text_required" CHECK ((type != 'text' OR text_text IS NOT NULL)),
+ CONSTRAINT "reasoning_text_required" CHECK ((type != 'reasoning' OR reasoning_text IS NOT NULL)),
+ CONSTRAINT "file_fields_required" CHECK ((type != 'file' OR (file_media_type IS NOT NULL AND file_filename IS NOT NULL AND file_url IS NOT NULL))),
+ CONSTRAINT "tool_state_valid" CHECK ((tool_state IS NULL OR tool_state IN ('input-streaming', 'input-available', 'output-available', 'output-error'))),
+ CONSTRAINT "tool_fields_required" CHECK ((type NOT LIKE 'tool-%' OR (tool_tool_call_id IS NOT NULL AND tool_state IS NOT NULL)))
+);
+--> statement-breakpoint
+ALTER TABLE "messages" ADD CONSTRAINT "messages_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "parts" ADD CONSTRAINT "parts_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
+CREATE INDEX "messages_chat_id_idx" ON "messages" USING btree ("chat_id");--> statement-breakpoint
+CREATE INDEX "messages_chat_id_created_at_idx" ON "messages" USING btree ("chat_id","created_at");--> statement-breakpoint
+CREATE INDEX "parts_message_id_idx" ON "parts" USING btree ("message_id");--> statement-breakpoint
+CREATE INDEX "parts_message_id_order_idx" ON "parts" USING btree ("message_id","order");
\ No newline at end of file
diff --git a/drizzle/0001_persistence_v5.sql b/drizzle/0001_persistence_v5.sql
deleted file mode 100644
index 515c13d4..00000000
--- a/drizzle/0001_persistence_v5.sql
+++ /dev/null
@@ -1,108 +0,0 @@
--- Drop existing tables if they exist (clean slate approach)
-DROP TABLE IF EXISTS messages CASCADE;
-DROP TABLE IF EXISTS chats CASCADE;
-
--- Create new chats table with generateId
-CREATE TABLE chats (
- id VARCHAR PRIMARY KEY,
- created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
- title TEXT NOT NULL,
- user_id VARCHAR NOT NULL,
- visibility VARCHAR(256) DEFAULT 'private' NOT NULL CHECK (visibility IN ('public', 'private'))
-);
-
--- Create new messages table (simplified)
-CREATE TABLE messages (
- id VARCHAR PRIMARY KEY,
- chat_id VARCHAR NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
- role VARCHAR(256) NOT NULL,
- created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
-);
-
--- Create indexes for messages
-CREATE INDEX messages_chat_id_idx ON messages(chat_id);
-CREATE INDEX messages_chat_id_created_at_idx ON messages(chat_id, created_at);
-
--- Create parts table
-CREATE TABLE parts (
- id VARCHAR PRIMARY KEY,
- message_id VARCHAR NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
- "order" INTEGER NOT NULL,
- type VARCHAR(256) NOT NULL,
-
- -- Text parts
- text_text TEXT,
-
- -- Reasoning parts
- reasoning_text TEXT,
-
- -- File parts
- file_media_type VARCHAR(256),
- file_filename VARCHAR(1024),
- file_url TEXT,
-
- -- Source URL parts
- source_url_source_id VARCHAR(256),
- source_url_url TEXT,
- source_url_title TEXT,
-
- -- Source document parts
- source_document_source_id VARCHAR(256),
- source_document_media_type VARCHAR(256),
- source_document_title TEXT,
- source_document_filename VARCHAR(1024),
- source_document_url TEXT,
- source_document_snippet TEXT,
-
- -- Tool parts (generic)
- tool_tool_call_id VARCHAR(256),
- tool_state VARCHAR(256),
- tool_error_text TEXT,
-
- -- Tool-specific columns
- tool_search_input JSONB,
- tool_search_output JSONB,
- tool_retrieve_input JSONB,
- tool_retrieve_output JSONB,
- tool_question_input JSONB,
- tool_question_output JSONB,
- tool_video_search_input JSONB,
- tool_video_search_output JSONB,
- tool_mcp_input JSONB,
- tool_mcp_output JSONB,
-
- -- Data parts
- data_prefix VARCHAR(256),
- data_content JSONB,
- data_id VARCHAR(256),
-
- -- Provider metadata
- provider_metadata JSONB,
-
- created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
-);
-
--- Create indexes for parts
-CREATE INDEX parts_message_id_idx ON parts(message_id);
-CREATE INDEX parts_message_id_order_idx ON parts(message_id, "order");
-
--- Add constraints
-ALTER TABLE parts ADD CONSTRAINT text_text_required
- CHECK (type != 'text' OR text_text IS NOT NULL);
-
-ALTER TABLE parts ADD CONSTRAINT reasoning_text_required
- CHECK (type != 'reasoning' OR reasoning_text IS NOT NULL);
-
-ALTER TABLE parts ADD CONSTRAINT file_fields_required
- CHECK (type != 'file' OR (file_media_type IS NOT NULL AND file_filename IS NOT NULL AND file_url IS NOT NULL));
-
-ALTER TABLE parts ADD CONSTRAINT tool_state_valid
- CHECK (tool_state IS NULL OR tool_state IN ('input-streaming', 'input-available', 'output-available', 'output-error'));
-
-ALTER TABLE parts ADD CONSTRAINT tool_fields_required
- CHECK (type NOT LIKE 'tool-%' OR (tool_tool_call_id IS NOT NULL AND tool_state IS NOT NULL));
-
--- Enable Row Level Security (if needed)
--- ALTER TABLE chats ENABLE ROW LEVEL SECURITY;
--- ALTER TABLE messages ENABLE ROW LEVEL SECURITY;
--- ALTER TABLE parts ENABLE ROW LEVEL SECURITY;
\ No newline at end of file
diff --git a/drizzle/0003_rename_mcp_to_dynamic.sql b/drizzle/0003_rename_mcp_to_dynamic.sql
deleted file mode 100644
index 1acb9851..00000000
--- a/drizzle/0003_rename_mcp_to_dynamic.sql
+++ /dev/null
@@ -1,11 +0,0 @@
--- Rename MCP tool columns to dynamic tool columns
-ALTER TABLE parts
- RENAME COLUMN tool_mcp_input TO tool_dynamic_input;
-
-ALTER TABLE parts
- RENAME COLUMN tool_mcp_output TO tool_dynamic_output;
-
--- Add dynamic tool metadata columns for storing tool name and type
-ALTER TABLE parts
- ADD COLUMN tool_dynamic_name VARCHAR(256),
- ADD COLUMN tool_dynamic_type VARCHAR(256);
\ No newline at end of file
diff --git a/drizzle/0004_rename_retrieve_to_fetch.sql b/drizzle/0004_rename_retrieve_to_fetch.sql
deleted file mode 100644
index b41f99e5..00000000
--- a/drizzle/0004_rename_retrieve_to_fetch.sql
+++ /dev/null
@@ -1,11 +0,0 @@
--- Migration: Rename retrieve tool columns to fetch
--- This migration renames the tool_retrieve_* columns to tool_fetch_*
--- to align with the renamed tool from 'retrieve' to 'fetch'
-
--- Rename tool_retrieve_input to tool_fetch_input
-ALTER TABLE parts
-RENAME COLUMN tool_retrieve_input TO tool_fetch_input;
-
--- Rename tool_retrieve_output to tool_fetch_output
-ALTER TABLE parts
-RENAME COLUMN tool_retrieve_output TO tool_fetch_output;
\ No newline at end of file
diff --git a/drizzle/0005_remove_video_search.sql b/drizzle/0005_remove_video_search.sql
deleted file mode 100644
index ba080e76..00000000
--- a/drizzle/0005_remove_video_search.sql
+++ /dev/null
@@ -1,3 +0,0 @@
--- Remove video search columns from parts table
-ALTER TABLE "parts" DROP COLUMN IF EXISTS "tool_video_search_input";
-ALTER TABLE "parts" DROP COLUMN IF EXISTS "tool_video_search_output";
\ No newline at end of file
diff --git a/drizzle/0006_add_todo_tools.sql b/drizzle/0006_add_todo_tools.sql
deleted file mode 100644
index 7dc60e90..00000000
--- a/drizzle/0006_add_todo_tools.sql
+++ /dev/null
@@ -1,5 +0,0 @@
--- Add todo tool columns
-ALTER TABLE "parts" ADD COLUMN "tool_todoWrite_input" json;
-ALTER TABLE "parts" ADD COLUMN "tool_todoWrite_output" json;
-ALTER TABLE "parts" ADD COLUMN "tool_todoRead_input" json;
-ALTER TABLE "parts" ADD COLUMN "tool_todoRead_output" json;
\ No newline at end of file
diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json
index 8ff8ec3a..f254f588 100644
--- a/drizzle/meta/0000_snapshot.json
+++ b/drizzle/meta/0000_snapshot.json
@@ -1,5 +1,5 @@
{
- "id": "1a87e5a3-280e-4953-ac53-2221e33657b2",
+ "id": "bd2133a6-1281-44a1-8619-c1f0407dfb77",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
@@ -300,6 +300,30 @@
"primaryKey": false,
"notNull": false
},
+ "tool_todoWrite_input": {
+ "name": "tool_todoWrite_input",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "tool_todoWrite_output": {
+ "name": "tool_todoWrite_output",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "tool_todoRead_input": {
+ "name": "tool_todoRead_input",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "tool_todoRead_output": {
+ "name": "tool_todoRead_output",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false
+ },
"tool_dynamic_input": {
"name": "tool_dynamic_input",
"type": "json",
diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json
index 52390448..777539fb 100644
--- a/drizzle/meta/_journal.json
+++ b/drizzle/meta/_journal.json
@@ -5,36 +5,8 @@
{
"idx": 0,
"version": "7",
- "when": 1753666852574,
- "tag": "0001_persistence_v5",
- "breakpoints": true
- },
- {
- "idx": 1,
- "version": "7",
- "when": 1753684227255,
- "tag": "0003_rename_mcp_to_dynamic",
- "breakpoints": true
- },
- {
- "idx": 2,
- "version": "7",
- "when": 1753688930677,
- "tag": "0004_rename_retrieve_to_fetch",
- "breakpoints": true
- },
- {
- "idx": 3,
- "version": "7",
- "when": 1753822953434,
- "tag": "0005_remove_video_search",
- "breakpoints": true
- },
- {
- "idx": 4,
- "version": "7",
- "when": 1754133183602,
- "tag": "0006_add_todo_tools",
+ "when": 1754303165189,
+ "tag": "0000_black_lifeguard",
"breakpoints": true
}
]