]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-init/Main.hs
[Backup][WIP]
[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 Strict #-}
15
16 module Main where
17
18 import Data.Text (Text)
19 import Data.Either (Either(..))
20 import Gargantext.API.Dev (withDevEnv, runCmdDev)
21 import Gargantext.API.Prelude (GargError)
22 import Gargantext.API.Node () -- instances only
23 import Gargantext.Core.Types.Individu (User(..), arbitraryNewUsers, NewUser(..), arbitraryUsername, GargPassword(..))
24 import Gargantext.Database.Action.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
25 import Gargantext.Database.Query.Table.Node (getOrMkList)
26 import Gargantext.Database.Query.Table.User (insertNewUsers, )
27 import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
28 import Gargantext.Database.Admin.Types.Node
29 import Gargantext.Database.Admin.Trigger.Init (initFirstTriggers, initLastTriggers)
30 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataCorpus)
31 import Gargantext.Database.Prelude (Cmd, )
32 import Gargantext.Prelude
33 import System.Environment (getArgs)
34 import Prelude (getLine)
35
36 -- TODO put this in gargantext.ini
37 secret :: Text
38 secret = "Database secret to change"
39
40 main :: IO ()
41 main = do
42 params@[iniPath] <- getArgs
43
44 _ <- if length params /= 1
45 then panic "USAGE: ./gargantext-init gargantext.ini"
46 else pure ()
47
48 putStrLn "Enter master user (gargantua) _password_ :"
49 password <- getLine
50
51 putStrLn "Enter master user (gargantua) _email_ :"
52 email <- getLine
53
54
55 let createUsers :: Cmd GargError Int64
56 createUsers = insertNewUsers (NewUser "gargantua" (cs email) (GargPassword $ cs password)
57 : arbitraryNewUsers
58 )
59
60 let
61 mkRoots :: Cmd GargError [(UserId, RootId)]
62 mkRoots = mapM getOrMkRoot $ map UserName ("gargantua" : arbitraryUsername)
63 -- TODO create all users roots
64
65 let
66 initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
67 initMaster = do
68 (masterUserId, masterRootId, masterCorpusId)
69 <- getOrMk_RootWithCorpus (UserName userMaster)
70 (Left corpusMasterName)
71 (Nothing :: Maybe HyperdataCorpus)
72 masterListId <- getOrMkList masterCorpusId masterUserId
73 _triggers <- initLastTriggers masterListId
74 pure (masterUserId, masterRootId, masterCorpusId, masterListId)
75
76 withDevEnv iniPath $ \env -> do
77 _ <- runCmdDev env (initFirstTriggers secret :: Cmd GargError [Int64])
78 _ <- runCmdDev env createUsers
79 x <- runCmdDev env initMaster
80 _ <- runCmdDev env mkRoots
81 putStrLn $ show x
82 pure ()