]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-init/Main.hs
[ADM] doc for gargantext.ini
[gargantext.git] / bin / gargantext-init / Main.hs
1 {-|
2 Module : Main.hs
3 Description : Gargantext Import Corpus
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Import a corpus binary.
11
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE RankNTypes #-}
18 {-# LANGUAGE Strict #-}
19
20 module Main where
21
22 import Data.Either (Either(..))
23 import Data.Maybe (Maybe(..))
24 import System.Environment (getArgs)
25 import Gargantext.Prelude
26 import Gargantext.Core.Types.Individu (UserId, User(..))
27 import Gargantext.Database.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
28 import Gargantext.Database.Schema.Node (getOrMkList)
29 import Gargantext.Database.Utils (Cmd, )
30 import Gargantext.Database.Types.Node (CorpusId, RootId, HyperdataCorpus, ListId)
31 import Gargantext.Database.Schema.User (insertUsersDemo)
32 import Gargantext.API.Types (GargError)
33 import Gargantext.API.Node () -- instances
34 import Gargantext.API.Settings (withDevEnv, runCmdDev)
35 import Gargantext.Database.Config (userMaster, corpusMasterName)
36 import Gargantext.Database.Init (initTriggers)
37 main :: IO ()
38 main = do
39 [iniPath] <- getArgs
40
41 let createUsers :: Cmd GargError Int64
42 createUsers = insertUsersDemo
43
44 let
45 mkRoots :: Cmd GargError [(UserId, RootId)]
46 mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2"]
47 -- TODO create all users roots
48
49 let
50 initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
51 initMaster = do
52 (masterUserId, masterRootId, masterCorpusId) <- getOrMk_RootWithCorpus (UserName userMaster) (Left corpusMasterName) (Nothing :: Maybe HyperdataCorpus)
53 masterListId <- getOrMkList masterCorpusId masterUserId
54 _triggers <- initTriggers masterListId
55 pure (masterUserId, masterRootId, masterCorpusId, masterListId)
56
57 withDevEnv iniPath $ \env -> do
58 _ <- runCmdDev env createUsers
59 _ <- runCmdDev env mkRoots
60 x <- runCmdDev env initMaster
61 putStrLn $ show x
62 pure ()