3 Description : Gargantext Import Corpus
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Import a corpus binary.
14 {-# LANGUAGE Strict #-}
15 {-# LANGUAGE QuasiQuotes #-}
19 import Data.Either (Either(..))
20 import Database.PostgreSQL.Simple.SqlQQ (sql)
21 import GHC.IO.Exception (IOException)
22 import Gargantext.API.Admin.EnvTypes (DevEnv)
23 import Gargantext.API.Dev (withDevEnv, runCmdDev)
24 import Gargantext.API.Ngrams.Tools (migrateFromDirToDb)
25 import Gargantext.API.Node () -- instances only
26 import Gargantext.API.Prelude (GargError)
27 import Gargantext.Core (HasDBid(toDBid))
28 import Gargantext.Core.Types.Individu (User(..))
29 import Gargantext.Database.Action.Flow (getOrMk_RootWithCorpus)
30 import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
31 import Gargantext.Database.Admin.Trigger.Init
32 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataCorpus)
33 import Gargantext.Database.Admin.Types.Node (NodeType(NodeDocument, NodeContact))
34 import Gargantext.Database.Prelude (Cmd'', Cmd, execPGSQuery)
35 import Gargantext.Prelude
36 import Gargantext.Prelude.Config (GargConfig(..), readConfig)
37 import Prelude (getLine)
38 import System.Environment (getArgs)
39 import qualified Data.List as List (cycle, concat, take, unlines)
50 putStrLn "GarganText upgrade to version 0.0.6.9.9.4.4"
53 params@[iniPath] <- getArgs
54 _ <- if length params /= 1
55 then panic "Usage: ./gargantext-upgrade gargantext.ini"
58 putStrLn $ List.unlines
59 [ "Your Database defined in gargantext.ini will be upgraded."
60 , "We stronlgy recommend you to make a backup using pg_dump."
62 , "Press ENTER if you want to continue, CTRL+C if you want to stop."
67 cfg <- readConfig iniPath
68 let _secret = _gc_secretkey cfg
70 withDevEnv iniPath $ \env -> do
71 _ <- runCmdDev env addIndex
72 _ <- runCmdDev env refreshIndex
76 putStrLn "Uprade done with success !"
80 refreshIndex :: Cmd'' DevEnv IOException ()
82 _ <- execPGSQuery [sql| refresh materialized view context_node_ngrams_view; |] ()
85 addIndex :: Cmd'' DevEnv IOException Int64
90 create materialized view if not exists context_node_ngrams_view as
91 select context_node_ngrams.context_id, ngrams_id, nodes_contexts.node_id
93 join context_node_ngrams
94 on context_node_ngrams.context_id = nodes_contexts.context_id;
96 create index if not exists context_node_ngrams_context_id_ngrams_id_idx on context_node_ngrams(context_id, ngrams_id);
97 create index if not exists context_node_ngrams_view_context_id_idx on context_node_ngrams_view(context_id);
98 create index if not exists context_node_ngrams_view_ngrams_id_idx on context_node_ngrams_view(ngrams_id);
99 create index if not exists context_node_ngrams_view_node_id_idx on context_node_ngrams_view(node_id);
100 create index if not exists node_stories_ngrams_id_idx on node_stories(ngrams_id);