Upgrade changes for Region schema. Made region_id not null

This commit is contained in:
Kishan Kavala 2013-02-01 13:49:45 +05:30
parent bfc4f982fd
commit fc925022bd
4 changed files with 42 additions and 19 deletions

View File

@ -18,25 +18,25 @@
-- Add a default ROOT domain
use cloud;
INSERT INTO `cloud`.`domain` (id, uuid, name, parent, path, owner) VALUES
(1, UUID(), 'ROOT', NULL, '/', 2);
INSERT INTO `cloud`.`domain` (id, uuid, name, parent, path, owner, region_id) VALUES
(1, UUID(), 'ROOT', NULL, '/', 2, 1);
-- Add system and admin accounts
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state) VALUES
(1, UUID(), 'system', 1, 1, 'enabled');
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state, region_id) VALUES
(1, UUID(), 'system', 1, 1, 'enabled', 1);
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state) VALUES
(2, UUID(), 'admin', 1, 1, 'enabled');
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state, region_id) VALUES
(2, UUID(), 'admin', 1, 1, 'enabled', 1);
-- Add system user
INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname,
lastname, email, state, created) VALUES (1, UUID(), 'system', RAND(),
'1', 'system', 'cloud', NULL, 'enabled', NOW());
lastname, email, state, created, region_id) VALUES (1, UUID(), 'system', RAND(),
'1', 'system', 'cloud', NULL, 'enabled', NOW(), 1);
-- Add system user with encrypted password=password
INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname,
lastname, email, state, created) VALUES (2, UUID(), 'admin', '5f4dcc3b5aa765d61d8327deb882cf99',
'2', 'Admin', 'User', 'admin@mailprovider.com', 'enabled', NOW());
lastname, email, state, created, region_id) VALUES (2, UUID(), 'admin', '5f4dcc3b5aa765d61d8327deb882cf99',
'2', 'Admin', 'User', 'admin@mailprovider.com', 'enabled', NOW(), 1);
-- Add configurations
INSERT INTO `cloud`.`configuration` (category, instance, component, name, value)

View File

@ -317,7 +317,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
protected void saveUser() {
//ToDo: Add regionId to default users and accounts
// insert system account
String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id) VALUES (1, UUID(), 'system', '1', '1')";
String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (1, UUID(), 'system', '1', '1', '1')";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
@ -325,8 +325,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
} catch (SQLException ex) {
}
// insert system user
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created)" +
" VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now())";
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, region_id)" +
" VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), '1')";
txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
@ -342,7 +342,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
String lastname = "cloud";
// create an account for the admin user first
insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id) VALUES (" + id + ", UUID(), '" + username + "', '1', '1')";
insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', '1')";
txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
@ -351,8 +351,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
}
// now insert the user
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created, state) " +
"VALUES (" + id + ",'" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled')";
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created, state, region_id) " +
"VALUES (" + id + ",'" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', '1')";
txn = Transaction.currentTxn();
try {

View File

@ -911,7 +911,7 @@ CREATE TABLE `cloud`.`user` (
`timezone` varchar(30) default NULL,
`registration_token` varchar(255) default NULL,
`is_registered` tinyint NOT NULL DEFAULT 0 COMMENT '1: yes, 0: no',
`region_id` int unsigned,
`region_id` int unsigned NOT NULL,
`incorrect_login_attempts` integer unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
INDEX `i_user__removed`(`removed`),
@ -1262,7 +1262,7 @@ CREATE TABLE `cloud`.`domain` (
`state` char(32) NOT NULL default 'Active' COMMENT 'state of the domain',
`network_domain` varchar(255),
`type` varchar(255) NOT NULL DEFAULT 'Normal' COMMENT 'type of the domain - can be Normal or Project',
`region_id` int unsigned,
`region_id` int unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (parent, name, removed),
INDEX `i_domain__path`(`path`),
@ -1281,7 +1281,7 @@ CREATE TABLE `cloud`.`account` (
`cleanup_needed` tinyint(1) NOT NULL default '0',
`network_domain` varchar(255),
`default_zone_id` bigint unsigned,
`region_id` int unsigned,
`region_id` int unsigned NOT NULL,
PRIMARY KEY (`id`),
INDEX i_account__removed(`removed`),
CONSTRAINT `fk_account__default_zone_id` FOREIGN KEY `fk_account__default_zone_id`(`default_zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE,

View File

@ -1268,3 +1268,26 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag
ALTER TABLE `cloud`.`op_dc_vnet_alloc` DROP INDEX i_op_dc_vnet_alloc__vnet__data_center_id;
ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD CONSTRAINT UNIQUE `i_op_dc_vnet_alloc__vnet__data_center_id`(`vnet`, `physical_network_id`, `data_center_id`);
CREATE TABLE `cloud`.`region` (
`id` int unsigned NOT NULL UNIQUE,
`name` varchar(255) NOT NULL UNIQUE,
`end_point` varchar(255) NOT NULL,
`api_key` varchar(255),
`secret_key` varchar(255),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`region_sync` (
`id` bigint unsigned NOT NULL auto_increment,
`region_id` int unsigned NOT NULL,
`api` varchar(1024) NOT NULL,
`created` datetime NOT NULL COMMENT 'date created',
`processed` tinyint NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api','','');
ALTER TABLE `cloud`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
ALTER TABLE `cloud`.`user` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
ALTER TABLE `cloud`.`domain` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';