Source:
<code>public void check() { GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade"); try { s_logger.info("Grabbing lock to check for database upgrade."); if (!lock.lock(20 * 60)) { throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); } try { final CloudStackVersion dbVersion = CloudStackVersion.parse(_dao.getCurrentVersion()); final String currentVersionValue = this.getClass().getPackage().getImplementationVersion(); if (StringUtils.isBlank(currentVersionValue)) { return; } final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue); s_logger.info("DB version = " + dbVersion + " Code Version = " + currentVersion); if (dbVersion.compareTo(currentVersion) > 0) { throw new CloudRuntimeException("Database version " + dbVersion + " is higher than management software version " + currentVersionValue); } if (dbVersion.compareTo(currentVersion) == 0) { s_logger.info("DB version and code version matches so no upgrade needed."); return; } upgrade(dbVersion, currentVersion); } finally { lock.unlock(); } } finally { lock.releaseRef(); } s_logger.info("Running Flyway migration on Cloudstack database"); Properties dbProps = DbProperties.getDbProperties(); final String cloudUsername = dbProps.getProperty("db.cloud.username"); final String cloudPassword = dbProps.getProperty("db.cloud.password"); final String cloudHost = dbProps.getProperty("db.cloud.host"); final int cloudPort = Integer.parseInt(dbProps.getProperty("db.cloud.port")); <START> final String dbUrl = "jdbc:mysql://" + cloudHost + ":" + cloudPort + "/cloud"; <END> try { Flyway flyway = new Flyway(); flyway.setDataSource(dbUrl, cloudUsername, cloudPassword); flyway.setTable("cloudstack_schema_version"); flyway.setBaselineOnMigrate(true); flyway.setBaselineVersionAsString("4.11"); flyway.setLocations("db/csmigration"); flyway.migrate(); } catch (FlywayException fwe) { s_logger.error("Failed to run Flyway migration on Cloudstack database due to " + fwe); } }</code><technical_language>@ustcweizhou cloud_usage database, do handle changes for that</technical_language>

Target:
public void check() { GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade"); try { s_logger.info("Grabbing lock to check for database upgrade."); if (!lock.lock(20 * 60)) { throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); } try { final CloudStackVersion dbVersion = CloudStackVersion.parse(_dao.getCurrentVersion()); final String currentVersionValue = this.getClass().getPackage().getImplementationVersion(); if (StringUtils.isBlank(currentVersionValue)) { return; } s_logger.info("DB version = " + dbVersion); if (dbVersion.getMajorRelease() < 4) { legacyUpgrade(dbVersion); } } finally { lock.unlock(); } } finally { lock.releaseRef(); } s_logger.info("Running Flyway migration on Cloudstack database"); Properties dbProps = DbProperties.getDbProperties(); final String cloudUsername = dbProps.getProperty("db.cloud.username"); final String cloudPassword = dbProps.getProperty("db.cloud.password"); final String cloudHost = dbProps.getProperty("db.cloud.host"); final int cloudPort = Integer.parseInt(dbProps.getProperty("db.cloud.port")); final String driver = dbProps.getProperty("db.cloud.driver", "jdbc:mysql"); final String dbUrl = driver + "://" + cloudHost + ":" + cloudPort + "/cloud"; try { Flyway flyway = new Flyway() .configure() .dataSource(dbUrl, cloudUsername, cloudPassword) .table("cloudstack_schema_version") .baselineOnMigrate(true) .baselineVersion(_dao.getCurrentVersion()) .placeholderReplacement(false) .locations("META-INF/db/csmigration","com/cloud/upgrade/flyway") .load(); flyway.migrate(); } catch (FlywayException fwe) { throw new CloudRuntimeException("Failed to run Flyway migration on Cloudstack database ", fwe); } }