From 47e1558e2e188f78ca4c6e54d2484bcc598919b2 Mon Sep 17 00:00:00 2001 From: dal Date: Fri, 7 Mar 2025 09:19:47 -0700 Subject: [PATCH] ok all is good on the western front --- api/libs/database/src/schema.rs | 15 +++++++++++++++ .../down.sql | 16 ++++++++-------- .../down.sql | 17 +++++++++++++---- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/api/libs/database/src/schema.rs b/api/libs/database/src/schema.rs index 784730737..41854d206 100644 --- a/api/libs/database/src/schema.rs +++ b/api/libs/database/src/schema.rs @@ -521,6 +521,18 @@ diesel::table! { } } +diesel::table! { + threads (id) { + id -> Uuid, + title -> Text, + organization_id -> Uuid, + created_at -> Timestamptz, + updated_at -> Timestamptz, + deleted_at -> Nullable, + created_by -> Uuid, + } +} + diesel::table! { threads_deprecated (id) { id -> Uuid, @@ -637,6 +649,8 @@ diesel::joinable!(teams_to_users -> users (user_id)); diesel::joinable!(terms -> organizations (organization_id)); diesel::joinable!(terms_to_datasets -> datasets (dataset_id)); diesel::joinable!(terms_to_datasets -> terms (term_id)); +diesel::joinable!(threads -> organizations (organization_id)); +diesel::joinable!(threads -> users (created_by)); diesel::joinable!(threads_deprecated -> organizations (organization_id)); diesel::joinable!(threads_to_dashboards -> dashboards (dashboard_id)); diesel::joinable!(threads_to_dashboards -> threads_deprecated (thread_id)); @@ -675,6 +689,7 @@ diesel::allow_tables_to_appear_in_same_query!( teams_to_users, terms, terms_to_datasets, + threads, threads_deprecated, threads_to_dashboards, user_favorites, diff --git a/api/migrations/2025-01-27-390057_adjust_threads_table/down.sql b/api/migrations/2025-01-27-390057_adjust_threads_table/down.sql index 6c1cfe41e..4e312ba2a 100644 --- a/api/migrations/2025-01-27-390057_adjust_threads_table/down.sql +++ b/api/migrations/2025-01-27-390057_adjust_threads_table/down.sql @@ -1,11 +1,11 @@ -- This file should undo anything in `up.sql` --- Drop indexes -DROP INDEX chats_organization_id_idx; -DROP INDEX chats_created_by_idx; -DROP INDEX chats_created_at_idx; --- Drop new threads table -DROP TABLE chats; +-- Drop indexes if they exist +DROP INDEX IF EXISTS chats_organization_id_idx; +DROP INDEX IF EXISTS chats_created_by_idx; +DROP INDEX IF EXISTS chats_created_at_idx; + +-- Drop new threads table if it exists +DROP TABLE IF EXISTS chats; + --- Rename deprecated table back to threads -ALTER TABLE threads_deprecated RENAME TO threads; diff --git a/api/migrations/2025-01-28-174921_adjust_messages_table/down.sql b/api/migrations/2025-01-28-174921_adjust_messages_table/down.sql index b770d0632..4b871ea42 100644 --- a/api/migrations/2025-01-28-174921_adjust_messages_table/down.sql +++ b/api/migrations/2025-01-28-174921_adjust_messages_table/down.sql @@ -1,11 +1,20 @@ -- This file should undo anything in `up.sql` --- Drop indexes -DROP INDEX messages_chat_id_idx; -DROP INDEX messages_created_by_idx; -DROP INDEX messages_created_at_idx; +-- Drop indexes first +DROP INDEX IF EXISTS messages_chat_id_idx; +DROP INDEX IF EXISTS messages_created_by_idx; +DROP INDEX IF EXISTS messages_created_at_idx; -- Drop new messages table DROP TABLE messages; -- Rename deprecated table back to messages ALTER TABLE messages_deprecated RENAME TO messages; + +-- Drop existing constraint if it exists +ALTER TABLE messages +DROP CONSTRAINT IF EXISTS messages_thread_id_fkey; + +-- Restore foreign key constraint +ALTER TABLE messages +ADD CONSTRAINT messages_thread_id_fkey +FOREIGN KEY (thread_id) REFERENCES threads(id);