From ad11282be117ae87b308fcc1cd1c11d2c56d4f73 Mon Sep 17 00:00:00 2001 From: filou Date: Tue, 26 Nov 2024 21:04:01 +0100 Subject: [PATCH 1/2] [KW-Search] Fix sql for nodes tables creation Description --- Migration did not work because quotes were needed for the reserved keyword 'table' Although not optimal in general as a column name, here it's the best naming, consistent with data_source / document / folder, and avoiding the clash with table_id (which is a string id) Risk --- na Deploy --- migration on prodbox deploy core --- core/src/stores/migrations/20241125_nodes_table.sql | 4 ++-- core/src/stores/store.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/stores/migrations/20241125_nodes_table.sql b/core/src/stores/migrations/20241125_nodes_table.sql index 6b1e8108cbc5..084891f0ba51 100644 --- a/core/src/stores/migrations/20241125_nodes_table.sql +++ b/core/src/stores/migrations/20241125_nodes_table.sql @@ -20,11 +20,11 @@ CREATE TABLE data_sources_nodes ( mime_type TEXT NOT NULL, parents TEXT[] NOT NULL, document BIGINT, - table BIGINT, + "table" BIGINT, folder BIGINT, FOREIGN KEY(data_source) REFERENCES data_sources(id), FOREIGN KEY(document) REFERENCES data_sources_documents(id), - FOREIGN KEY(table) REFERENCES tables(id), + FOREIGN KEY("table") REFERENCES tables(id), FOREIGN KEY(folder) REFERENCES data_sources_folders(id), CONSTRAINT data_sources_nodes_document_id_table_id_folder_id_check CHECK ( (document IS NOT NULL AND table IS NULL AND folder IS NULL) OR diff --git a/core/src/stores/store.rs b/core/src/stores/store.rs index 2769676b98f1..ac8897ce33ab 100644 --- a/core/src/stores/store.rs +++ b/core/src/stores/store.rs @@ -516,11 +516,11 @@ pub const POSTGRES_TABLES: [&'static str; 16] = [ mime_type TEXT NOT NULL, parents TEXT[] NOT NULL, document BIGINT, - table BIGINT, + \"table\" BIGINT, folder BIGINT, FOREIGN KEY(data_source) REFERENCES data_sources(id), FOREIGN KEY(document) REFERENCES data_sources_documents(id), - FOREIGN KEY(table) REFERENCES tables(id), + FOREIGN KEY(\"table\") REFERENCES tables(id), FOREIGN KEY(folder) REFERENCES data_sources_folders(id), CONSTRAINT data_sources_nodes_document_id_table_id_folder_id_check CHECK ( (document IS NOT NULL AND table IS NULL AND folder IS NULL) OR From 468412becda73ba69711fcb14a09bb69decfb9c1 Mon Sep 17 00:00:00 2001 From: filou Date: Tue, 26 Nov 2024 21:09:45 +0100 Subject: [PATCH 2/2] quotes --- core/src/stores/migrations/20241125_nodes_table.sql | 6 +++--- core/src/stores/store.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/stores/migrations/20241125_nodes_table.sql b/core/src/stores/migrations/20241125_nodes_table.sql index 084891f0ba51..7fac3f597bbc 100644 --- a/core/src/stores/migrations/20241125_nodes_table.sql +++ b/core/src/stores/migrations/20241125_nodes_table.sql @@ -27,9 +27,9 @@ CREATE TABLE data_sources_nodes ( FOREIGN KEY("table") REFERENCES tables(id), FOREIGN KEY(folder) REFERENCES data_sources_folders(id), CONSTRAINT data_sources_nodes_document_id_table_id_folder_id_check CHECK ( - (document IS NOT NULL AND table IS NULL AND folder IS NULL) OR - (document IS NULL AND table IS NOT NULL AND folder IS NULL) OR - (document IS NULL AND table IS NULL AND folder IS NOT NULL) + (document IS NOT NULL AND "table" IS NULL AND folder IS NULL) OR + (document IS NULL AND "table" IS NOT NULL AND folder IS NULL) OR + (document IS NULL AND "table" IS NULL AND folder IS NOT NULL) ) ); diff --git a/core/src/stores/store.rs b/core/src/stores/store.rs index ac8897ce33ab..a8ad0ef4d322 100644 --- a/core/src/stores/store.rs +++ b/core/src/stores/store.rs @@ -523,9 +523,9 @@ pub const POSTGRES_TABLES: [&'static str; 16] = [ FOREIGN KEY(\"table\") REFERENCES tables(id), FOREIGN KEY(folder) REFERENCES data_sources_folders(id), CONSTRAINT data_sources_nodes_document_id_table_id_folder_id_check CHECK ( - (document IS NOT NULL AND table IS NULL AND folder IS NULL) OR - (document IS NULL AND table IS NOT NULL AND folder IS NULL) OR - (document IS NULL AND table IS NULL AND folder IS NOT NULL) + (document IS NOT NULL AND \"table\" IS NULL AND folder IS NULL) OR + (document IS NULL AND \"table\" IS NOT NULL AND folder IS NULL) OR + (document IS NULL AND \"table\" IS NULL AND folder IS NOT NULL) ) );", ];