bug 9610: Added VERSION table and related index change

This commit is contained in:
Alex Huang 2011-04-27 13:53:04 -07:00
parent 2c64193646
commit e66baae84e
5 changed files with 36 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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