From 8189c8159edf04f19099d43260bbc8c5db33a230 Mon Sep 17 00:00:00 2001 From: Philippe Rolet Date: Tue, 26 Nov 2024 21:13:59 +0100 Subject: [PATCH] [KW-Search] Fix sql for nodes tables creation (#8926) * [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 * quotes --- core/src/stores/migrations/20241125_nodes_table.sql | 10 +++++----- core/src/stores/store.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/stores/migrations/20241125_nodes_table.sql b/core/src/stores/migrations/20241125_nodes_table.sql index 6b1e8108cbc5..7fac3f597bbc 100644 --- a/core/src/stores/migrations/20241125_nodes_table.sql +++ b/core/src/stores/migrations/20241125_nodes_table.sql @@ -20,16 +20,16 @@ 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 - (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 2769676b98f1..a8ad0ef4d322 100644 --- a/core/src/stores/store.rs +++ b/core/src/stores/store.rs @@ -516,16 +516,16 @@ 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 - (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) ) );", ];