Commit 490577df authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] #173 Ngrams Change insert causes Database error

parent 2b05b544
...@@ -5,7 +5,7 @@ cabal-version: 1.12 ...@@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
name: gargantext name: gargantext
version: 0.0.6.9.4 version: 0.0.6.9.4
synopsis: Search, map, share synopsis: Search, map, share
description: Please see README.md description: Please see README.md
category: Data category: Data
......
...@@ -396,18 +396,14 @@ insertNodeArchiveHistory c nodeId version (h:hs) = do ...@@ -396,18 +396,14 @@ insertNodeArchiveHistory c nodeId version (h:hs) = do
_ <- insertNodeArchiveHistory c nodeId version hs _ <- insertNodeArchiveHistory c nodeId version hs
pure () pure ()
where where
-- https://stackoverflow.com/questions/39224438/postgresql-insert-if-foreign-key-exists
-- https://dba.stackexchange.com/questions/265554/how-to-check-other-table-for-value-during-insert
query :: PGS.Query query :: PGS.Query
query = [sql| INSERT INTO node_story_archive_history(node_id, ngrams_type_id, ngrams_id, patch, version) query = [sql| INSERT INTO node_story_archive_history(node_id, ngrams_type_id, ngrams_id, patch, version)
SELECT node_id, ngrams_type_id, ngrams_id, patch::jsonb, version FROM ( SELECT node_id, ngrams_type_id, ngrams_id, patch::jsonb, version FROM (
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
) AS i(node_id, ngrams_type_id, ngrams_id, patch, version) ) AS i(node_id, ngrams_type_id, ngrams_id, patch, version)
WHERE NOT EXISTS ( WHERE EXISTS (
SELECT FROM ngrams SELECT * FROM nodes where nodes.id = node_id
CROSS JOIN nodes
WHERE ngrams.id = ngrams_id
AND nodes.id = node_id
)|] )|]
getNodeStory :: PGS.Connection -> NodeId -> IO NodeListStory getNodeStory :: PGS.Connection -> NodeId -> IO NodeListStory
...@@ -475,17 +471,14 @@ insertNodeStory c (NodeId nId) a = do ...@@ -475,17 +471,14 @@ insertNodeStory c (NodeId nId) a = do
-- runInsert c $ insert ngramsType ngrams ngramsRepoElement) $ archiveStateToList _a_state -- runInsert c $ insert ngramsType ngrams ngramsRepoElement) $ archiveStateToList _a_state
where where
-- https://dba.stackexchange.com/questions/265554/how-to-check-other-table-for-value-during-insert -- https://stackoverflow.com/questions/39224438/postgresql-insert-if-foreign-key-exists
query :: PGS.Query query :: PGS.Query
query = [sql| INSERT INTO node_stories(node_id, ngrams_type_id, ngrams_id, ngrams_repo_element) query = [sql| INSERT INTO node_stories(node_id, ngrams_type_id, ngrams_id, ngrams_repo_element)
SELECT * FROM ( SELECT * FROM (
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
) AS i(node_id, ngrams_type_id, ngrams_id, ngrams_repo_element) ) AS i(node_id, ngrams_type_id, ngrams_id, ngrams_repo_element)
WHERE NOT EXISTS ( WHERE EXISTS (
SELECT FROM ngrams SELECT * FROM nodes where nodes.id = node_id
CROSS JOIN nodes
WHERE ngrams.id = ngrams_id
AND nodes.id = node_id
)|] )|]
-- insert ngramsType ngrams ngramsRepoElement = -- insert ngramsType ngrams ngramsRepoElement =
-- Insert { iTable = nodeStoryTable -- Insert { iTable = nodeStoryTable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment