From 39bc94ac172c1a5afb0f5a8eeaf32e5c6c2a3f58 Mon Sep 17 00:00:00 2001 From: stewie925 Date: Wed, 23 May 2018 19:30:53 -0500 Subject: [PATCH] Fix ranger database scripts Change-Id: Ic1146f9500f3f1c7346819f7e4a7ffcf5520c84a --- .../db_scripts/ranger_cms_create_db.sql | 8 +- .../db_scripts/ranger_cms_update_db.sql | 9 +-- .../db_scripts/ranger_fms_create_db.sql | 11 ++- .../db_scripts/ranger_fms_update_db.sql | 26 ------ .../scripts/db_scripts/create_db.sql | 9 +++ .../scripts/db_scripts/update_db.sql | 29 ------- .../scripts/db_scripts/create_db.sql | 10 ++- .../scripts/db_scripts/update_db.sql | 80 ------------------- .../scripts/db_scripts/update_db.sql | 41 ---------- tools/ranger_create_db.sh | 6 -- tools/setenv.sh | 3 +- 11 files changed, 34 insertions(+), 198 deletions(-) mode change 100755 => 100644 orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql delete mode 100755 orm/services/flavor_manager/scripts/db_scripts/ranger_fms_update_db.sql delete mode 100755 orm/services/image_manager/scripts/db_scripts/update_db.sql delete mode 100644 orm/services/region_manager/scripts/db_scripts/update_db.sql delete mode 100755 orm/services/resource_distributor/scripts/db_scripts/update_db.sql diff --git a/orm/services/customer_manager/scripts/db_scripts/ranger_cms_create_db.sql b/orm/services/customer_manager/scripts/db_scripts/ranger_cms_create_db.sql index 08410af3..f16d1fe2 100755 --- a/orm/services/customer_manager/scripts/db_scripts/ranger_cms_create_db.sql +++ b/orm/services/customer_manager/scripts/db_scripts/ranger_cms_create_db.sql @@ -18,7 +18,7 @@ create table if not exists region ( id integer auto_increment not null, name varchar(64) not null, - type varchar(64) not null, + type varchar(64) not null DEFAULT 'single', primary key (id), unique name_idx (name)); @@ -89,7 +89,7 @@ create table if not exists user_role index region_id (region_id), index user_id (user_id)); -CREATE OR REPLACE VIEW rds_resource_status_view AS +create or replace view rds_resource_status_view AS ( - SELECT ID, RESOURCE_ID, REGION,STATUS, - ERR_CODE,OPERATION from orm_rds.resource_status); + SELECT id, resource_id, region, status, + err_code, operation from orm_rds.resource_status); diff --git a/orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql b/orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql old mode 100755 new mode 100644 index 3a924b1a..694f3d14 --- a/orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql +++ b/orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql @@ -84,13 +84,7 @@ DROP PROCEDURE IF EXISTS add_region_type ;; CREATE PROCEDURE add_region_type() BEGIN - -- add a column safely - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='type' AND TABLE_NAME='region') ) THEN - ALTER TABLE region ADD type varchar(64) NOT NULL DEFAULT 'single'; - ELSE - UPDATE region set type = "single" where id = -1; - END IF; + UPDATE region set type = "single" where id = -1; IF NOT EXISTS( SELECT * FROM region WHERE id=-1) THEN insert ignore into region(id,name,type) values(-1, "DEFAULT", "single"); @@ -101,4 +95,3 @@ END ;; CALL add_region_type() ;; DELIMITER ; - diff --git a/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_create_db.sql b/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_create_db.sql index 9ebd7f5f..ac115f5f 100755 --- a/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_create_db.sql +++ b/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_create_db.sql @@ -51,7 +51,7 @@ create table if not exists flavor_region ( flavor_internal_id bigint not null, region_name varchar(64) not null, - region_type varchar(32) not null, + region_type varchar(32) not null DEFAULT 'single', foreign key (flavor_internal_id) references flavor(internal_id) ON DELETE CASCADE ON UPDATE NO ACTION, primary key (flavor_internal_id,region_name) ); @@ -100,3 +100,12 @@ create table if not exists flavor_option ); # + +#***** +#* MySql script for Creating View rds_resource_status_view +#***** + +create or replace view rds_resource_status_view AS + ( + SELECT ID, RESOURCE_ID, REGION,STATUS, + ERR_CODE,OPERATION from orm_rds.resource_status); diff --git a/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_update_db.sql b/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_update_db.sql deleted file mode 100755 index b3da1f01..00000000 --- a/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_update_db.sql +++ /dev/null @@ -1,26 +0,0 @@ -USE orm_fms_db; - -DELIMITER ;; - -DROP PROCEDURE IF EXISTS add_regoion_type ;; -CREATE PROCEDURE add_regoion_type() -BEGIN - - -- add a column safely - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='region_type' AND TABLE_NAME='flavor_region') ) THEN - ALTER TABLE flavor_region ADD region_type varchar(32) NOT NULL DEFAULT 'single'; - END IF; - - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='alias' AND TABLE_NAME='flavor') ) THEN - ALTER TABLE flavor ADD alias varchar(64) NULL; - END IF; - -END ;; - -CALL add_regoion_type() ;; -ALTER TABLE `flavor` CHANGE COLUMN `name` `name` VARCHAR(250) NOT NULL;; - -DELIMITER ; - diff --git a/orm/services/image_manager/scripts/db_scripts/create_db.sql b/orm/services/image_manager/scripts/db_scripts/create_db.sql index df1384a7..30d046d8 100755 --- a/orm/services/image_manager/scripts/db_scripts/create_db.sql +++ b/orm/services/image_manager/scripts/db_scripts/create_db.sql @@ -84,3 +84,12 @@ create table if not exists image_customer foreign key (image_id) references image(id) ON DELETE CASCADE ON UPDATE NO ACTION ); # + +#***** +#* MySql script for Creating View rds_resource_status_view +#***** + +create or replace view rds_resource_status_view AS + ( + SELECT ID, RESOURCE_ID, REGION,STATUS, + ERR_CODE,OPERATION from orm_rds.resource_status); diff --git a/orm/services/image_manager/scripts/db_scripts/update_db.sql b/orm/services/image_manager/scripts/db_scripts/update_db.sql deleted file mode 100755 index abec7984..00000000 --- a/orm/services/image_manager/scripts/db_scripts/update_db.sql +++ /dev/null @@ -1,29 +0,0 @@ -USE orm_ims_db; - -DELIMITER ;; - -DROP PROCEDURE IF EXISTS add_region_properies; -CREATE PROCEDURE add_region_properies() -BEGIN - - -- add a column safely - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='checksum' AND TABLE_NAME='image_region') ) THEN - ALTER TABLE image_region ADD checksum varchar(64) NOT NULL; - END IF; - - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='size' AND TABLE_NAME='image_region') ) THEN - ALTER TABLE image_region ADD size varchar(64) NOT NULL; - END IF; - - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='virtual_size' AND TABLE_NAME='image_region') ) THEN - ALTER TABLE image_region ADD virtual_size varchar(64) NOT NULL; - END IF; -END ;; - -CALL add_region_properies() ;; - -DELIMITER ; - diff --git a/orm/services/region_manager/scripts/db_scripts/create_db.sql b/orm/services/region_manager/scripts/db_scripts/create_db.sql index b37c821a..ae6c0cf3 100644 --- a/orm/services/region_manager/scripts/db_scripts/create_db.sql +++ b/orm/services/region_manager/scripts/db_scripts/create_db.sql @@ -7,7 +7,10 @@ create table if not exists rms_groups group_id varchar(64) not null, name varchar(64) not null, description varchar(255) not null, - primary key (id), + created TIMESTAMP not null DEFAULT 0, + modified TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + primary key (id,group_id), + unique grp_namex (name), unique group_idx (group_id)); @@ -29,7 +32,10 @@ create table if not exists region vlcp_name varchar(64) not null, clli varchar(64) not null, description varchar(255) not null, - primary key (id), + created TIMESTAMP not null DEFAULT 0, + modified TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + primary key (id,region_id,name), + unique region_namex (name), unique region_idx (region_id)); diff --git a/orm/services/region_manager/scripts/db_scripts/update_db.sql b/orm/services/region_manager/scripts/db_scripts/update_db.sql deleted file mode 100644 index 73f8c851..00000000 --- a/orm/services/region_manager/scripts/db_scripts/update_db.sql +++ /dev/null @@ -1,80 +0,0 @@ -use orm_rms_db; - -# This SQL script is used for upgrading ORM_RMS_DB. - -# PROCEDURE Update_Region_Status() -# The following defines and then calls a stored procedure that updates and replaces -# region_status from 'commissioning' to 'building'. - -DROP PROCEDURE IF EXISTS Rename_group_table; - -DELIMITER $$ - -CREATE PROCEDURE Rename_group_table() -BEGIN - DECLARE _table_exist INT; --- Check if table 'group' exists even if no rows in table - SET _table_exist = ( SELECT COUNT(*) - FROM information_schema.tables - WHERE table_schema = 'orm_rms_db' - AND table_name like 'group'); - IF _table_exist > 0 THEN - RENAME TABLE `group` TO rms_groups; - END IF; -END $$ -DELIMITER ; - -CALL Rename_group_table; - -DROP PROCEDURE IF EXISTS Update_Region_Status; - -DELIMITER $$ - -CREATE PROCEDURE Update_Region_Status() -BEGIN --- Add a new enum value 'building' to the end of the enum list - ALTER TABLE region CHANGE region_status - region_status ENUM('commissioning','functional','maintenance','down','building'); - --- Update the table to change the old to the new value - UPDATE region set region_status = 'building' where region_status = 'commissioning'; - --- after changing to the new values, safe to remove the old "commissioning" value from the ENUM list - ALTER TABLE region CHANGE region_status - region_status ENUM('building','functional','maintenance','down'); - -END $$ -DELIMITER ; - -CALL Update_Region_Status; - -# PROCEDURE Upgrade_Region_Meta_Data; -# The following defines and then calls a stored procedure that does the following for the region_meta_data table: -# 1. Check if a column named 'id' not exist, if exist the db already up to date. -# 2. Remove old fk, pk and unique constraint. -# 3. Add a new column to the region_meta_data table named 'id' set it as auto increment and primary key. -# 4. Add a new constraint to define unique values. - -DROP PROCEDURE IF EXISTS Upgrade_Region_Meta_Data; - -DELIMITER $$ -CREATE PROCEDURE Upgrade_Region_Meta_Data() -BEGIN - DECLARE _count INT; - SET _count = ( SELECT COUNT(*) - FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'region_meta_data' AND - COLUMN_NAME = 'id'); - IF _count = 0 THEN - ALTER TABLE region_meta_data DROP FOREIGN KEY region_meta_data_ibfk_1; - ALTER TABLE region_meta_data DROP PRIMARY KEY; - ALTER TABLE region_meta_data DROP index region_meta_data_key; - - ALTER TABLE region_meta_data ADD COLUMN id int NOT NULL AUTO_INCREMENT primary key FIRST; - ALTER TABLE region_meta_data ADD CONSTRAINT region_meta_data_key_value UNIQUE (region_id, meta_data_key, meta_data_value); - END IF; -END $$ -DELIMITER ; - -CALL Upgrade_Region_Meta_Data; - diff --git a/orm/services/resource_distributor/scripts/db_scripts/update_db.sql b/orm/services/resource_distributor/scripts/db_scripts/update_db.sql deleted file mode 100755 index 05ba7230..00000000 --- a/orm/services/resource_distributor/scripts/db_scripts/update_db.sql +++ /dev/null @@ -1,41 +0,0 @@ -use orm_rds; - - -DELIMITER ;; - -#***** -#* MySql script for Creating Table image_metadata -#***** -DROP PROCEDURE IF EXISTS add_table_image_metadata ;; -CREATE PROCEDURE add_table_image_metadata() -BEGIN - - create table if not exists image_metadata - ( - image_meta_data_id integer not null, - checksum varchar(64) , - virtual_size varchar(64) , - size varchar(64) , - foreign key (image_meta_data_id) references resource_status(id) ON DELETE CASCADE ON UPDATE NO ACTION, - primary key (image_meta_data_id)); - - -END ;; -# -#*********** -#* add operation field to resource_status table -#*********** - -DROP PROCEDURE IF EXISTS add_operation_in_resource_status ;; -CREATE PROCEDURE add_operation_in_resource_status() -BEGIN - - IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() - AND COLUMN_NAME='operation' AND TABLE_NAME='resource_status') ) THEN - ALTER TABLE resource_status ADD operation varchar(64) DEFAULT ''; - END IF; - -END ;; -CALL add_operation_in_resource_status() ;; -CALL add_table_image_metadata();; -DELIMITER ; \ No newline at end of file diff --git a/tools/ranger_create_db.sh b/tools/ranger_create_db.sh index f77b7076..670cede5 100755 --- a/tools/ranger_create_db.sh +++ b/tools/ranger_create_db.sh @@ -3,7 +3,6 @@ tools_dir=/opt/stack/ranger/tools cd .. cd orm/services/audit_trail_manager/scripts/shell_scripts/ bash create_db.sh -bash update_db.sh cd $root_dir cd orm/services/customer_manager/scripts/shell_scripts/ bash create_db.sh @@ -11,22 +10,17 @@ bash update_db.sh cd $root_dir cd orm/services/flavor_manager/scripts/shell_scripts/ bash create_db.sh -bash update_db.sh cd $root_dir cd orm/services/id_generator/scripts/shell_scripts/ bash create_db.sh -bash update_db.sh cd $root_dir cd orm/services/image_manager/scripts/shell_scripts/ bash create_db.sh -bash update_db.sh cd $root_dir cd orm/services/region_manager/scripts/shell_scripts/ bash create_db.sh -bash update_db.sh cd $root_dir cd orm/services/resource_distributor/scripts/shell_scripts/ bash create_db.sh -bash update_db.sh echo "Databases Created!" cd $tools_dir diff --git a/tools/setenv.sh b/tools/setenv.sh index 3c8cc5c6..d981b17a 100755 --- a/tools/setenv.sh +++ b/tools/setenv.sh @@ -1,3 +1,4 @@ export RANGER_BASE='/opt/stack/ranger' export HTTP_PROXY='' -export MYSQL_PASSWORD=stack +export MYSQL_PASSWORD=xxxxxxxx +