From b9ea6641fff3d9e7635594021cd4c431bda673f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 16 Oct 2024 10:43:52 +0100 Subject: [PATCH] chore: AI chats db migration (#8460) https://linear.app/unleash/issue/2-2845/db-migration-ai-chats Adds a new DB migration for creating a new `ai_chats` table, used on the Unleash AI experiment. --- src/migrations/20241016090534-ai-chats.js | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/migrations/20241016090534-ai-chats.js diff --git a/src/migrations/20241016090534-ai-chats.js b/src/migrations/20241016090534-ai-chats.js new file mode 100644 index 0000000000..3a029a83bf --- /dev/null +++ b/src/migrations/20241016090534-ai-chats.js @@ -0,0 +1,26 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS ai_chats + ( + id BIGSERIAL PRIMARY KEY NOT NULL, + user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + chat JSONB NOT NULL + ); + + CREATE INDEX IF NOT EXISTS idx_ai_chats_user_id ON ai_chats(user_id); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX IF EXISTS idx_ai_chats_user_id; + DROP TABLE IF EXISTS ai_chats; + `, + cb, + ); +};