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
153
Issues
153
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
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
705f1e2d
Commit
705f1e2d
authored
Sep 07, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DB] triggers ok
parent
db0a62b6
Pipeline
#1040
failed with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
27 deletions
+55
-27
Main.hs
bin/gargantext-init/Main.hs
+8
-3
schema.sql
devops/postgres/schema.sql
+0
-3
Init.hs
src/Gargantext/Database/Admin/Trigger/Init.hs
+10
-5
Nodes.hs
src/Gargantext/Database/Admin/Trigger/Nodes.hs
+37
-16
No files found.
bin/gargantext-init/Main.hs
View file @
705f1e2d
...
...
@@ -15,6 +15,7 @@ Import a corpus binary.
module
Main
where
import
Data.Text
(
Text
)
import
Data.Either
(
Either
(
..
))
import
Data.Maybe
(
Maybe
(
..
))
import
Gargantext.API.Admin.Settings
(
withDevEnv
,
runCmdDev
)
...
...
@@ -26,13 +27,16 @@ import Gargantext.Database.Query.Table.Node (getOrMkList)
import
Gargantext.Database.Query.Table.User
(
insertUsersDemo
)
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Trigger.Init
(
initTriggers
)
import
Gargantext.Database.Admin.Trigger.Init
(
init
FirstTriggers
,
initLast
Triggers
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataCorpus
)
import
Gargantext.Database.Admin.Types.Node
(
CorpusId
,
RootId
,
ListId
)
import
Gargantext.Database.Prelude
(
Cmd
,
)
import
Gargantext.Prelude
import
System.Environment
(
getArgs
)
secret
::
Text
secret
=
"Database secret to change"
main
::
IO
()
main
=
do
[
iniPath
]
<-
getArgs
...
...
@@ -50,12 +54,13 @@ main = do
initMaster
=
do
(
masterUserId
,
masterRootId
,
masterCorpusId
)
<-
getOrMk_RootWithCorpus
(
UserName
userMaster
)
(
Left
corpusMasterName
)
(
Nothing
::
Maybe
HyperdataCorpus
)
masterListId
<-
getOrMkList
masterCorpusId
masterUserId
_triggers
<-
initTriggers
masterListId
_triggers
<-
init
Last
Triggers
masterListId
pure
(
masterUserId
,
masterRootId
,
masterCorpusId
,
masterListId
)
withDevEnv
iniPath
$
\
env
->
do
_
<-
runCmdDev
env
(
initFirstTriggers
secret
::
Cmd
GargError
[
Int64
])
_
<-
runCmdDev
env
createUsers
_
<-
runCmdDev
env
mkRoots
x
<-
runCmdDev
env
initMaster
_
<-
runCmdDev
env
mkRoots
putStrLn
$
show
x
pure
()
devops/postgres/schema.sql
View file @
705f1e2d
...
...
@@ -192,6 +192,3 @@ CREATE OR REPLACE function node_pos(int, int) returns bigint
--drop index node_by_pos;
create
index
node_by_pos
on
nodes
using
btree
(
node_pos
(
id
,
typename
));
src/Gargantext/Database/Admin/Trigger/Init.hs
View file @
705f1e2d
...
...
@@ -16,17 +16,22 @@ Ngrams by node enable contextual metrics.
module
Gargantext.Database.Admin.Trigger.Init
where
import
Data.Text
(
Text
)
import
Gargantext.Database.Admin.Trigger.NodeNodeNgrams
(
triggerCountInsert
,
triggerCountInsert2
)
import
Gargantext.Database.Admin.Trigger.Nodes
(
triggerSearchUpdate
)
import
Gargantext.Database.Admin.Trigger.Nodes
(
triggerSearchUpdate
,
triggerUpdateHash
)
import
Gargantext.Database.Admin.Trigger.NodesNodes
(
triggerDeleteCount
,
triggerInsertCount
,
triggerUpdateAdd
,
triggerUpdateDel
,
MasterListId
)
-- , triggerCoocInsert)
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Prelude
------------------------------------------------------------------------
initTriggers
::
MasterListId
->
Cmd
err
[
Int64
]
initTriggers
lId
=
do
t0
<-
triggerSearchUpdate
initFirstTriggers
::
Text
->
Cmd
err
[
Int64
]
initFirstTriggers
secret
=
do
t0
<-
triggerUpdateHash
secret
pure
[
t0
]
initLastTriggers
::
MasterListId
->
Cmd
err
[
Int64
]
initLastTriggers
lId
=
do
t0
<-
triggerSearchUpdate
t1
<-
triggerCountInsert
t1'
<-
triggerCountInsert2
-- t1'' <- triggerCoocInsert lId
...
...
src/Gargantext/Database/Admin/Trigger/Nodes.hs
View file @
705f1e2d
...
...
@@ -16,6 +16,7 @@ Triggers on Nodes table.
module
Gargantext.Database.Admin.Trigger.Nodes
where
import
Data.Text
(
Text
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
qualified
Database.PostgreSQL.Simple
as
DPS
...
...
@@ -67,32 +68,52 @@ triggerSearchUpdate = execPGSQuery query ( nodeTypeId NodeDocument
|]
triggerUpdateHash
::
Cmd
err
Int64
triggerUpdateHash
=
execPGSQuery
query
(
nodeTypeId
NodeDocument
,
nodeTypeId
NodeContact
)
type
Secret
=
Text
triggerUpdateHash
::
Secret
->
Cmd
err
Int64
triggerUpdateHash
secret
=
execPGSQuery
query
(
nodeTypeId
NodeDocument
,
nodeTypeId
NodeContact
,
secret
,
secret
,
nodeTypeId
NodeDocument
,
nodeTypeId
NodeContact
,
secret
,
secret
)
where
query
::
DPS
.
Query
query
=
[
sql
|
CREATE OR REPLACE FUNCTION hash_insert_nodes()
RETURNS trigger AS $$
BEGIN
IF NEW.hash_id = ''
THEN
IF NEW.typename = ? OR NEW.typename = ?
THEN NEW.hash_id = digest(CONCAT(?, NEW.typename, NEW.name, NEW.parent_id, NEW.hyperdata), 'sha256');
ELSE NEW.hash_id = digest(CONCAT(?, NEW.typename, NEW.name, NEW.id, NEW.hyperdata), 'sha256');
END IF;
END IF;
RETURN NEW;
END
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION hash_update_nodes()
RETURNS trigger AS $$
BEGIN
IF tg_op = 'INSERT' OR tg_op = 'UPDATE' THEN
IF NEW.hash_id = ''
THEN
IF NEW.typename = ? OR NEW.typename = ?
THEN NEW.hash_id = digest(CONCAT(NEW.parent_id, NEW.hyperdata), 'sha256');
ELSE NEW.hash_id = digest(CONCAT(NEW.id, NEW.hyperdata), 'sha256');
END IF;
END IF;
RETURN NEW;
END IF;
IF NEW.typename = ? OR NEW.typename = ?
THEN NEW.hash_id = digest(CONCAT(?, NEW.typename, NEW.name, NEW.parent_id, NEW.hyperdata), 'sha256');
ELSE NEW.hash_id = digest(CONCAT(?, NEW.typename, NEW.name, NEW.id, NEW.hyperdata), 'sha256');
END IF;
RETURN NEW;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER some_table_hash_update
BEFORE INSERT OR UPDATE ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_update_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();
|]
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