diff --git a/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java b/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java index 24439f61b26..71549e51d41 100644 --- a/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -67,8 +67,8 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { _upgradeMap.put("2.1.8", new DbUpgrade[] { new Upgrade218to22(), new Upgrade221to222(), new UpgradeSnapshot217to224(), new Upgrade222to224(), new Upgrade218to224DomainVlans() }); _upgradeMap.put("2.1.9", new DbUpgrade[] { new Upgrade218to22(), new Upgrade221to222(), new UpgradeSnapshot217to224(), new Upgrade222to224(), new Upgrade218to224DomainVlans() }); _upgradeMap.put("2.2.1", new DbUpgrade[] { new Upgrade221to222(), new UpgradeSnapshot223to224(), new Upgrade222to224()}); - _upgradeMap.put("2.2.2", new DbUpgrade[] { new UpgradeSnapshot223to224(), new Upgrade222to224() }); - _upgradeMap.put("2.2.3", new DbUpgrade[] { new UpgradeSnapshot223to224(), new Upgrade222to224() }); + _upgradeMap.put("2.2.2", new DbUpgrade[] { new Upgrade222to224(), new UpgradeSnapshot223to224() }); + _upgradeMap.put("2.2.3", new DbUpgrade[] { new Upgrade222to224(), new UpgradeSnapshot223to224() }); } protected void runScript(File file) { @@ -122,7 +122,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { for (DbUpgrade upgrade : upgrades) { s_logger.info("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade.getUpgradableVersionRange()[1] - + " to " + upgrade.getUpgradedVersion()); + + " to " + upgrade.getUpgradedVersion()); Transaction txn = Transaction.open("Upgrade"); txn.start(); try { diff --git a/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java b/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java index 19fbc6c5bf9..e0427f1b703 100644 --- a/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java +++ b/server/src/com/cloud/upgrade/dao/VersionDaoImpl.java @@ -102,10 +102,19 @@ public class VersionDaoImpl extends GenericDaoBase implements V pstmt.close(); } } else { - rs.close(); - pstmt.close(); - s_logger.debug("No version table but has nics table, returning 2.2.1"); - return "2.2.1"; + try { + rs.close(); + pstmt.close(); + pstmt = conn.prepareStatement("SELECT is_static_nat from firewall_rules"); + pstmt.executeQuery(); + return "2.2.1"; + } catch (SQLException e) { + s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); + return "2.2.2"; + } finally { + rs.close(); + pstmt.close(); + } } } @@ -136,7 +145,7 @@ public class VersionDaoImpl extends GenericDaoBase implements V pstmt = conn.prepareStatement("SELECT is_static_nat from firewall_rules"); pstmt.executeQuery(); throw new CloudRuntimeException( - "Unable to determine the current version, version table exists and empty, nics table doesn't exist, is_static_nat field exists in firewall_rules table"); + "Unable to determine the current version, version table exists and empty, nics table doesn't exist, is_static_nat field exists in firewall_rules table"); } } catch (SQLException e) { s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); diff --git a/setup/db/db/schema-222to224.sql b/setup/db/db/schema-222to224.sql index 1d0aa4d0d65..b281534a5c1 100644 --- a/setup/db/db/schema-222to224.sql +++ b/setup/db/db/schema-222to224.sql @@ -1,6 +1,16 @@ --; -- Schema upgrade from 2.2.2 to 2.2.4; --; + +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; + ALTER TABLE `cloud`.`op_host_capacity` ADD COLUMN `cluster_id` bigint unsigned AFTER `pod_id`; ALTER TABLE `cloud`.`op_host_capacity` ADD CONSTRAINT `fk_op_host_capacity__cluster_id` FOREIGN KEY `fk_op_host_capacity__cluster_id` (`cluster_id`) REFERENCES `cloud`.`cluster`(`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`op_host_capacity` ADD INDEX `i_op_host_capacity__cluster_id`(`cluster_id`);