Commit 61af47c9 authored by Valentin Suhnjov's avatar Valentin Suhnjov

Merge branch 'releases/release-0.10.0' into master

parents 953236b7 be489c2b
Pipeline #43 failed with stages
image: riha-test-env
variables:
DEPLOYMENT_DIR: "/opt/tomcat/webapps"
ARTIFACT_NAME: "$CI_PROJECT_NAME.war"
stages:
- test
- build
- deploy
# Tests are failing. Commented for now
# test:
# stage: test
# script:
# - mvn clean test
# tags:
# - riha
build:
stage: build
script:
......@@ -36,8 +26,7 @@ deploy_development:
- echo "$SSH_HOST_KEY" > $HOME/.ssh/known_hosts
- scp -i id_rsa target/*.war deployer@$SSH_HOST:$DEPLOYMENT_DIR/$ARTIFACT_NAME
environment:
name: development
url: http://$SSH_HOST:$PORT/
name: demo
when: manual
tags:
- riha
\ No newline at end of file
This diff is collapsed.
-- Extensions
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- Sequence: riha.comment_seq
-- DROP SEQUENCE riha.comment_seq;
......@@ -135,6 +138,7 @@ CREATE TABLE riha.main_resource
field_name character varying(150),
kind_id integer, -- Ressursi liik (infosystem, classifier, service, dictionary, xmlresource vms.).
main_resource_template_id integer,
search_content text, -- Indexed full text search column.
CONSTRAINT pk_main_resource PRIMARY KEY (main_resource_id),
CONSTRAINT fk_main_resource_main_resource_02 FOREIGN KEY (main_resource_template_id)
REFERENCES riha.main_resource (main_resource_id) MATCH SIMPLE
......@@ -163,6 +167,7 @@ COMMENT ON COLUMN riha.main_resource.modifier IS 'Viimati kirjet muutnud isiku i
COMMENT ON COLUMN riha.main_resource.creation_date IS 'Kirje loomise ajahetk.';
COMMENT ON COLUMN riha.main_resource.modified_date IS 'Kirje viimati muutmise ajahetk.';
COMMENT ON COLUMN riha.main_resource.kind_id IS 'Ressursi liik (infosystem, classifier, service, dictionary, xmlresource vms.).';
COMMENT ON COLUMN riha.main_resource.search_content IS 'Indexed full text search column.';
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.main_resource TO riha;
......@@ -196,6 +201,13 @@ CREATE INDEX ixfk_main_resource_kind_template
USING btree
(main_resource_template_id);
-- DROP INDEX IF EXISTS idx_main_resource_search;
CREATE INDEX idx_main_resource_search
ON riha.main_resource
USING GIN (search_content gin_trgm_ops);
-- Table: riha.data_object
......
This diff is collapsed.
-- DROP VIEW riha.main_resource_relation_view;
DROP VIEW IF EXISTS riha.main_resource_view CASCADE;
CREATE OR REPLACE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid')
*,
......@@ -9,8 +9,7 @@ CREATE OR REPLACE VIEW riha.main_resource_view AS
j_update_timestamp DESC NULLS LAST,
main_resource_id DESC;
-- DROP VIEW riha.main_resource_relation_view;
DROP VIEW IF EXISTS riha.main_resource_relation_view;
CREATE OR REPLACE VIEW riha.main_resource_relation_view AS
SELECT
mrr.*,
......
-- Index: riha.ixfk_comment_comment
DROP INDEX IF EXISTS riha.ixfk_comment_comment;
DROP TABLE IF EXISTS riha.comment;
DROP INDEX riha.ixfk_comment_comment;
DROP TABLE IF EXISTS riha.document;
-- Table: riha.comment
DROP INDEX IF EXISTS riha.ixfk_data_object_main_resource;
DROP INDEX IF EXISTS riha.ixfk_data_object_data_object;
DROP TABLE IF EXISTS riha.data_object;
DROP TABLE riha.comment;
DROP VIEW IF EXISTS riha.main_resource_relation_view;
DROP FUNCTION IF EXISTS riha.update_main_resource_search_content();
DROP FUNCTION IF EXISTS riha.main_resource_search_content( JSONB );
DROP INDEX IF EXISTS riha.idx_main_resource_relation_infosystem_uuid;
DROP INDEX IF EXISTS riha.idx_main_resource_relation_related_infosystem_uuid;
DROP TABLE IF EXISTS riha.main_resource_relation;
-- Table: riha.document
DROP VIEW IF EXISTS riha.main_resource_view;
DROP INDEX IF EXISTS riha.ixfk_main_resource_kind_template;
DROP INDEX IF EXISTS riha.ixfk_main_resource_kind;
DROP INDEX IF EXISTS riha.ixfk_main_resource_main_resource;
DROP TABLE IF EXISTS riha.main_resource;
DROP TABLE riha.document;
DROP TABLE IF EXISTS riha.kind;
-- Index: riha.ixfk_data_object_main_resource
DROP TABLE IF EXISTS riha.file_resource;
DROP INDEX riha.ixfk_data_object_main_resource;
DROP TABLE IF EXISTS riha.large_object;
-- Index: riha.ixfk_data_object_data_object
DROP INDEX riha.ixfk_data_object_data_object;
-- Table: riha.data_object
DROP TABLE riha.data_object;
-- Table: riha.main_resource_relation
DROP INDEX riha.idx_main_resource_relation_infosystem_uuid;
DROP INDEX riha.idx_main_resource_relation_related_infosystem_uuid;
DROP TABLE riha.main_resource_relation;
-- Index: riha.ixfk_main_resource_kind_template
DROP INDEX riha.ixfk_main_resource_kind_template;
-- Index: riha.ixfk_main_resource_kind
DROP INDEX riha.ixfk_main_resource_kind;
-- Index: riha.ixfk_main_resource_main_resource
DROP INDEX riha.ixfk_main_resource_main_resource;
-- Table: riha.main_resource
DROP TABLE riha.main_resource;
-- Table: riha.kind
DROP TABLE riha.kind;
-- Table: riha.file_resource
DROP TABLE riha.file_resource;
-- Table: riha.large_object
DROP TABLE riha.large_object;
-- Sequence: riha.comment_seq
DROP SEQUENCE riha.comment_seq;
-- Sequence: riha.data_object_seq
DROP SEQUENCE riha.data_object_seq;
-- Sequence: riha.document_seq
DROP SEQUENCE riha.document_seq;
-- Sequence: riha.kind_seq
DROP SEQUENCE riha.kind_seq;
-- Sequence: riha.main_resource_seq
DROP SEQUENCE riha.main_resource_seq;
-- Sequence: riha.main_resource_relation_seq
DROP SEQUENCE riha.main_resource_relation_seq;
\ No newline at end of file
DROP SEQUENCE IF EXISTS riha.comment_seq;
DROP SEQUENCE IF EXISTS riha.data_object_seq;
DROP SEQUENCE IF EXISTS riha.document_seq;
DROP SEQUENCE IF EXISTS riha.kind_seq;
DROP SEQUENCE IF EXISTS riha.main_resource_seq;
DROP SEQUENCE IF EXISTS riha.main_resource_relation_seq;
DROP SEQUENCE IF EXISTS riha.large_object_seq;
\ No newline at end of file
-- enable trigram extension
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- add full text search column
ALTER TABLE riha.main_resource
ADD COLUMN search_content TEXT;
-- recreate views
DROP VIEW IF EXISTS riha.main_resource_view CASCADE;
CREATE OR REPLACE VIEW riha.main_resource_view AS
SELECT DISTINCT ON (json_content ->> 'uuid')
*,
((main_resource.json_content #>> '{meta,creation_timestamp}' :: TEXT [])) :: TIMESTAMP AS j_creation_timestamp,
((main_resource.json_content #>> '{meta,update_timestamp}' :: TEXT [])) :: TIMESTAMP AS j_update_timestamp
FROM riha.main_resource AS main_resource
ORDER BY json_content ->> 'uuid',
j_update_timestamp DESC NULLS LAST,
main_resource_id DESC;
DROP VIEW IF EXISTS riha.main_resource_relation_view;
CREATE OR REPLACE VIEW riha.main_resource_relation_view AS
SELECT
mrr.*,
infosystem.json_content ->> 'short_name' AS infosystem_short_name,
infosystem.json_content ->> 'name' AS infosystem_name,
related_infosystem.json_content ->> 'short_name' AS related_infosystem_short_name,
related_infosystem.json_content ->> 'name' AS related_infosystem_name
FROM riha.main_resource_relation mrr
LEFT JOIN riha.main_resource_view infosystem ON (infosystem.json_content ->> 'uuid') = mrr.infosystem_uuid :: TEXT
LEFT JOIN riha.main_resource_view related_infosystem
ON (related_infosystem.json_content ->> 'uuid') = mrr.related_infosystem_uuid :: TEXT;
-- create function that picks data from json
DROP FUNCTION IF EXISTS riha.main_resource_search_content();
CREATE OR REPLACE FUNCTION riha.main_resource_search_content(json_content JSONB)
RETURNS TEXT AS $$
SELECT concat_ws(' ',
json_content #>> '{name}',
json_content #>> '{short_name}',
json_content #>> '{owner,code}',
json_content #>> '{owner,name}',
json_content #>> '{purpose}',
json_content #>> '{homepage}',
(SELECT string_agg(value, ' ')
FROM jsonb_array_elements_text(nullif(jsonb_extract_path(json_content, 'topics'), 'null'))),
(SELECT string_agg(value, ' ')
FROM jsonb_array_elements_text(nullif(jsonb_extract_path(json_content, 'stored_data'), 'null'))),
(SELECT string_agg(value ->> 'name', ' ')
FROM jsonb_array_elements(nullif(jsonb_extract_path(json_content, 'data_files'), 'null'))),
(SELECT string_agg(value ->> 'url', ' ')
FROM jsonb_array_elements(nullif(jsonb_extract_path(json_content, 'data_files'), 'null'))
WHERE value ->> 'url' NOT ILIKE 'file://%'),
(SELECT string_agg(value ->> 'name', ' ')
FROM jsonb_array_elements(nullif(jsonb_extract_path(json_content, 'documents'), 'null'))),
(SELECT string_agg(value ->> 'url', ' ')
FROM jsonb_array_elements(nullif(jsonb_extract_path(json_content, 'documents'), 'null'))
WHERE value ->> 'url' NOT ILIKE 'file://%'),
(SELECT string_agg(value ->> 'name', ' ')
FROM jsonb_array_elements(nullif(jsonb_extract_path(json_content, 'legislations'), 'null'))),
(SELECT string_agg(value ->> 'url', ' ')
FROM jsonb_array_elements(nullif(jsonb_extract_path(json_content, 'legislations'), 'null')))
);
$$ LANGUAGE SQL
IMMUTABLE;
-- add trigger to update full text search column data
DROP FUNCTION IF EXISTS riha.update_main_resource_search_content() CASCADE;
CREATE OR REPLACE FUNCTION riha.update_main_resource_search_content()
RETURNS TRIGGER AS $$
BEGIN
new.search_content = riha.main_resource_search_content(new.json_content);
RETURN new;
END
$$ LANGUAGE plpgsql
IMMUTABLE;
DROP TRIGGER IF EXISTS update_search_content
ON riha.main_resource;
CREATE TRIGGER update_search_content
BEFORE INSERT OR UPDATE
ON riha.main_resource
FOR EACH ROW EXECUTE PROCEDURE riha.update_main_resource_search_content();
-- update table
UPDATE riha.main_resource
SET search_content = riha.main_resource_search_content(json_content);
-- add index on full text search column
DROP INDEX IF EXISTS idx_main_resource_search;
CREATE INDEX idx_main_resource_search
ON riha.main_resource
USING GIN (search_content gin_trgm_ops);
\ No newline at end of file
......@@ -81,6 +81,9 @@ public class Main_resource implements BaseModel {
private Integer kind_id;
// Needed for indication that this field should not be searched in json content
private String search_content;
/*
* (non-Javadoc)
*
......
......@@ -48,6 +48,9 @@ public class Main_resource_view implements BaseModel {
private String kind;
// Needed for indication that this field should not be searched in json content
private String search_content;
@Column(name = "j_creation_timestamp")
private Date j_creation_timestamp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment