diff --git a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java index 4e6a4758ec3..5111e424553 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java @@ -57,10 +57,25 @@ public class Upgrade222to224 implements DbUpgrade { return new File[] { new File(script) }; } + + private void fixRelatedFkeyOnNetworksTable(Connection conn) throws SQLException { + PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__related`"); + try { + pstmt.executeUpdate(); + } catch (SQLException e) { + s_logger.debug("Ignore if the key is not there."); + } + pstmt.close(); + + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + pstmt.close(); + } @Override public void performDataMigration(Connection conn) { try { + fixRelatedFkeyOnNetworksTable(conn); updateClusterIdInOpHostCapacity(conn); updateGuestOsType(conn); updateNicsWithMode(conn); diff --git a/setup/db/db/schema-217to218.sql b/setup/db/db/schema-217to218.sql index 06ee15f7aa4..6284bf72fc6 100644 --- a/setup/db/db/schema-217to218.sql +++ b/setup/db/db/schema-217to218.sql @@ -4,3 +4,12 @@ ALTER TABLE `cloud`.`account_vlan_map` modify `account_id` bigint unsigned defau ALTER TABLE `cloud`.`account_vlan_map` ADD COLUMN `domain_id` bigint unsigned COMMENT 'domain id. foreign key to domain table'; ALTER TABLE `cloud`.`account_vlan_map` ADD CONSTRAINT `fk_account_vlan_map__domain_id` FOREIGN KEY `fk_account_vlan_map__domain_id` (`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`account_vlan_map` ADD INDEX `i_account_vlan_map__domain_id`(`domain_id`); + +CREATE TABLE `cloud`.`version` ( + `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', + `version` char(40) NOT NULL UNIQUE COMMENT 'version', + `updated` datetime NOT NULL COMMENT 'Date this version table was updated', + `step` char(32) NOT NULL COMMENT 'Step in the upgrade to this version', + PRIMARY KEY (`id`), + INDEX `i_version__version`(`version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index bb4340fca54..5eba19050a5 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -24,7 +24,7 @@ DROP TABLE `cloud`.`security_group_vm_map`; -- Easy stuff first. All new tables.; -CREATE TABLE `cloud`.`version` ( +CREATE TABLE IF NOT EXISTS `cloud`.`version` ( `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', `version` char(40) NOT NULL UNIQUE COMMENT 'version', `updated` datetime NOT NULL COMMENT 'Date this version table was updated', diff --git a/setup/db/db/schema-221to222.sql b/setup/db/db/schema-221to222.sql index db9a1f3003f..41b68f71897 100644 --- a/setup/db/db/schema-221to222.sql +++ b/setup/db/db/schema-221to222.sql @@ -27,3 +27,11 @@ update network_offerings set availability='Optional' where id=7; delete from configuration where name='router.cleanup.interval'; INSERT INTO configuration (category, instance, component, name, value, description) VALUES ('Advanced', 'DEFAULT', 'management-server', 'management.network.cidr', NULL, 'The cidr of management server network'); +CREATE TABLE IF NOT EXISTS `cloud`.`version` ( + `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', + `version` char(40) NOT NULL UNIQUE COMMENT 'version', + `updated` datetime NOT NULL COMMENT 'Date this version table was updated', + `step` char(32) NOT NULL COMMENT 'Step in the upgrade to this version', + PRIMARY KEY (`id`), + INDEX `i_version__version`(`version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 31e0233424f..f5d69b9f260 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -37,9 +37,9 @@ ALTER TABLE `cloud`.`remote_access_vpn` MODIFY `local_ip` char(40) NOT NULL; ALTER TABLE `cloud`.`storage_pool` MODIFY `host_address` char(40) NOT NULL; ALTER TABLE `cloud`.`user_ip_address` MODIFY `public_ip_address` char(40) NOT NULL; - -ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__related`; -ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE; +#Commented out these lines because they have to be done inside java.; +#ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__related`; +#ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`cluster` ADD COLUMN `removed` datetime COMMENT 'date removed if not null'; ALTER TABLE `cloud`.`cluster` MODIFY `name` varchar(255) COMMENT 'name for the cluster';