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
-- see: https://github.com/sol/hpack
name: gargantext
version: 0.0.6.9.4
version: 0.0.6.9.4
synopsis: Search, map, share
description: Please see README.md
category: Data
......
......@@ -396,18 +396,14 @@ insertNodeArchiveHistory c nodeId version (h:hs) = do
_ <- insertNodeArchiveHistory c nodeId version hs
pure ()
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 = [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 (
VALUES (?, ?, ?, ?, ?)
) AS i(node_id, ngrams_type_id, ngrams_id, patch, version)
WHERE NOT EXISTS (
SELECT FROM ngrams
CROSS JOIN nodes
WHERE ngrams.id = ngrams_id
AND nodes.id = node_id
WHERE EXISTS (
SELECT * FROM nodes where nodes.id = node_id
)|]
getNodeStory :: PGS.Connection -> NodeId -> IO NodeListStory
......@@ -475,17 +471,14 @@ insertNodeStory c (NodeId nId) a = do
-- runInsert c $ insert ngramsType ngrams ngramsRepoElement) $ archiveStateToList _a_state
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 = [sql| INSERT INTO node_stories(node_id, ngrams_type_id, ngrams_id, ngrams_repo_element)
SELECT * FROM (
VALUES (?, ?, ?, ?)
) AS i(node_id, ngrams_type_id, ngrams_id, ngrams_repo_element)
WHERE NOT EXISTS (
SELECT FROM ngrams
CROSS JOIN nodes
WHERE ngrams.id = ngrams_id
AND nodes.id = node_id
WHERE EXISTS (
SELECT * FROM nodes where nodes.id = node_id
)|]
-- insert ngramsType ngrams ngramsRepoElement =
-- 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