-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2035: PG data model and functions for Dataset
* First commit
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |