diff --git a/docker-compose/timescaledb/Dockerfile b/docker-compose/timescaledb/Dockerfile index 88e81b1ba2a3ffbb98f1016cfdcdfc255daec575..14e828d6453495b5c445d6d48040c58dbae0b24c 100644 --- a/docker-compose/timescaledb/Dockerfile +++ b/docker-compose/timescaledb/Dockerfile @@ -4,22 +4,23 @@ FROM timescale/timescaledb:latest-pg12 COPY resources/01_admin.sh docker-entrypoint-initdb.d/002_admin.sh # Create DB schema (tables, indexes, etc.) COPY resources/02_hdb_schema.sql docker-entrypoint-initdb.d/003_hdb_schema.sql +COPY resources/03_hdb_images docker-entrypoint-initdb.d/004_hdb_images.sql # Create DB roles -COPY resources/03_hdb_roles.sql docker-entrypoint-initdb.d/004_hdb_roles.sql +COPY resources/04_hdb_roles.sql docker-entrypoint-initdb.d/005_hdb_roles.sql # Create further roles -COPY resources/04_hdb_ext_users.sql docker-entrypoint-initdb.d/005_hdb_ext_users.sql +COPY resources/05_hdb_ext_users.sql docker-entrypoint-initdb.d/006_hdb_ext_users.sql # Add further functions -COPY resources/05_hdb_ext_import.sql docker-entrypoint-initdb.d/006_hdb_ext_import.sql +COPY resources/06_hdb_ext_import.sql docker-entrypoint-initdb.d/007_hdb_ext_import.sql # Create timescaledb aggregates -COPY resources/06_hdb_ext_aggregates.sql docker-entrypoint-initdb.d/007_hdb_ext_aggregates.sql -COPY resources/07_hdb_ext_arrays_aggregates_helper.sql docker-entrypoint-initdb.d/008_hdb_ext_arrays_aggregates_helper.sql -COPY resources/08_hdb_ext_arrays_aggregates.sql docker-entrypoint-initdb.d/009_hdb_ext_arrays_aggregates.sql +COPY resources/07_hdb_ext_aggregates.sql docker-entrypoint-initdb.d/008_hdb_ext_aggregates.sql +COPY resources/08_hdb_ext_arrays_aggregates_helper.sql docker-entrypoint-initdb.d/009_hdb_ext_arrays_aggregates_helper.sql +COPY resources/09_hdb_ext_arrays_aggregates.sql docker-entrypoint-initdb.d/010_hdb_ext_arrays_aggregates.sql # Add compress policy -COPY resources/09_hdb_ext_compress_policy.sql docker-entrypoint-initdb.d/010_hdb_ext_compress_policy.sql +COPY resources/10_hdb_ext_compress_policy.sql docker-entrypoint-initdb.d/011_hdb_ext_compress_policy.sql # Add reorder policy -COPY resources/10_hdb_ext_reorder_policy.sql docker-entrypoint-initdb.d/011_hdb_ext_reorder_policy.sql +COPY resources/11_hdb_ext_reorder_policy.sql docker-entrypoint-initdb.d/012_hdb_ext_reorder_policy.sql # Add LOFAR functions and views -COPY resources/11_lofar_func.sh docker-entrypoint-initdb.d/012_lofar_func.sh -COPY resources/12_lofar_views.sql docker-entrypoint-initdb.d/013_lofar_views.sql +COPY resources/12_lofar_func.sh docker-entrypoint-initdb.d/013_lofar_func.sh +COPY resources/13_lofar_views.sql docker-entrypoint-initdb.d/014_lofar_views.sql # Cleanup admin role -COPY resources/13_cleanup.sql docker-entrypoint-initdb.d/014_cleanup.sql +COPY resources/14_cleanup.sql docker-entrypoint-initdb.d/015_cleanup.sql diff --git a/docker-compose/timescaledb/resources/03_hdb_images.sql b/docker-compose/timescaledb/resources/03_hdb_images.sql new file mode 100644 index 0000000000000000000000000000000000000000..7ad8a0e27f4f0f9e8e37a4e6adb740b852ef364f --- /dev/null +++ b/docker-compose/timescaledb/resources/03_hdb_images.sql @@ -0,0 +1,296 @@ +-- ----------------------------------------------------------------------------- +-- This file is part of the hdbpp-timescale-project +-- +-- Copyright (C) : 2014-2019 +-- European Synchrotron Radiation Facility +-- BP 220, Grenoble 38043, FRANCE +-- +-- libhdb++timescale is free software: you can redistribute it and/or modify +-- it under the terms of the Lesser GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- libhdb++timescale is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser +-- GNU General Public License for more details. +-- +-- You should have received a copy of the Lesser GNU General Public License +-- along with libhdb++timescale. If not, see <http://www.gnu.org/licenses/>. +-- ----------------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS att_image_devboolean ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r boolean[][], + value_w boolean[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devboolean IS 'Array Boolean Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devboolean_att_conf_id_idx ON att_array_devboolean (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devboolean_att_conf_id_data_time_idx ON att_array_devboolean (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devboolean', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devuchar ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r uchar[][], + value_w uchar[][], + quality smallint, + details json, + att_error_desc_id integer, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devuchar IS 'Array UChar Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devuchar_att_conf_id_idx ON att_array_devuchar (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devuchar_att_conf_id_data_time_idx ON att_array_devuchar (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devuchar', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devshort ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r smallint[][], + value_w smallint[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devshort IS 'Array Short Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devshort_att_conf_id_idx ON att_array_devshort (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devshort_att_conf_id_data_time_idx ON att_array_devshort (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devshort', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devushort ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r ushort[][], + value_w ushort[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devushort IS 'Array UShort Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devushort_att_conf_id_idx ON att_array_devushort (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devushort_att_conf_id_data_time_idx ON att_array_devushort (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devushort', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devlong ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r integer[][], + value_w integer[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devlong IS 'Array Long Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devlong_att_conf_id_idx ON att_array_devlong (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devlong_att_conf_id_data_time_idx ON att_array_devlong (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devlong', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devulong ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r ulong[][], + value_w ulong[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devulong IS 'Array ULong Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devulong_att_conf_id_idx ON att_array_devulong (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devulong_att_conf_id_data_time_idx ON att_array_devulong (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devulong', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devlong64 ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r bigint[][], + value_w bigint[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devlong64 IS 'Array Long64 Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devlong64_att_conf_id_idx ON att_array_devlong64 (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devlong64_att_conf_id_data_time_idx ON att_array_devlong64 (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devlong64', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devulong64 ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r ulong64[][], + value_w ulong64[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devulong64 IS 'Array ULong64 Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devulong64_att_conf_id_idx ON att_array_devulong64 (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devulong64_att_conf_id_data_time_idx ON att_array_devulong64 (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devulong64', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devfloat ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r real[][], + value_w real[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devfloat IS 'Array Float Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devfloat_att_conf_id_idx ON att_array_devfloat (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devfloat_att_conf_id_data_time_idx ON att_array_devfloat (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devfloat', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devdouble ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r double precision[][], + value_w double precision[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devdouble IS 'Array Double Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devdouble_att_conf_id_idx ON att_array_devdouble (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devdouble_att_conf_id_data_time_idx ON att_array_devdouble (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devdouble', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devstring ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r text[][], + value_w text[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devstring IS 'Array String Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devstring_att_conf_id_idx ON att_array_devstring (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devstring_att_conf_id_data_time_idx ON att_array_devstring (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devstring', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devstate ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r integer[][], + value_w integer[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devstate IS 'Array State Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devstate_att_conf_id_idx ON att_array_devstate (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devstate_att_conf_id_data_time_idx ON att_array_devstate (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devstate', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devencoded ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r bytea[][], + value_w bytea[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); +COMMENT ON TABLE att_image_devencoded IS 'Array DevEncoded Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devencoded_att_conf_id_idx ON att_array_devencoded (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devencoded_att_conf_id_data_time_idx ON att_array_devencoded (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devencoded', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +CREATE TABLE IF NOT EXISTS att_image_devenum ( + att_conf_id integer NOT NULL, + data_time timestamp WITH TIME ZONE NOT NULL, + value_r_label text[][], + value_r smallint[][], + value_w_label text[][], + value_w smallint[][], + quality smallint, + att_error_desc_id integer, + details json, + PRIMARY KEY (att_conf_id, data_time), + FOREIGN KEY (att_conf_id) REFERENCES att_conf (att_conf_id), + FOREIGN KEY (att_error_desc_id) REFERENCES att_error_desc (att_error_desc_id) +); + +COMMENT ON TABLE att_image_devenum IS 'Array Enum Values Table'; +CREATE INDEX IF NOT EXISTS att_image_devenum_att_conf_id_idx ON att_array_devenum (att_conf_id); +CREATE INDEX IF NOT EXISTS att_image_devenum_att_conf_id_data_time_idx ON att_array_devenum (att_conf_id,data_time DESC); +SELECT create_hypertable('att_image_devenum', 'data_time', chunk_time_interval => interval '28 day', create_default_indexes => FALSE); + +-- Trigger to set the enum_labels +CREATE OR REPLACE FUNCTION set_enum_label_array() RETURNS TRIGGER AS $$ +DECLARE +BEGIN + IF NEW.value_r IS NOT NULL THEN + WITH enum_labels AS ( + SELECT enum_labels FROM att_parameter WHERE att_conf_id=NEW.att_conf_id ORDER BY recv_time DESC limit 1 + ) + SELECT array_agg(res) FROM (SELECT enum_labels[UNNEST(NEW.value_r)+ 1] FROM enum_labels) as res INTO NEW.value_r_label; + END IF; + IF NEW.value_w IS NOT NULL THEN + WITH enum_labels AS ( + SELECT enum_labels FROM att_parameter WHERE att_conf_id=NEW.att_conf_id ORDER BY recv_time DESC limit 1 + ) + SELECT array_agg(res) FROM (SELECT enum_labels[UNNEST(NEW.value_w)+ 1] FROM enum_labels) as res INTO NEW.value_w_label; + END IF; + RETURN NEW; +END +$$ LANGUAGE plpgsql; + +CREATE TRIGGER enum_label_trigger BEFORE INSERT ON att_image_devenum FOR EACH ROW EXECUTE PROCEDURE set_enum_label_array(); + diff --git a/docker-compose/timescaledb/resources/03_hdb_roles.sql b/docker-compose/timescaledb/resources/04_hdb_roles.sql similarity index 100% rename from docker-compose/timescaledb/resources/03_hdb_roles.sql rename to docker-compose/timescaledb/resources/04_hdb_roles.sql diff --git a/docker-compose/timescaledb/resources/04_hdb_ext_users.sql b/docker-compose/timescaledb/resources/05_hdb_ext_users.sql similarity index 100% rename from docker-compose/timescaledb/resources/04_hdb_ext_users.sql rename to docker-compose/timescaledb/resources/05_hdb_ext_users.sql diff --git a/docker-compose/timescaledb/resources/05_hdb_ext_import.sql b/docker-compose/timescaledb/resources/06_hdb_ext_import.sql similarity index 100% rename from docker-compose/timescaledb/resources/05_hdb_ext_import.sql rename to docker-compose/timescaledb/resources/06_hdb_ext_import.sql diff --git a/docker-compose/timescaledb/resources/06_hdb_ext_aggregates.sql b/docker-compose/timescaledb/resources/07_hdb_ext_aggregates.sql similarity index 100% rename from docker-compose/timescaledb/resources/06_hdb_ext_aggregates.sql rename to docker-compose/timescaledb/resources/07_hdb_ext_aggregates.sql diff --git a/docker-compose/timescaledb/resources/07_hdb_ext_arrays_aggregates_helper.sql b/docker-compose/timescaledb/resources/08_hdb_ext_arrays_aggregates_helper.sql similarity index 100% rename from docker-compose/timescaledb/resources/07_hdb_ext_arrays_aggregates_helper.sql rename to docker-compose/timescaledb/resources/08_hdb_ext_arrays_aggregates_helper.sql diff --git a/docker-compose/timescaledb/resources/08_hdb_ext_arrays_aggregates.sql b/docker-compose/timescaledb/resources/09_hdb_ext_arrays_aggregates.sql similarity index 100% rename from docker-compose/timescaledb/resources/08_hdb_ext_arrays_aggregates.sql rename to docker-compose/timescaledb/resources/09_hdb_ext_arrays_aggregates.sql diff --git a/docker-compose/timescaledb/resources/09_hdb_ext_compress_policy.sql b/docker-compose/timescaledb/resources/10_hdb_ext_compress_policy.sql similarity index 100% rename from docker-compose/timescaledb/resources/09_hdb_ext_compress_policy.sql rename to docker-compose/timescaledb/resources/10_hdb_ext_compress_policy.sql diff --git a/docker-compose/timescaledb/resources/10_hdb_ext_reorder_policy.sql b/docker-compose/timescaledb/resources/11_hdb_ext_reorder_policy.sql similarity index 100% rename from docker-compose/timescaledb/resources/10_hdb_ext_reorder_policy.sql rename to docker-compose/timescaledb/resources/11_hdb_ext_reorder_policy.sql diff --git a/docker-compose/timescaledb/resources/11_lofar_func.sh b/docker-compose/timescaledb/resources/12_lofar_func.sh similarity index 100% rename from docker-compose/timescaledb/resources/11_lofar_func.sh rename to docker-compose/timescaledb/resources/12_lofar_func.sh diff --git a/docker-compose/timescaledb/resources/12_lofar_views.sql b/docker-compose/timescaledb/resources/13_lofar_views.sql similarity index 100% rename from docker-compose/timescaledb/resources/12_lofar_views.sql rename to docker-compose/timescaledb/resources/13_lofar_views.sql diff --git a/docker-compose/timescaledb/resources/13_cleanup.sql b/docker-compose/timescaledb/resources/14_cleanup.sql similarity index 100% rename from docker-compose/timescaledb/resources/13_cleanup.sql rename to docker-compose/timescaledb/resources/14_cleanup.sql