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
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
21cfdf17
Commit
21cfdf17
authored
Jun 28, 2023
by
Alexandre Delanoë
Committed by
Alfredo Di Napoli
Jun 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] update schema
parent
1d7ebc63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
schema.sql
devops/postgres/schema.sql
+84
-0
No files found.
devops/postgres/schema.sql
View file @
21cfdf17
...
...
@@ -357,3 +357,87 @@ ON context_node_ngrams(context_id, ngrams_id);
CREATE
INDEX
IF
NOT
EXISTS
node_stories_ngrams_id_idx
ON
node_stories
(
ngrams_id
);
----
-- Version 0.0.6.9.9.6.4.sql
-- ADD triggers
CREATE
OR
REPLACE
FUNCTION
check_node_stories_json
()
RETURNS
TRIGGER
AS
$$
DECLARE
missing_ngrams_exist
boolean
;
BEGIN
WITH
child_ngrams
as
(
SELECT
jsonb_array_elements_text
(
NEW
.
ngrams_repo_element
->
'children'
)
AS
term
),
parent_ngrams
AS
(
SELECT
NEW
.
ngrams_repo_element
->>
'root'
AS
term
),
ngrams_child_parent
AS
(
SELECT
child_ngrams
.
term
,
ngrams
.
terms
FROM
child_ngrams
LEFT
JOIN
ngrams
ON
child_ngrams
.
term
=
ngrams
.
terms
WHERE
ngrams
.
terms
IS
NULL
UNION
SELECT
parent_ngrams
.
term
,
ngrams
.
terms
FROM
parent_ngrams
LEFT
JOIN
ngrams
ON
parent_ngrams
.
term
=
ngrams
.
terms
WHERE
ngrams
.
terms
IS
NULL
AND
parent_ngrams
.
term
IS
NOT
NULL
)
SELECT
EXISTS
(
SELECT
*
FROM
ngrams_child_parent
)
INTO
missing_ngrams_exist
;
IF
missing_ngrams_exist
THEN
RAISE
EXCEPTION
'node_stories: ngrams are missing: %'
,
row_to_json
(
NEW
);
END
IF
;
RETURN
NEW
;
END
;
$$
LANGUAGE
plpgsql
;
CREATE
OR
REPLACE
TRIGGER
check_node_stories_json_trg
AFTER
INSERT
OR
UPDATE
ON
node_stories
FOR
EACH
ROW
EXECUTE
PROCEDURE
check_node_stories_json
();
CREATE
OR
REPLACE
FUNCTION
check_ngrams_json
()
RETURNS
TRIGGER
AS
$$
DECLARE
missing_ngrams_exist
boolean
;
BEGIN
WITH
child_ngrams
as
(
SELECT
jsonb_array_elements_text
(
ngrams_repo_element
->
'children'
)
AS
term
FROM
node_stories
WHERE
term
=
OLD
.
terms
),
parent_ngrams
AS
(
SELECT
ngrams_repo_element
->>
'root'
AS
term
FROM
node_stories
WHERE
term
=
OLD
.
terms
),
child_parent_ngrams
AS
(
SELECT
*
FROM
child_ngrams
UNION
SELECT
*
FROM
parent_ngrams
)
SELECT
EXISTS
(
SELECT
*
FROM
child_parent_ngrams
)
INTO
missing_ngrams_exist
;
IF
missing_ngrams_exist
THEN
RAISE
EXCEPTION
'ngrams are missing: %'
,
row_to_json
(
OLD
);
END
IF
;
RETURN
OLD
;
END
;
$$
LANGUAGE
plpgsql
;
CREATE
OR
REPLACE
TRIGGER
check_ngrams_json_trg
AFTER
DELETE
ON
ngrams
FOR
EACH
ROW
EXECUTE
PROCEDURE
check_ngrams_json
();
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