diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java b/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java index 07b7ab4d073..b914d637621 100755 --- a/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java @@ -195,7 +195,7 @@ public class Upgrade2213to2214 implements DbUpgrade { throw new CloudRuntimeException("Unable to insert foreign key in security_group table ", e); } - //Drop securityGroup keys (if exists) and insert one with correct name + //Drop vmInstance keys (if exists) and insert one with correct name keys = new ArrayList(); keys.add("i_vm_instance__host_id"); keys.add("fk_vm_instance__host_id"); @@ -225,6 +225,30 @@ public class Upgrade2213to2214 implements DbUpgrade { throw new CloudRuntimeException("Unable to insert foreign key in vm_instance table ", e); } + //Drop user_ip_address keys (if exists) and insert one with correct name + keys = new ArrayList(); + keys.add("fk_user_ip_address__account_id"); + keys.add("i_user_ip_address__account_id"); + + keys.add("fk_user_ip_address__vlan_db_id"); + keys.add("i_user_ip_address__vlan_db_id"); + + keys.add("fk_user_ip_address__data_center_id"); + keys.add("i_user_ip_address__data_center_id"); + + DbUpgradeUtils.dropKeysIfExist(conn, "cloud.user_ip_address", keys, true); + DbUpgradeUtils.dropKeysIfExist(conn, "cloud.user_ip_address", keys, false); + try { + PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `fk_user_ip_address__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`)"); + pstmt.executeUpdate(); + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `fk_user_ip_address__vlan_db_id` FOREIGN KEY (`vlan_db_id`) REFERENCES `vlan`(`id`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `fk_user_ip_address__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + pstmt.close(); + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to insert foreign key in vm_instance table ", e); + } } } diff --git a/setup/db/db/schema-2213to2214.sql b/setup/db/db/schema-2213to2214.sql index bb79667b0e8..9c9ba4d8c02 100644 --- a/setup/db/db/schema-2213to2214.sql +++ b/setup/db/db/schema-2213to2214.sql @@ -58,5 +58,8 @@ ALTER TABLE `cloud`.`domain_router` MODIFY `stop_pending` int(1) unsigned NOT NU ALTER TABLE `cloud`.`service_offering` MODIFY `limit_cpu_use` tinyint(1) unsigned NOT NULL default '0' COMMENT 'Limit the CPU usage to service offering'; +ALTER TABLE `cloud`.`vm_instance` MODIFY `limit_cpu_use` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Limit the cpu usage to service offering'; -UPDATE `cloud`.`configuration` SET `value`='false' WHERE `name`='agent.lb.enabled'; \ No newline at end of file +UPDATE `cloud`.`configuration` SET `value`='false' WHERE `name`='agent.lb.enabled'; + +ALTER TABLE `cloud_usage`.`user_statistics` MODIFY `device_type` varchar(32) NOT NULL; \ No newline at end of file