Fix ranger database scripts

Change-Id: Ic1146f9500f3f1c7346819f7e4a7ffcf5520c84a
This commit is contained in:
stewie925 2018-05-23 19:30:53 -05:00
parent 338f582060
commit 39bc94ac17
11 changed files with 34 additions and 198 deletions

View File

@ -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);

View File

@ -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 ;

View File

@ -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);

View File

@ -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 ;

View File

@ -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);

View File

@ -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 ;

View File

@ -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));

View File

@ -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;

View File

@ -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 ;

View File

@ -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

View File

@ -1,3 +1,4 @@
export RANGER_BASE='/opt/stack/ranger'
export HTTP_PROXY=''
export MYSQL_PASSWORD=stack
export MYSQL_PASSWORD=xxxxxxxx