Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
152
Issues
152
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
gargantext
haskell-gargantext
Commits
cfbd39f8
Commit
cfbd39f8
authored
Jan 20, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MIGRATION] upgrade script (WIP)
parent
e724b810
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
94 additions
and
48 deletions
+94
-48
Main.hs
bin/gargantext-init/Main.hs
+8
-9
Main.hs
bin/gargantext-upgrade/Main.hs
+53
-12
create
devops/postgres/create
+3
-1
schema.sql
devops/postgres/schema.sql
+0
-2
schema.sql
devops/postgres/upgrade/0.0.5/schema.sql
+6
-1
package.yaml
package.yaml
+14
-13
ContextNodeNgrams.hs
src/Gargantext/Database/Admin/Trigger/ContextNodeNgrams.hs
+2
-2
Contexts.hs
src/Gargantext/Database/Admin/Trigger/Contexts.hs
+7
-7
Init.hs
src/Gargantext/Database/Admin/Trigger/Init.hs
+1
-1
No files found.
bin/gargantext-init/Main.hs
View file @
cfbd39f8
...
...
@@ -15,27 +15,24 @@ Import a corpus binary.
module
Main
where
import
Data.Text
(
Text
)
import
Data.Either
(
Either
(
..
))
import
Gargantext.API.Dev
(
withDevEnv
,
runCmdDev
)
import
Gargantext.API.Prelude
(
GargError
)
import
Gargantext.API.Node
()
-- instances only
import
Gargantext.API.Prelude
(
GargError
)
import
Gargantext.Core.Types.Individu
(
User
(
..
),
arbitraryNewUsers
,
NewUser
(
..
),
arbitraryUsername
,
GargPassword
(
..
))
import
Gargantext.Database.Action.Flow
(
getOrMkRoot
,
getOrMk_RootWithCorpus
)
import
Gargantext.Database.Query.Table.Node
(
getOrMkList
)
import
Gargantext.Database.Query.Table.User
(
insertNewUsers
,
)
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Trigger.Init
(
initFirstTriggers
,
initLastTriggers
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataCorpus
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
(
Cmd
,
)
import
Gargantext.Database.Query.Table.Node
(
getOrMkList
)
import
Gargantext.Database.Query.Table.User
(
insertNewUsers
,
)
import
Gargantext.Prelude
import
System.Environment
(
getArgs
)
import
Gargantext.Prelude.Config
(
GargConfig
(
..
),
readConfig
)
import
Prelude
(
getLine
)
import
System.Environment
(
getArgs
)
-- TODO put this in gargantext.ini
secret
::
Text
secret
=
"Database secret to change"
main
::
IO
()
main
=
do
...
...
@@ -51,6 +48,8 @@ main = do
putStrLn
"Enter master user (gargantua) _email_ :"
email
<-
getLine
cfg
<-
readConfig
iniPath
let
secret
=
_gc_secretkey
cfg
let
createUsers
::
Cmd
GargError
Int64
createUsers
=
insertNewUsers
(
NewUser
"gargantua"
(
cs
email
)
(
GargPassword
$
cs
password
)
...
...
bin/gargantext-upgrade/Main.hs
View file @
cfbd39f8
...
...
@@ -12,44 +12,85 @@ Import a corpus binary.
-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE QuasiQuotes #-}
module
Main
where
import
Data.Text
(
Text
)
import
Gargantext.API.Admin.EnvTypes
(
DevEnv
)
import
Gargantext.API.Dev
(
withDevEnv
,
runCmdDev
)
import
Gargantext.API.Prelude
(
GargError
)
import
Gargantext.API.Node
()
-- instances only
import
Gargantext.API.Ngrams.Tools
(
getRepo
)
-- import Gargantext.API.Ngrams.Tools (getRepo)
import
Gargantext.Database.Query.Table.Node
(
getOrMkList
)
import
Data.Either
(
Either
(
..
))
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataCorpus
)
import
Gargantext.Database.Prelude
(
Cmd
''
,
)
import
Gargantext.Database.Action.Flow
(
getOrMkRoot
,
getOrMk_RootWithCorpus
)
import
Gargantext.Core.NodeStory
import
Gargantext.Core.Types.Individu
(
User
(
..
),
arbitraryNewUsers
,
NewUser
(
..
),
arbitraryUsername
,
GargPassword
(
..
))
import
Gargantext.Prelude
import
Gargantext.Prelude.Config
(
GargConfig
(
..
),
readConfig
)
import
System.Environment
(
getArgs
)
import
Prelude
(
getLine
)
import
GHC.IO.Exception
(
IOException
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Gargantext.Database.Prelude
(
Cmd
,
execPGSQuery
)
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Trigger.Init
import
Gargantext.Prelude
import
Gargantext.Prelude.Config
(
GargConfig
(
..
),
readConfig
)
main
::
IO
()
main
=
do
putStrLn
"Manual method:"
putStrLn
"Upgrade your GarganText instance with the script:"
putStrLn
"Then press enter key to launch upgrade."
putStrLn
"./bin/psql gargantext.ini < devops/postgres/upgrade/0.0.5/schema.sql"
putStrLn
"Then press enter key when you are done."
_ok
<-
getLine
[
iniPath
]
<-
getArgs
cfg
<-
readConfig
iniPath
let
secret
=
_gc_secretkey
cfg
let
-- upgrade :: Cmd'' DevEnv GargError ()
upgrade
::
Cmd''
DevEnv
IOException
()
upgrade
=
do
let
repo_filepath
=
_gc_repofilepath
cfg
repo
<-
getRepo
_
<-
liftBase
$
repoMigration
repo_filepath
repo
sqlUpdateTriggerHash
::
Cmd''
DevEnv
IOException
Int64
sqlUpdateTriggerHash
=
do
execPGSQuery
query
()
where
query
=
[
sql
|
UPDATE nodes SET typename = typename;
|]
let
sqlNodes2Context
::
Cmd''
DevEnv
IOException
Int64
sqlNodes2Context
=
do
execPGSQuery
query
()
where
query
=
[
sql
|
UPDATE nodes SET typename = typename;
|]
let
contextsTriggers
::
Cmd
GargError
()
contextsTriggers
=
do
(
masterUserId
,
_masterRootId
,
masterCorpusId
)
<-
getOrMk_RootWithCorpus
(
UserName
userMaster
)
(
Left
corpusMasterName
)
(
Nothing
::
Maybe
HyperdataCorpus
)
masterListId
<-
getOrMkList
masterCorpusId
masterUserId
_triggers
<-
initLastTriggers
masterListId
pure
()
withDevEnv
iniPath
$
\
env
->
do
_
<-
runCmdDev
env
upgrade
_
<-
runCmdDev
env
(
initFirstTriggers
secret
::
Cmd
GargError
[
Int64
])
_
<-
runCmdDev
env
(
contextsTriggers
::
Cmd
GargError
()
)
_
<-
runCmdDev
env
sqlUpdateTriggerHash
putStrLn
"Uprade done with success"
pure
()
pure
()
devops/postgres/create
View file @
cfbd39f8
...
...
@@ -13,7 +13,9 @@ USER="gargantua"
psql
-c
"DROP DATABASE IF EXISTS
\"
${
DB
}
\"
"
createdb
"
${
DB
}
"
psql
"
${
DB
}
"
< schema.sql
#psql "${DB}" < schema.sql
../../bin/psql ../../gargantext.ini < gargandb.dump
psql
-c
"ALTER DATABASE
\"
${
DB
}
\"
OWNER to
\"
${
USER
}
\"
"
...
...
devops/postgres/schema.sql
View file @
cfbd39f8
...
...
@@ -154,8 +154,6 @@ CREATE TABLE public.context_node_ngrams (
weight
double
precision
,
PRIMARY
KEY
(
context_id
,
node_id
,
ngrams_id
,
ngrams_type
)
);
ALTER
TABLE
public
.
context_node_ngrams
OWNER
TO
gargantua
;
CREATE
TABLE
public
.
context_node_ngrams2
(
...
...
devops/postgres/upgrade/0.0.5/schema.sql
View file @
cfbd39f8
...
...
@@ -73,5 +73,10 @@ CREATE INDEX ON public.context_node_ngrams2 USING btree (context_id);
CREATE
INDEX
ON
public
.
context_node_ngrams2
USING
btree
(
nodengrams_id
);
CREATE
INDEX
ON
public
.
context_node_ngrams2
USING
btree
(
context_id
,
nodengrams_id
);
DROP
TABLE
if
EXISTS
public
.
node_nodengrams_nodengrams
;
DROP
TRIGGER
if
EXISTS
trigger_count_delete2
ON
nodes_nodes
;
DROP
TRIGGER
if
EXISTS
trigger_count_update_add
ON
nodes_nodes
;
DROP
TRIGGER
if
EXISTS
trigger_delete_count
ON
nodes_nodes
;
DROP
TRIGGER
if
EXISTS
trigger_insert_count
ON
nodes_nodes
;
DELETE
TABLE
public
.
node_nodengrams_nodengrams
package.yaml
View file @
cfbd39f8
...
...
@@ -379,19 +379,20 @@ executables:
-
gargantext-prelude
-
base
# gargantext-upgrade:
# main: Main.hs
# source-dirs: bin/gargantext-upgrade
# ghc-options:
# - -threaded
# - -rtsopts
# - -with-rtsopts=-N
# - -O2
# - -Wmissing-signatures
# dependencies:
# - gargantext
# - gargantext-prelude
# - base
gargantext-upgrade
:
main
:
Main.hs
source-dirs
:
bin/gargantext-upgrade
ghc-options
:
-
-threaded
-
-rtsopts
-
-with-rtsopts=-N
-
-O2
-
-Wmissing-signatures
dependencies
:
-
gargantext
-
gargantext-prelude
-
base
-
postgresql-simple
gargantext-admin
:
main
:
Main.hs
...
...
src/Gargantext/Database/Admin/Trigger/ContextNodeNgrams.hs
View file @
cfbd39f8
...
...
@@ -52,7 +52,7 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
END
$$ LANGUAGE plpgsql;
-- DROP trigger
trigger_count_insert on context_node_ngrams;
DROP trigger IF EXISTS
trigger_count_insert on context_node_ngrams;
CREATE TRIGGER trigger_count_insert AFTER INSERT on context_node_ngrams
REFERENCING NEW TABLE AS NEW
...
...
@@ -95,7 +95,7 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
END
$$ LANGUAGE plpgsql;
-- DROP trigger
trigger_count_insert2 on context_node_ngrams2;
DROP trigger IF EXISTS
trigger_count_insert2 on context_node_ngrams2;
CREATE TRIGGER trigger_count_insert2 AFTER INSERT on context_node_ngrams2
REFERENCING NEW TABLE AS NEW
...
...
src/Gargantext/Database/Admin/Trigger/
Node
s.hs
→
src/Gargantext/Database/Admin/Trigger/
Context
s.hs
View file @
cfbd39f8
...
...
@@ -13,7 +13,7 @@ Triggers on Nodes table.
{-# LANGUAGE QuasiQuotes #-}
module
Gargantext.Database.Admin.Trigger.
Node
s
module
Gargantext.Database.Admin.Trigger.
Context
s
where
import
Data.Text
(
Text
)
...
...
@@ -33,7 +33,6 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
where
query
::
DPS
.
Query
query
=
[
sql
|
-- DROP TRIGGER search_update_trigger on contexts;
CREATE OR REPLACE FUNCTION public.search_update()
RETURNS trigger AS $$
begin
...
...
@@ -57,6 +56,7 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
ALTER FUNCTION public.search_update() OWNER TO gargantua;
DROP TRIGGER IF EXISTS search_update_trigger on contexts;
CREATE TRIGGER search_update_trigger
BEFORE INSERT OR UPDATE
ON contexts FOR EACH ROW
...
...
@@ -109,13 +109,13 @@ triggerUpdateHash secret = execPGSQuery query ( toDBid NodeDocument
END
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS nodes_hash_insert ON nodes;
DROP TRIGGER IF EXISTS nodes_hash_update ON nodes;
CREATE TRIGGER nodes_hash_insert BEFORE INSERT ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_insert_nodes();
CREATE TRIGGER nodes_hash_update BEFORE UPDATE ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_update_nodes();
DROP TRIGGER IF EXISTS contexts_hash_insert ON contexts;
DROP TRIGGER IF EXISTS contexts_hash_update ON contexts;
CREATE TRIGGER contexts_hash_insert BEFORE INSERT ON contexts FOR EACH ROW EXECUTE PROCEDURE hash_insert_nodes();
CREATE TRIGGER contexts_hash_update BEFORE UPDATE ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_update_nodes();
CREATE TRIGGER contexts_hash_update BEFORE UPDATE ON contexts FOR EACH ROW EXECUTE PROCEDURE hash_update_nodes();
|]
src/Gargantext/Database/Admin/Trigger/Init.hs
View file @
cfbd39f8
...
...
@@ -18,7 +18,7 @@ module Gargantext.Database.Admin.Trigger.Init
import
Data.Text
(
Text
)
import
Gargantext.Database.Admin.Trigger.ContextNodeNgrams
(
triggerCountInsert
,
triggerCountInsert2
)
import
Gargantext.Database.Admin.Trigger.
Node
s
(
triggerSearchUpdate
,
triggerUpdateHash
)
import
Gargantext.Database.Admin.Trigger.
Context
s
(
triggerSearchUpdate
,
triggerUpdateHash
)
import
Gargantext.Database.Admin.Trigger.NodesContexts
(
{-triggerDeleteCount,-}
triggerInsertCount
,
triggerUpdateAdd
,
triggerUpdateDel
,
MasterListId
)
-- , triggerCoocInsert)
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Prelude
...
...
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