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
8ece5eac
Commit
8ece5eac
authored
Sep 05, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DB] Trigger for sha256sum (WIP)
parent
d03e0973
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
+33
-17
schema.sql
devops/postgres/schema.sql
+5
-17
Nodes.hs
src/Gargantext/Database/Admin/Trigger/Nodes.hs
+28
-0
No files found.
devops/postgres/schema.sql
View file @
8ece5eac
CREATE
EXTENSION
IF
NOT
EXISTS
plpgsql
WITH
SCHEMA
pg_catalog
;
CREATE
EXTENSION
IF
NOT
EXISTS
tsm_system_rows
;
COMMENT
ON
EXTENSION
plpgsql
IS
'PL/pgSQL procedural language'
;
CREATE
EXTENSION
IF
NOT
EXISTS
tsm_system_rows
;
CREATE
EXTENSION
pgcrypto
;
-----------------------------------------------------------------
CREATE
TABLE
public
.
auth_user
(
id
SERIAL
,
password
CHARACTER
varying
(
128
)
NOT
NULL
,
...
...
@@ -191,19 +194,4 @@ create index node_by_pos on nodes using btree(node_pos(id,typename));
-- Trigger to update hash of nodes
CREATE
EXTENSION
pgcrypto
;
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
NEW
.
hash_id
=
digest
(
CONCAT
(
NEW
.
id
,
NEW
.
hyperdata
),
'sha256'
);
END
IF
;
RETURN
NEW
;
END
IF
;
END
$$
LANGUAGE
plpgsql
;
CREATE
TRIGGER
some_table_hash_update
BEFORE
INSERT
OR
UPDATE
ON
nodes
FOR
EACH
ROW
EXECUTE
PROCEDURE
hash_update_nodes
();
src/Gargantext/Database/Admin/Trigger/Nodes.hs
View file @
8ece5eac
...
...
@@ -67,4 +67,32 @@ triggerSearchUpdate = execPGSQuery query ( nodeTypeId NodeDocument
|]
triggerUpdateHash
::
Cmd
err
Int64
triggerUpdateHash
=
execPGSQuery
query
(
nodeTypeId
NodeDocument
,
nodeTypeId
NodeContact
)
where
query
::
DPS
.
Query
query
=
[
sql
|
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;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER some_table_hash_update
BEFORE INSERT OR 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