Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
cc5cef13
Commit
cc5cef13
authored
Sep 05, 2022
by
Alp Mestanogullari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check that garg-init has been executed at startup, abort with helpful error if not
parent
91b97fbd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
API.hs
src/Gargantext/API.hs
+15
-1
Prelude.hs
src/Gargantext/Database/Prelude.hs
+9
-3
No files found.
src/Gargantext/API.hs
View file @
cc5cef13
...
...
@@ -31,10 +31,13 @@ Pouillard (who mainly made it).
module
Gargantext.API
where
import
Control.Exception
(
finally
)
import
Control.Exception
(
catch
,
finally
,
SomeException
)
import
Control.Lens
import
Control.Monad.Except
import
Control.Monad.Reader
(
runReaderT
)
import
Data.Either
import
Data.List
(
lookup
)
import
Data.Text
(
pack
)
import
Data.Text.Encoding
(
encodeUtf8
)
import
Data.Text.IO
(
putStrLn
)
import
Data.Validity
...
...
@@ -49,6 +52,7 @@ import Gargantext.API.Prelude
import
Gargantext.API.Routes
import
Gargantext.API.Server
(
server
)
import
Gargantext.Core.NodeStory
import
qualified
Gargantext.Database.Prelude
as
DB
import
Gargantext.Prelude
hiding
(
putStrLn
)
import
Network.HTTP.Types
hiding
(
Query
)
import
Network.Wai
...
...
@@ -66,11 +70,21 @@ data Mode = Dev | Mock | Prod
startGargantext
::
Mode
->
PortNumber
->
FilePath
->
IO
()
startGargantext
mode
port
file
=
do
env
<-
newEnv
port
file
runDbCheck
env
portRouteInfo
port
app
<-
makeApp
env
mid
<-
makeDevMiddleware
mode
run
port
(
mid
app
)
`
finally
`
stopGargantext
env
where
runDbCheck
env
=
do
r
<-
runExceptT
(
runReaderT
DB
.
dbCheck
env
)
`
catch
`
(
\
(
_
::
SomeException
)
->
return
$
Right
False
)
case
r
of
Right
True
->
return
()
_
->
panic
$
"You must run 'gargantext-init "
<>
pack
file
<>
"' before running gargantext-server (only the first time)."
portRouteInfo
::
PortNumber
->
IO
()
portRouteInfo
port
=
do
putStrLn
" ----Main Routes----- "
...
...
src/Gargantext/Database/Prelude.hs
View file @
cc5cef13
...
...
@@ -9,7 +9,7 @@ Portability : POSIX
-}
{-# LANGUAGE ConstraintKinds
#-}
{-# LANGUAGE ConstraintKinds
, ScopedTypeVariables
#-}
module
Gargantext.Database.Prelude
where
...
...
@@ -30,6 +30,7 @@ import Data.Word (Word16)
import
Database.PostgreSQL.Simple
(
Connection
,
connect
)
import
Database.PostgreSQL.Simple.FromField
(
Conversion
,
ResultError
(
ConversionFailed
),
fromField
,
returnError
)
import
Database.PostgreSQL.Simple.Internal
(
Field
)
import
Database.PostgreSQL.Simple.Types
(
Query
(
..
))
import
Gargantext.Core.Mail.Types
(
HasMail
)
import
Gargantext.Prelude
import
Gargantext.Prelude.Config
(
readIniFile'
,
val
)
...
...
@@ -167,10 +168,9 @@ runPGSQuery_ :: ( CmdM env err m
runPGSQuery_
q
=
mkCmd
$
\
conn
->
catch
(
PGS
.
query_
conn
q
)
printError
where
printError
(
SomeException
e
)
=
do
printDebug
"[G.D.P.runPGSQuery_]"
(
"TODO: format query error"
::
Text
)
hPutStrLn
stderr
(
fromQuery
q
)
throw
(
SomeException
e
)
execPGSQuery
::
PGS
.
ToRow
a
=>
PGS
.
Query
->
a
->
Cmd
err
Int64
execPGSQuery
q
a
=
mkCmd
$
\
conn
->
PGS
.
execute
conn
q
a
...
...
@@ -209,3 +209,9 @@ fromField' field mb = do
printSqlOpa
::
Default
Unpackspec
a
a
=>
Select
a
->
IO
()
printSqlOpa
=
putStrLn
.
maybe
"Empty query"
identity
.
showSql
dbCheck
::
CmdM
env
err
m
=>
m
Bool
dbCheck
=
do
r
::
[
PGS
.
Only
Text
]
<-
runPGSQuery_
"select username from public.auth_user"
case
r
of
[]
->
return
False
_
->
return
True
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment