From fedce11f16d0ea647394ddebc85a36215a3f0ccf Mon Sep 17 00:00:00 2001 From: David Benedeki <14905969+benedeki@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:04:20 +0200 Subject: [PATCH] #2035: PG data model and functions for Dataset (#2054) * #2035: PG data model and functions for Dataset * First commit * * Added check on entity type * * get fucntion * dataset fields * * get comment fixes * * refactored to use id in connection of entities and versions * add function --- database/src/main/dataset/_.ddl | 19 ++ database/src/main/dataset/_add.sql | 138 ++++++++++++++ database/src/main/dataset/add.sql | 159 ++++++++++++++++ database/src/main/dataset/entities.ddl | 32 ++++ database/src/main/dataset/get.sql | 242 +++++++++++++++++++++++++ database/src/main/dataset/list.sql | 51 ++++++ database/src/main/dataset/versions.ddl | 31 ++++ 7 files changed, 672 insertions(+) create mode 100644 database/src/main/dataset/_.ddl create mode 100644 database/src/main/dataset/_add.sql create mode 100644 database/src/main/dataset/add.sql create mode 100644 database/src/main/dataset/entities.ddl create mode 100644 database/src/main/dataset/get.sql create mode 100644 database/src/main/dataset/list.sql create mode 100644 database/src/main/dataset/versions.ddl diff --git a/database/src/main/dataset/_.ddl b/database/src/main/dataset/_.ddl new file mode 100644 index 000000000..0195bd979 --- /dev/null +++ b/database/src/main/dataset/_.ddl @@ -0,0 +1,19 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CREATE SCHEMA IF NOT EXISTS dataset; +ALTER SCHEMA dataset OWNER TO enceladus; + +GRANT USAGE ON SCHEMA dataset TO menas; diff --git a/database/src/main/dataset/_add.sql b/database/src/main/dataset/_add.sql new file mode 100644 index 000000000..546588dec --- /dev/null +++ b/database/src/main/dataset/_add.sql @@ -0,0 +1,138 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CREATE OR REPLACE FUNCTION dataset._add( + IN i_entity_name TEXT, + IN i_entity_version INTEGER, + IN i_entity_description TEXT, + IN i_source_path TEXT, + IN i_publish_path TEXT, + IN i_key_schema BIGINT, + IN i_conformance JSON[], + IN i_user_name TEXT, + OUT status INTEGER, + OUT status_text TEXT, + OUT key_entity_version BIGINT +) RETURNS record AS +$$ +------------------------------------------------------------------------------- +-- +-- Function: jobs_configuration._add(8) +-- Stores a new version of the dataset. +-- +-- Parameters: +-- i_entity_name - name of the dataset +-- i_entity_version - version of the dataset +-- i_entity_description - description of the dataset +-- i_source_path - source path for the dataset +-- i_publish_path - output path for the dataset +-- i_key_schema - reference to the schema of the dataset +-- i_conformance - array of conformance rules +-- i_user_name - the user who submitted the changes +-- +-- Returns: +-- status - Status code +-- status_text - Status text +-- key_entity_version - id of the newly created dataset record +-- +-- Status codes: +-- 11 - OK +-- 31 - Dataset has been disabled +-- 32 - Dataset is locked +-- 50 - Dataset version wrong +-- 51 - Dataset already exists +-- +------------------------------------------------------------------------------- +DECLARE + _entity_type CHAR := 'D'; + _key_entity BIGINT; + _new_entity BOOLEAN; + _latest_version INTEGER; + _locked BOOLEAN; + _disabled BOOLEAN; +BEGIN + IF i_entity_version = 1 THEN + -- lock on stats to prevent competing inserts of new entity + PERFORM 1 + FROM entity_base.stats S + WHERE S.entity_type = _entity_type + FOR UPDATE; + END IF; + + SELECT E.id_entity, E.entity_latest_version, E.locked_at IS NOT NULL, E.disabled_at IS NOT NULL + FROM dataset.entities E + WHERE E.entity_name = i_entity_name + FOR UPDATE + INTO _key_entity, _latest_version, _locked, _disabled; + + _new_entity := NOT found; + + IF _new_entity THEN + IF i_entity_version != 1 THEN + status := 50; + status_text := 'Dataset version wrong'; + RETURN; + END IF; + + UPDATE entity_base.stats + SET entity_count = stats.entity_count + 1 + WHERE entity_type = _entity_type; + + INSERT INTO dataset.entities(entity_name, entity_latest_version, created_by) + VALUES (i_entity_name, i_entity_version, i_user_name) + RETURNING id_entity + INTO _key_entity; + ELSE + IF _disabled THEN + status := 31; + status_text := 'Dataset has been disabled'; + RETURN ; + ELSIF _locked THEN + status := 32; + status_text := 'Dataset is locked'; + RETURN; + ELSIF _latest_version >= i_entity_version THEN + status := 51; + status_text := 'Dataset already exists'; + RETURN; + ELSIF _latest_version + 1 < i_entity_version THEN + status := 50; + status_text := 'Dataset version wrong'; + RETURN; + END IF; + + END IF; + + INSERT INTO dataset.versions(key_entity, entity_version, entity_description, updated_by, + source_path, publish_path, key_schema, conformance) + VALUES (_key_entity, i_entity_version, i_entity_description, i_user_name, + i_source_path, i_publish_path, i_key_schema, i_conformance) + RETURNING dataset.versions.id_entity_version + INTO key_entity_version; + + IF NOT _new_entity THEN + UPDATE dataset.entities + SET entity_latest_version = i_entity_version + WHERE id_entity = _key_entity; + END IF; + + status := 11; + status_text := 'OK'; + RETURN; +END; +$$ +LANGUAGE plpgsql VOLATILE SECURITY DEFINER; + +ALTER FUNCTION dataset._add(TEXT, INTEGER, TEXT, TEXT, TEXT, BIGINT, JSON[], TEXT) OWNER TO enceladus; diff --git a/database/src/main/dataset/add.sql b/database/src/main/dataset/add.sql new file mode 100644 index 000000000..142021463 --- /dev/null +++ b/database/src/main/dataset/add.sql @@ -0,0 +1,159 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CREATE OR REPLACE FUNCTION dataset.add( + IN i_entity_name TEXT, + IN i_entity_version INTEGER, + IN i_entity_description TEXT, + IN i_source_path TEXT, + IN i_publish_path TEXT, + IN i_key_schema BIGINT, + IN i_conformance JSON[], + IN i_user_name TEXT, + OUT status INTEGER, + OUT status_text TEXT, + OUT key_entity_version BIGINT +) RETURNS record AS +$$ +------------------------------------------------------------------------------- +-- +-- Function: jobs_configuration.add(8) +-- Stores a new version of the dataset. +-- The i_entity_version has to be an increment of the latest version of an existing dataset or 1 in the case of a +-- new one +-- +-- Parameters: +-- i_entity_name - name of the dataset +-- i_entity_version - version of the dataset +-- i_entity_description - description of the dataset +-- i_source_path - source path for the dataset +-- i_publish_path - output path for the dataset +-- i_key_schema - reference to the schema of the dataset +-- i_conformance - array of conformance rules +-- i_user_name - the user who submitted the changes +-- +-- Returns: +-- status - Status code +-- status_text - Status text +-- key_entity_version - id of the newly created dataset record +-- +-- Status codes: +-- 11 - OK +-- 31 - Dataset has been disabled +-- 32 - Dataset is locked +-- 42 - Schema does not exists +-- 50 - Dataset version wrong +-- 51 - Dataset already exists +-- +------------------------------------------------------------------------------- +DECLARE +BEGIN + PERFORM 1 + FROM dataset_schema.versions V + WHERE V.id_entity_version = i_key_schema; + + IF NOT found THEN + status := 42; + status_text := 'Schema does not exists'; + RETURN; + END IF; + + SELECT A.status, A.status_text, A.key_entity_version + FROM dataset._add(i_entity_name, i_entity_version, i_entity_description, i_source_path, + i_publish_path, i_key_schema, i_conformance, i_user_name) A + INTO status, status_text, key_entity_version; + + RETURN; +END; +$$ + LANGUAGE plpgsql VOLATILE SECURITY DEFINER; + +ALTER FUNCTION dataset.add(TEXT, INTEGER, TEXT, TEXT, TEXT, BIGINT, JSON[], TEXT) OWNER TO enceladus; +GRANT EXECUTE ON FUNCTION dataset.add(TEXT, INTEGER, TEXT, TEXT, TEXT, BIGINT, JSON[], TEXT) TO menas; + +CREATE OR REPLACE FUNCTION dataset.add( + IN i_entity_name TEXT, + IN i_entity_version INTEGER, + IN i_entity_description TEXT, + IN i_source_path TEXT, + IN i_publish_path TEXT, + IN i_schema_name TEXT, + IN i_schema_version INTEGER, + IN i_conformance JSON[], + IN i_user_name TEXT, + OUT status INTEGER, + OUT status_text TEXT, + OUT key_entity_version BIGINT +) RETURNS record AS +$$ +------------------------------------------------------------------------------- +-- +-- Function: jobs_configuration.add(9) +-- Stores a new version of the mapping table. +-- The i_entity_version has to be an increment of the latest version of an existing dataset or 1 in the case of a +-- new one +-- +-- Parameters: +-- i_entity_name - name of the dataset +-- i_entity_version - version of the dataset +-- i_entity_description - description of the dataset +-- i_source_path - source path for the dataset +-- i_publish_path - output path for the dataset +-- i_schema_name - name of the referenced schema of the dataset +-- i_schema_version - version of the referenced schema of the dataset +-- i_conformance - array of conformance rules +-- i_user_name - the user who submitted the changes +-- +-- Returns: +-- status - Status code +-- status_text - Status text +-- key_entity_version - id of the newly created dataset record +-- +-- Status codes: +-- 11 - OK +-- 31 - Dataset has been disabled +-- 32 - Dataset is locked +-- 42 - Schema does not exists +-- 50 - Dataset version wrong +-- 51 - Dataset already exists +-- +------------------------------------------------------------------------------- +DECLARE + _key_schema BIGINT; +BEGIN + + SELECT G.id_entity_version + FROM dataset_schema.get(i_schema_name, i_schema_version) G + WHERE G.status = 10 + INTO _key_schema; + + IF NOT found THEN + status := 42; + status_text := 'Schema does not exists'; + RETURN; + END IF; + + SELECT A.status, A.status_text, A.key_entity_version + FROM mapping_table._add(i_entity_name, i_entity_version, i_entity_description, i_source_path, + i_publish_path, _key_schema, i_conformance, i_user_name) A + INTO status, status_text, key_entity_version; + + RETURN; +END; +$$ + LANGUAGE plpgsql VOLATILE SECURITY DEFINER; + +ALTER FUNCTION dataset.add(TEXT, INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, JSON[], TEXT) OWNER TO enceladus; +GRANT EXECUTE ON FUNCTION dataset.add(TEXT, INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, JSON[], TEXT) TO menas; diff --git a/database/src/main/dataset/entities.ddl b/database/src/main/dataset/entities.ddl new file mode 100644 index 000000000..757c86d39 --- /dev/null +++ b/database/src/main/dataset/entities.ddl @@ -0,0 +1,32 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- DROP TABLE IF EXISTS dataset.entities; + +CREATE TABLE dataset.entities +( + entity_type CHAR NOT NULL DEFAULT 'D', + CONSTRAINT entities_pk PRIMARY KEY (id_entity) +) + INHERITS (entity_base.entities); + +ALTER TABLE dataset.entities + ADD CONSTRAINT entities_unq UNIQUE (entity_name); + +ALTER TABLE IF EXISTS dataset.entities + ADD CONSTRAINT check_dataset_entity_type CHECK (entity_type = 'D') + NOT VALID; + +ALTER TABLE dataset.entities OWNER to enceladus; diff --git a/database/src/main/dataset/get.sql b/database/src/main/dataset/get.sql new file mode 100644 index 000000000..b524cc92e --- /dev/null +++ b/database/src/main/dataset/get.sql @@ -0,0 +1,242 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CREATE OR REPLACE FUNCTION dataset.get( + IN i_entity_name TEXT, + IN i_entity_version INTEGER DEFAULT NULL, + OUT status INTEGER, + OUT status_text TEXT, + OUT id_entity_version BIGINT, + OUT entity_name TEXT, + OUT entity_version INTEGER, + OUT entity_description TEXT, + OUT created_by TEXT, + OUT created_at TIMESTAMP WITH TIME ZONE, + OUT updated_by TEXT, + OUT updated_at TIMESTAMP WITH TIME ZONE, + OUT locked_by TEXT, + OUT locked_at TIMESTAMP WITH TIME ZONE, + OUT disabled_by TEXT, + OUT disabled_at TIMESTAMP WITH TIME ZONE, + OUT source_path TEXT, + OUT publish_path TEXT, + OUT key_schema BIGINT, + OUT schema_name TEXT, + OUT schema_version INTEGER, + OUT schema_fields JSON, + OUT conformance JSON[] +) RETURNS record AS +$$ +------------------------------------------------------------------------------- +-- +-- Function: jobs_configuration.get(2) +-- Returns the data of the requested dataset, based on its name and version +-- If the version is omitted/NULL the latest version data are returned. +-- +-- Parameters: +-- i_entity_name - name of the dataset +-- i_entity_version - dataset version to return, latest is taken if NULL +-- +-- Returns: +-- status - Status code +-- status_text - Status text +-- id_entity_version - id of the dataset +-- entity_name - name of the dataset +-- entity_version - the version of the dataset +-- entity_description - description of the dataset +-- created_by - user who created the dataset +-- created_at - time & date when the dataset was disabled +-- updated_by - user who updated the dataset to this particular version +-- updated_at - time & date when the this particular version of the dataset was created +-- locked_by - if locked, who was the user who locked the dataset +-- locked_at - if not NULL the dataset is locked +-- disabled_by - if disabled, who was the user who disabled the dataset +-- disabled_at - if not NULL the dataset has been disabled +-- source_path - source path of the dataset +-- publish_path - publish path of the dataset +-- key_schema - id of the attached schema +-- schema_name - name of the schema +-- schema_version - the version of the schema +-- schema_fields - the fields the schema consist of +-- conformance - conformance rules of the dataset +-- +-- Status codes: +-- 10 - OK +-- 40 - Dataset does not exist +-- 42 - Schema not found (Should never happen) +-- 43 - Dataset of the given version does not exist +-- +------------------------------------------------------------------------------- +DECLARE + _key_entity BIGINT; + _entity_version INTEGER; + _schema_status INTEGER; +BEGIN + SELECT E.id_entity, coalesce(i_entity_version, E.entity_latest_version), E.entity_name, + E.created_by, E.created_at, E.locked_by, E.locked_at, + E.disabled_by, E.locked_at + FROM dataset.entities E + WHERE E.entity_name = i_entity_name + INTO _key_entity, _entity_version, get.entity_name, + get.created_by, get.created_at, get.locked_by, get.locked_at, + get.disabled_by, get.disabled_at; + + IF NOT found THEN + status := 40; + status_text := 'Dataset does not exist'; + RETURN; + END IF; + + SELECT 10, 'OK', V.id_entity_version, V.entity_version, + V.entity_description, V.updated_by, V.updated_at, + V.source_path, V.publish_path, V.key_schema, V.conformance + FROM dataset.versions V + WHERE V.key_entity = _key_entity AND + V.entity_version = _entity_version + INTO status, status_text, get.id_entity_version, get.entity_version, + get.entity_description, get.updated_by, get.updated_at, + get.source_path, get.publish_path, get.key_schema, get.conformance; + + IF NOT found THEN + status := 43; + status_text := 'Dataset of the given version does not exist'; + RETURN; + END IF; + + SELECT G.status, G.entity_name, G.entity_version, G.fields + FROM dataset_schema.get(key_schema) G + INTO _schema_status, schema_name, schema_version, schema_fields; + + IF _schema_status != 10 THEN + status := 42; + status_text := 'Schema not found (Should never happen)'; + RETURN; + END IF; + + RETURN; +END; +$$ +LANGUAGE plpgsql VOLATILE SECURITY DEFINER; + + +CREATE OR REPLACE FUNCTION dataset.get( + IN i_key_entity_version BIGINT, + OUT status INTEGER, + OUT status_text TEXT, + OUT id_entity_version BIGINT, + OUT entity_name TEXT, + OUT entity_version INTEGER, + OUT entity_description TEXT, + OUT created_by TEXT, + OUT created_at TIMESTAMP WITH TIME ZONE, + OUT updated_by TEXT, + OUT updated_at TIMESTAMP WITH TIME ZONE, + OUT locked_by TEXT, + OUT locked_at TIMESTAMP WITH TIME ZONE, + OUT disabled_by TEXT, + OUT disabled_at TIMESTAMP WITH TIME ZONE, + OUT source_path TEXT, + OUT publish_path TEXT, + OUT key_schema BIGINT, + OUT schema_name TEXT, + OUT schema_version INTEGER, + OUT schema_fields JSON, + OUT conformance JSON[] +) RETURNS record AS +$$ +------------------------------------------------------------------------------- +-- +-- Function: jobs_configuration.get(1) +-- Returns the data of the requested dataset, based on its id +-- +-- Parameters: +-- i_key_entity_version - id of the dataset +-- +-- Returns: +-- status - Status code +-- status_text - Status text +-- id_entity_version - id of the dataset +-- entity_name - name of the dataset +-- entity_version - the version of the dataset +-- entity_description - description of the dataset +-- created_by - user who created the dataset +-- created_at - time & date when the dataset was disabled +-- updated_by - user who updated the dataset to this particular version +-- updated_at - time & date when the this particular version of the dataset was created +-- locked_by - if locked, who was the user who locked the dataset +-- locked_at - if not NULL the dataset is locked +-- disabled_by - if disabled, who was the user who disabled the dataset +-- disabled_at - if not NULL the dataset has been disabled +-- source_path - source path of the dataset +-- publish_path - publish path of the dataset +-- key_schema - id of the attached schema +-- schema_name - name of the schema +-- schema_version - the version of the schema +-- schema_fields - the fields the schema consist of +-- conformance - conformance rules of the dataset +-- +-- Status codes: +-- 10 - OK +-- 40 - Dataset does not exist +-- 42 - Schema not found (Should never happen) +-- +------------------------------------------------------------------------------- +DECLARE + _key_entity BIGINT; + _schema_status TEXT; +BEGIN + + SELECT 10, 'OK', V.id_entity_version, V.key_entity, V.entity_version, + V.entity_description, V.updated_by, V.updated_at, + V.source_path, V.publish_path, V.key_schema, V.conformance + FROM dataset.versions V + WHERE V.id_entity_version = i_key_entity_version + INTO status, status_text, get.id_entity_version, _key_entity, get.entity_version, + get.entity_description, get.updated_by, get.updated_at, + get.source_path, get.publish_path, get.key_schema, get.conformance; + + IF NOT found THEN + status := 40; + status_text := 'Dataset does not exist'; + RETURN; + END IF; + + + SELECT E.entity_name, E.created_by, E.created_at, + E.locked_by, E.locked_at, E.disabled_by, E.locked_at + FROM dataset.entities E + WHERE E.entity_name = get.entity_name + INTO get.entity_name, get.created_by, get.created_at, + get.locked_by, get.locked_at, get.disabled_by, get.disabled_at; + + SELECT G.status, G.entity_name, G.entity_version, G.fields + FROM dataset_schema.get(key_schema) G + INTO _schema_status, schema_name, schema_version, schema_fields; + + IF _schema_status != 10 THEN + status := 42; + status_text := 'Schema not found (Should never happen)'; + RETURN; + END IF; + + RETURN; +END; +$$ +LANGUAGE plpgsql VOLATILE SECURITY DEFINER; + +ALTER FUNCTION dataset.get(TEXT, INTEGER) OWNER TO enceladus; +ALTER FUNCTION dataset.get(BIGINT) OWNER TO enceladus; +GRANT EXECUTE ON FUNCTION dataset.get(TEXT, INTEGER) TO menas; +GRANT EXECUTE ON FUNCTION dataset.get(BIGINT) TO menas; diff --git a/database/src/main/dataset/list.sql b/database/src/main/dataset/list.sql new file mode 100644 index 000000000..27cb01670 --- /dev/null +++ b/database/src/main/dataset/list.sql @@ -0,0 +1,51 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CREATE OR REPLACE FUNCTION dataset.list( + IN i_include_disabled BOOLEAN DEFAULT FALSE, + OUT entity_name TEXT, + OUT entity_latest_version INTEGER, + OUT locked BOOLEAN, + OUT disabled BOOLEAN +) RETURNS SETOF record AS +$$ +------------------------------------------------------------------------------- +-- +-- Function: dataset.list(1) +-- Returns a list of schemas with their latest versions +-- +-- Parameters: +-- i_include_disabled - flag indicating if to include disabled schemas too +-- +-- Returns: +-- entity_name - name of the schema +-- entity_latest_version - the latest version of the schema +-- locked - signals if the schema is locked or not +-- disabled - signals if the schema is disabled or not +-- +------------------------------------------------------------------------------- +DECLARE +BEGIN + RETURN QUERY + SELECT E.entity_name, E.entity_latest_version, E.disabled_at IS NOT NULL, E.locked_at IS NOT NULL + FROM dataset.entities E + WHERE i_include_disabled OR E.disabled_at IS NULL + ORDER BY entity_name; --TODO Include order by? +END; +$$ +LANGUAGE plpgsql VOLATILE SECURITY DEFINER; + +ALTER FUNCTION dataset.list(BOOLEAN) OWNER TO enceladus; +GRANT EXECUTE ON FUNCTION dataset.list(BOOLEAN) TO menas; diff --git a/database/src/main/dataset/versions.ddl b/database/src/main/dataset/versions.ddl new file mode 100644 index 000000000..ab929b600 --- /dev/null +++ b/database/src/main/dataset/versions.ddl @@ -0,0 +1,31 @@ +/* + * Copyright 2018 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- DROP TABLE IF EXISTS dataset.versions; + +CREATE TABLE dataset.versions +( + source_path TEXT NOT NULL, + publish_path TEXT NOT NULL, + key_schema BIGINT NOT NULL, + conformance JSON[] NOT NULL, + CONSTRAINT versions_pk PRIMARY KEY (id_entity_version) +) + INHERITS (entity_base.versions); + +ALTER TABLE dataset.versions + ADD CONSTRAINT versions_unq UNIQUE (key_entity, entity_version); + +ALTER TABLE dataset.versions OWNER to enceladus;