Skip to content

Commit fc92502

Browse files
author
Kishan Kavala
committed
Upgrade changes for Region schema. Made region_id not null
1 parent bfc4f98 commit fc92502

4 files changed

Lines changed: 42 additions & 19 deletions

File tree

developer/developer-prefill.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
-- Add a default ROOT domain
1919
use cloud;
2020

21-
INSERT INTO `cloud`.`domain` (id, uuid, name, parent, path, owner) VALUES
22-
(1, UUID(), 'ROOT', NULL, '/', 2);
21+
INSERT INTO `cloud`.`domain` (id, uuid, name, parent, path, owner, region_id) VALUES
22+
(1, UUID(), 'ROOT', NULL, '/', 2, 1);
2323

2424
-- Add system and admin accounts
25-
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state) VALUES
26-
(1, UUID(), 'system', 1, 1, 'enabled');
25+
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state, region_id) VALUES
26+
(1, UUID(), 'system', 1, 1, 'enabled', 1);
2727

28-
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state) VALUES
29-
(2, UUID(), 'admin', 1, 1, 'enabled');
28+
INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, state, region_id) VALUES
29+
(2, UUID(), 'admin', 1, 1, 'enabled', 1);
3030

3131
-- Add system user
3232
INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname,
33-
lastname, email, state, created) VALUES (1, UUID(), 'system', RAND(),
34-
'1', 'system', 'cloud', NULL, 'enabled', NOW());
33+
lastname, email, state, created, region_id) VALUES (1, UUID(), 'system', RAND(),
34+
'1', 'system', 'cloud', NULL, 'enabled', NOW(), 1);
3535

3636
-- Add system user with encrypted password=password
3737
INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname,
38-
lastname, email, state, created) VALUES (2, UUID(), 'admin', '5f4dcc3b5aa765d61d8327deb882cf99',
39-
'2', 'Admin', 'User', 'admin@mailprovider.com', 'enabled', NOW());
38+
lastname, email, state, created, region_id) VALUES (2, UUID(), 'admin', '5f4dcc3b5aa765d61d8327deb882cf99',
39+
'2', 'Admin', 'User', 'admin@mailprovider.com', 'enabled', NOW(), 1);
4040

4141
-- Add configurations
4242
INSERT INTO `cloud`.`configuration` (category, instance, component, name, value)

server/src/com/cloud/server/ConfigurationServerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,16 @@ private String getEnvironmentProperty(String name) {
317317
protected void saveUser() {
318318
//ToDo: Add regionId to default users and accounts
319319
// insert system account
320-
String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id) VALUES (1, UUID(), 'system', '1', '1')";
320+
String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (1, UUID(), 'system', '1', '1', '1')";
321321
Transaction txn = Transaction.currentTxn();
322322
try {
323323
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
324324
stmt.executeUpdate();
325325
} catch (SQLException ex) {
326326
}
327327
// insert system user
328-
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created)" +
329-
" VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now())";
328+
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, region_id)" +
329+
" VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), '1')";
330330
txn = Transaction.currentTxn();
331331
try {
332332
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
@@ -342,7 +342,7 @@ protected void saveUser() {
342342
String lastname = "cloud";
343343

344344
// create an account for the admin user first
345-
insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id) VALUES (" + id + ", UUID(), '" + username + "', '1', '1')";
345+
insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', '1')";
346346
txn = Transaction.currentTxn();
347347
try {
348348
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
@@ -351,8 +351,8 @@ protected void saveUser() {
351351
}
352352

353353
// now insert the user
354-
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created, state) " +
355-
"VALUES (" + id + ",'" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled')";
354+
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created, state, region_id) " +
355+
"VALUES (" + id + ",'" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', '1')";
356356

357357
txn = Transaction.currentTxn();
358358
try {

setup/db/create-schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ CREATE TABLE `cloud`.`user` (
911911
`timezone` varchar(30) default NULL,
912912
`registration_token` varchar(255) default NULL,
913913
`is_registered` tinyint NOT NULL DEFAULT 0 COMMENT '1: yes, 0: no',
914-
`region_id` int unsigned,
914+
`region_id` int unsigned NOT NULL,
915915
`incorrect_login_attempts` integer unsigned NOT NULL DEFAULT 0,
916916
PRIMARY KEY (`id`),
917917
INDEX `i_user__removed`(`removed`),
@@ -1262,7 +1262,7 @@ CREATE TABLE `cloud`.`domain` (
12621262
`state` char(32) NOT NULL default 'Active' COMMENT 'state of the domain',
12631263
`network_domain` varchar(255),
12641264
`type` varchar(255) NOT NULL DEFAULT 'Normal' COMMENT 'type of the domain - can be Normal or Project',
1265-
`region_id` int unsigned,
1265+
`region_id` int unsigned NOT NULL,
12661266
PRIMARY KEY (`id`),
12671267
UNIQUE (parent, name, removed),
12681268
INDEX `i_domain__path`(`path`),
@@ -1281,7 +1281,7 @@ CREATE TABLE `cloud`.`account` (
12811281
`cleanup_needed` tinyint(1) NOT NULL default '0',
12821282
`network_domain` varchar(255),
12831283
`default_zone_id` bigint unsigned,
1284-
`region_id` int unsigned,
1284+
`region_id` int unsigned NOT NULL,
12851285
PRIMARY KEY (`id`),
12861286
INDEX i_account__removed(`removed`),
12871287
CONSTRAINT `fk_account__default_zone_id` FOREIGN KEY `fk_account__default_zone_id`(`default_zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE,

setup/db/db/schema-40to410.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,3 +1268,26 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag
12681268
ALTER TABLE `cloud`.`op_dc_vnet_alloc` DROP INDEX i_op_dc_vnet_alloc__vnet__data_center_id;
12691269

12701270
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`);
1271+
1272+
CREATE TABLE `cloud`.`region` (
1273+
`id` int unsigned NOT NULL UNIQUE,
1274+
`name` varchar(255) NOT NULL UNIQUE,
1275+
`end_point` varchar(255) NOT NULL,
1276+
`api_key` varchar(255),
1277+
`secret_key` varchar(255),
1278+
PRIMARY KEY (`id`)
1279+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1280+
1281+
CREATE TABLE `cloud`.`region_sync` (
1282+
`id` bigint unsigned NOT NULL auto_increment,
1283+
`region_id` int unsigned NOT NULL,
1284+
`api` varchar(1024) NOT NULL,
1285+
`created` datetime NOT NULL COMMENT 'date created',
1286+
`processed` tinyint NOT NULL default '0',
1287+
PRIMARY KEY (`id`)
1288+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1289+
1290+
INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api','','');
1291+
ALTER TABLE `cloud`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
1292+
ALTER TABLE `cloud`.`user` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
1293+
ALTER TABLE `cloud`.`domain` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';

0 commit comments

Comments
 (0)