Commit e1dbfd70 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[nodeStory] insert/update/delete state handling

This doesn't work with locks yet.
parent 9166bb01
Pipeline #3129 passed with stage
in 93 minutes and 14 seconds
-- Start a new transaction. In case data migration goes wrong, we are
-- back to our original table.
BEGIN;
-- we will migrate data here -- we will migrate data here
-- rename old table and create a new one -- rename old table and create a new one
...@@ -56,3 +60,6 @@ INSERT INTO public.node_stories ...@@ -56,3 +60,6 @@ INSERT INTO public.node_stories
FROM node_stories_old FROM node_stories_old
CROSS JOIN jsonb_each(archive->'state'->'NgramsTerms') AS j CROSS JOIN jsonb_each(archive->'state'->'NgramsTerms') AS j
JOIN ngrams ON terms = j.key; JOIN ngrams ON terms = j.key;
-- finally, write out the stuff
COMMIT;
...@@ -259,15 +259,6 @@ setListNgrams listId ngramsType ns = do ...@@ -259,15 +259,6 @@ setListNgrams listId ngramsType ns = do
saveNodeStory saveNodeStory
currentVersion :: HasNodeStory env err m
=> ListId -> m Version
currentVersion listId = do
--nls <- getRepo [listId]
pool <- view connPool
nls <- liftBase $ getNodeStory pool listId
pure $ nls ^. unNodeStory . at listId . _Just . a_version
newNgramsFromNgramsStatePatch :: NgramsStatePatch' -> [Ngrams] newNgramsFromNgramsStatePatch :: NgramsStatePatch' -> [Ngrams]
newNgramsFromNgramsStatePatch p = newNgramsFromNgramsStatePatch p =
[ text2ngrams (unNgramsTerm n) [ text2ngrams (unNgramsTerm n)
......
...@@ -19,6 +19,7 @@ import Control.Lens (_Just, (^.), at, view, At, Index, IxValue) ...@@ -19,6 +19,7 @@ import Control.Lens (_Just, (^.), at, view, At, Index, IxValue)
import Control.Monad.Reader import Control.Monad.Reader
import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict (HashMap)
import Data.Hashable (Hashable) import Data.Hashable (Hashable)
import Data.Pool (withResource)
import Data.Set (Set) import Data.Set (Set)
import Data.Validity import Data.Validity
import Gargantext.API.Ngrams.Types import Gargantext.API.Ngrams.Types
...@@ -202,15 +203,16 @@ migrateFromDirToDb :: (CmdM env err m, HasNodeStory env err m) ...@@ -202,15 +203,16 @@ migrateFromDirToDb :: (CmdM env err m, HasNodeStory env err m)
=> m () => m ()
migrateFromDirToDb = do migrateFromDirToDb = do
pool <- view connPool pool <- view connPool
listIds <- liftBase $ getNodesIdWithType pool NodeList withResource pool $ \c -> do
printDebug "[migrateFromDirToDb] listIds" listIds listIds <- liftBase $ getNodesIdWithType c NodeList
(NodeStory nls) <- NSF.getRepoReadConfig listIds printDebug "[migrateFromDirToDb] listIds" listIds
printDebug "[migrateFromDirToDb] nls" nls (NodeStory nls) <- NSF.getRepoReadConfig listIds
_ <- mapM (\(nId, a) -> do printDebug "[migrateFromDirToDb] nls" nls
n <- liftBase $ nodeExists pool nId _ <- mapM (\(nId, a) -> do
case n of n <- liftBase $ nodeExists c nId
False -> pure () case n of
True -> liftBase $ upsertNodeArchive pool nId a False -> pure ()
) $ Map.toList nls True -> liftBase $ upsertNodeStories c nId a
--_ <- nodeStoryIncs (Just $ NodeStory nls) listIds ) $ Map.toList nls
pure () --_ <- nodeStoryIncs (Just $ NodeStory nls) listIds
pure ()
This diff is collapsed.
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