Skip to content

Commit

Permalink
[KW-Search] Fix sql for nodes tables creation (#8926)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
philipperolet authored Nov 26, 2024
1 parent b95d883 commit 8189c81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions core/src/stores/migrations/20241125_nodes_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);

Expand Down
10 changes: 5 additions & 5 deletions core/src/stores/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);",
];
Expand Down

0 comments on commit 8189c81

Please sign in to comment.