diff --git a/security-admin/db/mysql/patches/074-create-index-for-x_trx_log.sql b/security-admin/db/mysql/patches/074-create-index-for-x_trx_log.sql index 9a8f3c0d2d..9b65ebb1b0 100644 --- a/security-admin/db/mysql/patches/074-create-index-for-x_trx_log.sql +++ b/security-admin/db/mysql/patches/074-create-index-for-x_trx_log.sql @@ -17,9 +17,11 @@ drop procedure if exists create_index_for_x_trx_log; delimiter ;; create procedure create_index_for_x_trx_log() begin -if not exists (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='x_trx_log' AND index_name='x_trx_log_IDX_trx_id') then - CREATE INDEX x_trx_log_IDX_trx_id ON x_trx_log(trx_id); - end if; +if exists (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='x_trx_log') then + if not exists (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='x_trx_log' AND index_name='x_trx_log_IDX_trx_id') then + CREATE INDEX x_trx_log_IDX_trx_id ON x_trx_log(trx_id); + end if; +end if; end;; delimiter ; diff --git a/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql b/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql index 551660ab40..ed6d20b3d3 100644 --- a/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql +++ b/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql @@ -1987,8 +1987,8 @@ INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,act INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '060',sys_extract_utc(systimestamp),'Ranger 1.0.0',sys_extract_utc(systimestamp),'localhost','Y'); INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '065',sys_extract_utc(systimestamp),'Ranger 1.0.0',sys_extract_utc(systimestamp),'localhost','Y'); INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '066',sys_extract_utc(systimestamp),'Ranger 3.0.0',sys_extract_utc(systimestamp),'localhost','Y'); -INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '067',sys_extract_utc(systimestamp),'Ranger 3.0.0',sys_extract_utc(systimestamp),'localhost','Y'); -INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '068',sys_extract_utc(systimestamp),'Ranger 3.0.0',sys_extract_utc(systimestamp),'localhost','Y'); +INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '073',sys_extract_utc(systimestamp),'Ranger 3.0.0',sys_extract_utc(systimestamp),'localhost','Y'); +INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, '074',sys_extract_utc(systimestamp),'Ranger 3.0.0',sys_extract_utc(systimestamp),'localhost','Y'); INSERT INTO x_db_version_h (id,version,inst_at,inst_by,updated_at,updated_by,active) VALUES (X_DB_VERSION_H_SEQ.nextval, 'DB_PATCHES',sys_extract_utc(systimestamp),'Ranger 1.0.0',sys_extract_utc(systimestamp),'localhost','Y'); INSERT INTO x_user_module_perm (id,user_id,module_id,create_time,update_time,added_by_id,upd_by_id,is_allowed) VALUES (X_USER_MODULE_PERM_SEQ.nextval,getXportalUIdByLoginId('admin'),getModulesIdByName('Reports'),sys_extract_utc(systimestamp),sys_extract_utc(systimestamp),getXportalUIdByLoginId('admin'),getXportalUIdByLoginId('admin'),1); diff --git a/security-admin/db/oracle/patches/067-create-x_trx_log_v2.sql b/security-admin/db/oracle/patches/073-create-x_trx_log_v2.sql similarity index 100% rename from security-admin/db/oracle/patches/067-create-x_trx_log_v2.sql rename to security-admin/db/oracle/patches/073-create-x_trx_log_v2.sql diff --git a/security-admin/db/oracle/patches/068-create-index-for-x_trx_log.sql b/security-admin/db/oracle/patches/074-create-index-for-x_trx_log.sql similarity index 67% rename from security-admin/db/oracle/patches/068-create-index-for-x_trx_log.sql rename to security-admin/db/oracle/patches/074-create-index-for-x_trx_log.sql index 1ef726b539..5a813f091f 100644 --- a/security-admin/db/oracle/patches/068-create-index-for-x_trx_log.sql +++ b/security-admin/db/oracle/patches/074-create-index-for-x_trx_log.sql @@ -16,10 +16,14 @@ DECLARE v_index_exists number:=0; + v_table_exists number := 0; BEGIN - SELECT COUNT(*) INTO v_index_exists FROM USER_INDEXES WHERE INDEX_NAME = upper('x_trx_log_IDX_trx_id') AND TABLE_NAME= upper('x_trx_log'); - IF (v_index_exists = 0) THEN - execute IMMEDIATE 'CREATE INDEX x_trx_log_IDX_trx_id ON x_trx_log(trx_id)'; - commit; + SELECT COUNT(*) INTO v_table_exists FROM USER_TABLES WHERE TABLE_NAME = upper('x_trx_log'); + IF (v_table_exists > 0) THEN + SELECT COUNT(*) INTO v_index_exists FROM USER_INDEXES WHERE INDEX_NAME = upper('x_trx_log_IDX_trx_id') AND TABLE_NAME= upper('x_trx_log'); + IF (v_index_exists = 0) THEN + execute IMMEDIATE 'CREATE INDEX x_trx_log_IDX_trx_id ON x_trx_log(trx_id)'; + commit; + END IF; END IF; END;/ diff --git a/security-admin/db/postgres/patches/074-create-index-for-x_trx_log.sql b/security-admin/db/postgres/patches/074-create-index-for-x_trx_log.sql index 34cf77ccc0..2e6352a915 100644 --- a/security-admin/db/postgres/patches/074-create-index-for-x_trx_log.sql +++ b/security-admin/db/postgres/patches/074-create-index-for-x_trx_log.sql @@ -18,11 +18,15 @@ CREATE OR REPLACE FUNCTION create_index_for_x_trx_log() RETURNS void AS $$ DECLARE v_attnum1 integer := 0; + v_table_exists integer := 0; BEGIN - select attnum into v_attnum1 from pg_attribute where attrelid in(select oid from pg_class where relname='x_trx_log') and attname in('trx_id'); - IF v_attnum1 > 0 THEN - IF not exists (select * from pg_index where indrelid in(select oid from pg_class where relname='x_trx_log') and indkey[0]=v_attnum1) THEN - CREATE INDEX x_trx_log_IDX_trx_id ON x_trx_log(trx_id); + SELECT COUNT(*) INTO v_table_exists FROM pg_class WHERE relname = 'x_trx_log'; + IF v_table_exists > 0 THEN + select attnum into v_attnum1 from pg_attribute where attrelid in(select oid from pg_class where relname='x_trx_log') and attname in('trx_id'); + IF v_attnum1 > 0 THEN + IF not exists (select * from pg_index where indrelid in(select oid from pg_class where relname='x_trx_log') and indkey[0]=v_attnum1) THEN + CREATE INDEX x_trx_log_IDX_trx_id ON x_trx_log(trx_id); + END IF; END IF; END IF; END; diff --git a/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql b/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql index 792fffd8da..72a9afb83b 100644 --- a/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql +++ b/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql @@ -2284,9 +2284,9 @@ INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active GO INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('066',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); GO -INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('067',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); +INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('073',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); GO -INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('068',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); +INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('074',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); GO INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('DB_PATCHES',CURRENT_TIMESTAMP,'Ranger 1.0.0',CURRENT_TIMESTAMP,'localhost','Y'); GO diff --git a/security-admin/db/sqlanywhere/patches/067-create-x_trx_log_v2.sql b/security-admin/db/sqlanywhere/patches/073-create-x_trx_log_v2.sql similarity index 100% rename from security-admin/db/sqlanywhere/patches/067-create-x_trx_log_v2.sql rename to security-admin/db/sqlanywhere/patches/073-create-x_trx_log_v2.sql diff --git a/security-admin/db/sqlanywhere/patches/068-create-index-for-x_trx_log.sql b/security-admin/db/sqlanywhere/patches/074-create-index-for-x_trx_log.sql similarity index 76% rename from security-admin/db/sqlanywhere/patches/068-create-index-for-x_trx_log.sql rename to security-admin/db/sqlanywhere/patches/074-create-index-for-x_trx_log.sql index ae76a6de97..d4d39c8c2d 100644 --- a/security-admin/db/sqlanywhere/patches/068-create-index-for-x_trx_log.sql +++ b/security-admin/db/sqlanywhere/patches/074-create-index-for-x_trx_log.sql @@ -13,7 +13,11 @@ -- See the License for the specific language governing permissions and -- limitations under the License. -CREATE INDEX IF NOT EXISTS x_trx_log_IDX_trx_id ON x_trx_log(trx_id); +IF EXISTS(select * from SYS.SYSTABLES where tname = 'x_trx_log') THEN + IF EXISTS(select * from SYS.SYSCOLUMNS where tname = 'x_trx_log' and cname = 'trx_id') THEN + CREATE INDEX IF NOT EXISTS x_trx_log_IDX_trx_id ON x_trx_log(trx_id); + END IF; +END IF; GO EXIT diff --git a/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql b/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql index eccf7f46f1..70a2e00cde 100644 --- a/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql +++ b/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql @@ -4143,8 +4143,8 @@ INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('060',CURRENT_TIMESTAMP,'Ranger 1.0.0',CURRENT_TIMESTAMP,'localhost','Y'); INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('065',CURRENT_TIMESTAMP,'Ranger 1.0.0',CURRENT_TIMESTAMP,'localhost','Y'); INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('066',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); -INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('067',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); -INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('068',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); +INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('073',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); +INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('074',CURRENT_TIMESTAMP,'Ranger 3.0.0',CURRENT_TIMESTAMP,'localhost','Y'); INSERT INTO x_db_version_h (version,inst_at,inst_by,updated_at,updated_by,active) VALUES ('DB_PATCHES',CURRENT_TIMESTAMP,'Ranger 1.0.0',CURRENT_TIMESTAMP,'localhost','Y'); INSERT INTO x_user_module_perm (user_id,module_id,create_time,update_time,added_by_id,upd_by_id,is_allowed) VALUES (dbo.getXportalUIdByLoginId('admin'),dbo.getModulesIdByName('Reports'),CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,dbo.getXportalUIdByLoginId('admin'),dbo.getXportalUIdByLoginId('admin'),1); INSERT INTO x_user_module_perm (user_id,module_id,create_time,update_time,added_by_id,upd_by_id,is_allowed) VALUES (dbo.getXportalUIdByLoginId('admin'),dbo.getModulesIdByName('Resource Based Policies'),CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,dbo.getXportalUIdByLoginId('admin'),dbo.getXportalUIdByLoginId('admin'),1); diff --git a/security-admin/db/sqlserver/patches/067-create-x_trx_log_v2.sql b/security-admin/db/sqlserver/patches/073-create-x_trx_log_v2.sql similarity index 100% rename from security-admin/db/sqlserver/patches/067-create-x_trx_log_v2.sql rename to security-admin/db/sqlserver/patches/073-create-x_trx_log_v2.sql diff --git a/security-admin/db/sqlserver/patches/068-create-index-for-x_trx_log.sql b/security-admin/db/sqlserver/patches/074-create-index-for-x_trx_log.sql similarity index 69% rename from security-admin/db/sqlserver/patches/068-create-index-for-x_trx_log.sql rename to security-admin/db/sqlserver/patches/074-create-index-for-x_trx_log.sql index 3efb9eebbe..3db055a8c5 100644 --- a/security-admin/db/sqlserver/patches/068-create-index-for-x_trx_log.sql +++ b/security-admin/db/sqlserver/patches/074-create-index-for-x_trx_log.sql @@ -13,13 +13,16 @@ -- See the License for the specific language governing permissions and -- limitations under the License. GO -IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'x_trx_log_IDX_trx_id' AND object_id = OBJECT_ID('x_trx_log')) +IF OBJECT_ID('x_trx_log') IS NOT NULL BEGIN - CREATE NONCLUSTERED INDEX [x_trx_log_IDX_trx_id] ON [x_trx_log] - ( - [trx_id] ASC - ) - WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY] + IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'x_trx_log_IDX_trx_id' AND object_id = OBJECT_ID('x_trx_log')) + BEGIN + CREATE NONCLUSTERED INDEX [x_trx_log_IDX_trx_id] ON [x_trx_log] + ( + [trx_id] ASC + ) + WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY] + END END Go