module Main where
+import Data.Either (Either(..))
+import Data.Maybe (Maybe(..))
import System.Environment (getArgs)
import Gargantext.Prelude
-import Gargantext.Database.Flow (FlowCmdM, flowCorpusFile, getOrMkRoot)
-import Gargantext.Text.Corpus.Parsers (FileFormat(..))
+import Gargantext.Core.Types.Individu (UserId, User(..))
+import Gargantext.Database.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
+import Gargantext.Database.Schema.Node (getOrMkList)
import Gargantext.Database.Utils (Cmd, )
-import Gargantext.Database.Types.Node (CorpusId, toHyperdataDocument, RootId)
-import Gargantext.Database.Schema.User (insertUsersDemo, UserId)
-import Gargantext.Text.Terms (TermType(..))
-import Gargantext.Core (Lang(..))
+import Gargantext.Database.Types.Node (CorpusId, RootId, HyperdataCorpus, ListId)
+import Gargantext.Database.Schema.User (insertUsersDemo)
import Gargantext.API.Types (GargError)
import Gargantext.API.Node () -- instances
-import Gargantext.API.Settings (withDevEnv, runCmdDev, DevEnv)
---import Gargantext.Text.Corpus.Parsers.GrandDebat (readFile, GrandDebatReference(..))
-import Data.Text (Text)
-import qualified Data.Text as Text
-import Control.Monad.IO.Class (liftIO)
-
+import Gargantext.API.Settings (withDevEnv, runCmdDev)
+import Gargantext.Database.Config (userMaster, corpusMasterName)
+import Gargantext.Database.Init (initTriggers)
main :: IO ()
main = do
[iniPath] <- getArgs
let createUsers :: Cmd GargError Int64
createUsers = insertUsersDemo
-
+
let
- mkRoots :: Cmd GargError (UserId, RootId)
- mkRoots = getOrMkRoot "user1"
+ mkRoots :: Cmd GargError [(UserId, RootId)]
+ mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2"]
+ -- TODO create all users roots
+ let
+ initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
+ initMaster = do
+ (masterUserId, masterRootId, masterCorpusId) <- getOrMk_RootWithCorpus (UserName userMaster) (Left corpusMasterName) (Nothing :: Maybe HyperdataCorpus)
+ masterListId <- getOrMkList masterCorpusId masterUserId
+ _triggers <- initTriggers masterListId
+ pure (masterUserId, masterRootId, masterCorpusId, masterListId)
withDevEnv iniPath $ \env -> do
_ <- runCmdDev env createUsers
_ <- runCmdDev env mkRoots
+ x <- runCmdDev env initMaster
+ putStrLn $ show x
pure ()