Compatibility with mariadb 10.x and mysql 8.x
[policy/xacml-pdp.git] / packages / policy-xacmlpdp-tarball / src / main / resources / mysql / sql / createguardtable.sql
1 -- ============LICENSE_START=======================================================
2 -- Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
3 -- ================================================================================
4 -- Licensed under the Apache License, Version 2.0 (the "License");
5 -- you may not use this file except in compliance with the License.
6 -- You may obtain a copy of the License at
7 --
8 --      http://www.apache.org/licenses/LICENSE-2.0
9 --
10 -- Unless required by applicable law or agreed to in writing, software
11 -- distributed under the License is distributed on an "AS IS" BASIS,
12 -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- See the License for the specific language governing permissions and
14 -- limitations under the License.
15 -- ============LICENSE_END=========================================================
16
17 USE operationshistory;
18
19 CREATE TABLE IF NOT EXISTS operationshistory (
20     id INT(11) NOT NULL AUTO_INCREMENT,
21     closedLoopName VARCHAR(255) NOT NULL,
22     requestId VARCHAR(50),
23     actor VARCHAR(50) NOT NULL,
24     operation VARCHAR(50) NOT NULL,
25     target VARCHAR(50) NOT NULL,
26     starttime timestamp NOT NULL,
27     outcome VARCHAR(50) NOT NULL,
28     message VARCHAR(255),
29     subrequestId VARCHAR(50),
30     endtime timestamp NULL DEFAULT current_timestamp,
31     PRIMARY KEY (id)
32 );
33
34 DROP PROCEDURE IF EXISTS create_clreqid_index;
35
36 \d $$
37 CREATE PROCEDURE create_clreqid_index()
38 BEGIN
39     DECLARE index_count INT DEFAULT 1;
40
41     SELECT count(index_name) INTO index_count FROM information_schema.statistics
42     WHERE table_schema=DATABASE() AND table_name='operationshistory' AND index_name='operationshistory_clreqid_index';
43
44     IF index_count = 0 THEN
45         CREATE INDEX operationshistory_clreqid_index ON operationshistory(requestId, closedLoopName);
46     END IF;
47 END
48 $$
49
50 \d ;
51
52 CALL create_clreqid_index();
53
54 DROP PROCEDURE IF EXISTS create_target_index;
55
56 \d $$
57 CREATE PROCEDURE create_target_index()
58 BEGIN
59     DECLARE index_count INT DEFAULT 1;
60
61     SELECT count(index_name) INTO index_count FROM information_schema.statistics
62     WHERE table_schema=DATABASE() AND table_name='operationshistory' AND index_name='operationshistory_target_index';
63
64     IF index_count = 0 THEN
65         CREATE INDEX operationshistory_target_index ON operationshistory(target, operation, actor, endtime);
66     END IF;
67 END
68 $$
69
70 CALL create_target_index();
71 \d ;