From 6f41c22cb5e923aa46091005a609b053d07ffa12 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Sat, 1 Aug 2026 09:38:27 +0700 Subject: [PATCH] fix(db): migration 0013 rename mascot_chat_messages to chatbot_messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /api/chat/history 500 (relation "chatbot_messages" does not exist): codebase di-rename mascot->chatbot (977a6f9) tapi tabel DB tidak pernah di-migrate — backend SELECT dari chatbot_messages, DB masih mascot_chat_messages dengan kolom mascot_response. - Migration 0013 (idempotent): ALTER TABLE mascot_chat_messages RENAME TO chatbot_messages, RENAME COLUMN mascot_response -> bot_response, RENAME INDEX -> idx_chatbot_messages_user_created; journal when > max(created_at) di __drizzle_migrations (0012) - Diterapkan live via psql; riwayat chat lama tetap ada - Verifikasi: GET /api/chat/history 200 + data, POST /api/chat 200 + tersimpan (total history 1 -> 2) --- .../0013_rename_mascot_chat_to_chatbot.sql | 19 +++++++++++++++++++ .../drizzle/migrations/meta/_journal.json | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 services/discord-gateway/drizzle/migrations/0013_rename_mascot_chat_to_chatbot.sql diff --git a/services/discord-gateway/drizzle/migrations/0013_rename_mascot_chat_to_chatbot.sql b/services/discord-gateway/drizzle/migrations/0013_rename_mascot_chat_to_chatbot.sql new file mode 100644 index 0000000..0dedbee --- /dev/null +++ b/services/discord-gateway/drizzle/migrations/0013_rename_mascot_chat_to_chatbot.sql @@ -0,0 +1,19 @@ +-- Rename mascot chat tables/columns to chatbot (code rename in 977a6f9, +-- DB was never migrated). Idempotent: no-ops on databases that already +-- carry the new names (e.g. after a manual hotfix). +ALTER TABLE IF EXISTS "mascot_chat_messages" RENAME TO "chatbot_messages"; + +--> statement-breakpoint +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_name = 'chatbot_messages' AND column_name = 'mascot_response' + ) THEN + ALTER TABLE "chatbot_messages" RENAME COLUMN "mascot_response" TO "bot_response"; + END IF; +END $$; + +--> statement-breakpoint +ALTER INDEX IF EXISTS "idx_mascot_chat_messages_user_created" RENAME TO "idx_chatbot_messages_user_created"; diff --git a/services/discord-gateway/drizzle/migrations/meta/_journal.json b/services/discord-gateway/drizzle/migrations/meta/_journal.json index 8edda62..3e933a2 100644 --- a/services/discord-gateway/drizzle/migrations/meta/_journal.json +++ b/services/discord-gateway/drizzle/migrations/meta/_journal.json @@ -92,6 +92,13 @@ "when": 1785500000000, "tag": "0012_add_embedding_to_text_cache", "breakpoints": true + }, + { + "idx": 13, + "version": "7", + "when": 1785551832190, + "tag": "0013_rename_mascot_chat_to_chatbot", + "breakpoints": true } ] } \ No newline at end of file