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/entities.ddl b/database/src/main/dataset/entities.ddl new file mode 100644 index 000000000..473847250 --- /dev/null +++ b/database/src/main/dataset/entities.ddl @@ -0,0 +1,29 @@ +/* + * 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 (entity_name) +) + INHERITS (entity_base.entities); + +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/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..71fc72c68 --- /dev/null +++ b/database/src/main/dataset/versions.ddl @@ -0,0 +1,29 @@ +/* + * 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, + publish_path TEXT, + CONSTRAINT versions_pk PRIMARY KEY (id_entity_version) +) + INHERITS (entity_base.versions); + +ALTER TABLE dataset.versions + ADD CONSTRAINT versions_unq UNIQUE (entity_name, entity_version); + +ALTER TABLE dataset.versions OWNER to enceladus;