mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
add procedures procedure (#9385)
This commit is contained in:
parent
c98f1b8b3c
commit
6e6a276663
@ -128,6 +128,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
|
||||
private static final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class);
|
||||
private final DatabaseVersionHierarchy hierarchy;
|
||||
private static final String VIEWS_DIRECTORY = Paths.get("META-INF", "db", "views").toString();
|
||||
private static final String PROCEDURES_DIRECTORY = Paths.get("META-INF", "db", "procedures").toString();
|
||||
|
||||
@Inject
|
||||
VersionDao _dao;
|
||||
@ -295,83 +296,120 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
|
||||
}
|
||||
|
||||
protected void upgrade(CloudStackVersion dbVersion, CloudStackVersion currentVersion) {
|
||||
executeProcedureScripts();
|
||||
final DbUpgrade[] upgrades = executeUpgrades(dbVersion, currentVersion);
|
||||
|
||||
executeViewScripts();
|
||||
updateSystemVmTemplates(upgrades);
|
||||
}
|
||||
|
||||
protected void executeProcedureScripts() {
|
||||
s_logger.info(String.format("Executing Stored Procedure scripts that are under resource directory [%s].", PROCEDURES_DIRECTORY));
|
||||
List<String> filesPathUnderViewsDirectory = FileUtil.getFilesPathsUnderResourceDirectory(PROCEDURES_DIRECTORY);
|
||||
|
||||
try (TransactionLegacy txn = TransactionLegacy.open("execute-procedure-scripts")) {
|
||||
Connection conn = txn.getConnection();
|
||||
|
||||
for (String filePath : filesPathUnderViewsDirectory) {
|
||||
s_logger.debug(String.format("Executing PROCEDURE script [%s].", filePath));
|
||||
|
||||
InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
|
||||
runScript(conn, viewScript);
|
||||
}
|
||||
|
||||
s_logger.info(String.format("Finished execution of PROCEDURE scripts that are under resource directory [%s].", PROCEDURES_DIRECTORY));
|
||||
} catch (SQLException e) {
|
||||
String message = String.format("Unable to execute PROCEDURE scripts due to [%s].", e.getMessage());
|
||||
s_logger.error(message, e);
|
||||
throw new CloudRuntimeException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
private DbUpgrade[] executeUpgrades(CloudStackVersion dbVersion, CloudStackVersion currentVersion) {
|
||||
s_logger.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion);
|
||||
|
||||
final DbUpgrade[] upgrades = calculateUpgradePath(dbVersion, currentVersion);
|
||||
|
||||
for (DbUpgrade upgrade : upgrades) {
|
||||
VersionVO version;
|
||||
s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade
|
||||
.getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion());
|
||||
TransactionLegacy txn = TransactionLegacy.open("Upgrade");
|
||||
txn.start();
|
||||
VersionVO version = executeUpgrade(upgrade);
|
||||
executeUpgradeCleanup(upgrade, version);
|
||||
}
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
private VersionVO executeUpgrade(DbUpgrade upgrade) {
|
||||
VersionVO version;
|
||||
s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade
|
||||
.getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion());
|
||||
TransactionLegacy txn = TransactionLegacy.open("Upgrade");
|
||||
txn.start();
|
||||
try {
|
||||
Connection conn;
|
||||
try {
|
||||
Connection conn;
|
||||
try {
|
||||
conn = txn.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String errorMessage = "Unable to upgrade the database";
|
||||
s_logger.error(errorMessage, e);
|
||||
throw new CloudRuntimeException(errorMessage, e);
|
||||
}
|
||||
InputStream[] scripts = upgrade.getPrepareScripts();
|
||||
if (scripts != null) {
|
||||
for (InputStream script : scripts) {
|
||||
runScript(conn, script);
|
||||
}
|
||||
}
|
||||
|
||||
upgrade.performDataMigration(conn);
|
||||
|
||||
version = new VersionVO(upgrade.getUpgradedVersion());
|
||||
version = _dao.persist(version);
|
||||
|
||||
txn.commit();
|
||||
} catch (CloudRuntimeException e) {
|
||||
conn = txn.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String errorMessage = "Unable to upgrade the database";
|
||||
s_logger.error(errorMessage, e);
|
||||
throw new CloudRuntimeException(errorMessage, e);
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
InputStream[] scripts = upgrade.getPrepareScripts();
|
||||
if (scripts != null) {
|
||||
for (InputStream script : scripts) {
|
||||
runScript(conn, script);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the corresponding '-cleanup.sql' script
|
||||
txn = TransactionLegacy.open("Cleanup");
|
||||
try {
|
||||
s_logger.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade
|
||||
.getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion());
|
||||
upgrade.performDataMigration(conn);
|
||||
|
||||
txn.start();
|
||||
Connection conn;
|
||||
try {
|
||||
conn = txn.getConnection();
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unable to cleanup the database", e);
|
||||
throw new CloudRuntimeException("Unable to cleanup the database", e);
|
||||
}
|
||||
version = new VersionVO(upgrade.getUpgradedVersion());
|
||||
version = _dao.persist(version);
|
||||
|
||||
InputStream[] scripts = upgrade.getCleanupScripts();
|
||||
if (scripts != null) {
|
||||
for (InputStream script : scripts) {
|
||||
runScript(conn, script);
|
||||
s_logger.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully");
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
txn.start();
|
||||
version.setStep(Step.Complete);
|
||||
version.setUpdated(new Date());
|
||||
_dao.update(version.getId(), version);
|
||||
txn.commit();
|
||||
s_logger.debug("Upgrade completed for version " + version.getVersion());
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
txn.commit();
|
||||
} catch (CloudRuntimeException e) {
|
||||
String errorMessage = "Unable to upgrade the database";
|
||||
s_logger.error(errorMessage, e);
|
||||
throw new CloudRuntimeException(errorMessage, e);
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
executeViewScripts();
|
||||
updateSystemVmTemplates(upgrades);
|
||||
private void executeUpgradeCleanup(DbUpgrade upgrade, VersionVO version) {
|
||||
TransactionLegacy txn;
|
||||
// Run the corresponding '-cleanup.sql' script
|
||||
txn = TransactionLegacy.open("Cleanup");
|
||||
try {
|
||||
s_logger.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade
|
||||
.getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion());
|
||||
|
||||
txn.start();
|
||||
Connection conn;
|
||||
try {
|
||||
conn = txn.getConnection();
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unable to cleanup the database", e);
|
||||
throw new CloudRuntimeException("Unable to cleanup the database", e);
|
||||
}
|
||||
|
||||
InputStream[] scripts = upgrade.getCleanupScripts();
|
||||
if (scripts != null) {
|
||||
for (InputStream script : scripts) {
|
||||
runScript(conn, script);
|
||||
s_logger.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully");
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
txn.start();
|
||||
version.setStep(Step.Complete);
|
||||
version.setUpdated(new Date());
|
||||
_dao.update(version.getId(), version);
|
||||
txn.commit();
|
||||
s_logger.debug("Upgrade completed for version " + version.getVersion());
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeViewScripts() {
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- PR#4699 Drop the procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` if it already exist.
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING`;
|
||||
|
||||
-- PR#4699 Create the procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` to add guest_os and guest_os_hypervisor mapping.
|
||||
CREATE PROCEDURE `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` (
|
||||
IN guest_os_category_id bigint(20) unsigned,
|
||||
IN guest_os_display_name VARCHAR(255),
|
||||
IN guest_os_hypervisor_hypervisor_type VARCHAR(32),
|
||||
IN guest_os_hypervisor_hypervisor_version VARCHAR(32),
|
||||
IN guest_os_hypervisor_guest_os_name VARCHAR(255)
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO cloud.guest_os (uuid, category_id, display_name, created)
|
||||
SELECT UUID(), guest_os_category_id, guest_os_display_name, now()
|
||||
FROM DUAL
|
||||
WHERE not exists( SELECT 1
|
||||
FROM cloud.guest_os
|
||||
WHERE cloud.guest_os.category_id = guest_os_category_id
|
||||
AND cloud.guest_os.display_name = guest_os_display_name)
|
||||
|
||||
; INSERT INTO cloud.guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created)
|
||||
SELECT UUID(), guest_os_hypervisor_hypervisor_type, guest_os_hypervisor_hypervisor_version, guest_os_hypervisor_guest_os_name, guest_os.id, now()
|
||||
FROM cloud.guest_os
|
||||
WHERE guest_os.category_id = guest_os_category_id
|
||||
AND guest_os.display_name = guest_os_display_name
|
||||
AND NOT EXISTS (SELECT 1
|
||||
FROM cloud.guest_os_hypervisor as hypervisor
|
||||
WHERE hypervisor_type = guest_os_hypervisor_hypervisor_type
|
||||
AND hypervisor_version = guest_os_hypervisor_hypervisor_version
|
||||
AND hypervisor.guest_os_id = guest_os.id
|
||||
AND hypervisor.guest_os_name = guest_os_hypervisor_guest_os_name)
|
||||
;END;
|
||||
@ -0,0 +1,27 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- in cloud
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200),
|
||||
IN in_column_name VARCHAR(200),
|
||||
IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,27 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_KEY`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_KEY` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
, IN in_key_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' ADD KEY ') ; SET @ddl = CONCAT(@ddl, ' ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', in_key_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,26 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- Idempotent ADD UNIQUE INDEX
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_ADD_UNIQUE_INDEX`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_ADD_UNIQUE_INDEX` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_index_name VARCHAR(200)
|
||||
, IN in_index_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD UNIQUE INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', in_index_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,26 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- Idempotent ADD UNIQUE KEY
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_key_name VARCHAR(200)
|
||||
, IN in_key_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD UNIQUE KEY ', in_key_name); SET @ddl = CONCAT(@ddl, ' ', in_key_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,27 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- in usage Idempotent CHANGE COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_CHANGE_COLUMN`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_CHANGE_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_new_name VARCHAR(200)
|
||||
, IN in_column_new_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1054 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'CHANGE COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_new_name); SET @ddl = CONCAT(@ddl, ' ', in_column_new_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,27 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
, IN in_index_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('CREATE UNIQUE INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', in_index_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,25 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY` (
|
||||
IN in_table_name VARCHAR(200),
|
||||
IN in_foreign_key_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1091, 1025 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' DROP FOREIGN KEY '); SET @ddl = CONCAT(@ddl, ' ', in_foreign_key_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,27 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- in cloud
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_INDEX`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_INDEX` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('DROP INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,48 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`(
|
||||
IN in_hypervisor_type VARCHAR(32),
|
||||
IN in_hypervisor_version VARCHAR(32),
|
||||
IN in_guest_os_name VARCHAR(255),
|
||||
IN in_guest_os_id BIGINT(20) UNSIGNED,
|
||||
IN is_user_defined int(1) UNSIGNED)
|
||||
BEGIN
|
||||
IF NOT EXISTS ((SELECT * FROM `cloud`.`guest_os_hypervisor` WHERE
|
||||
hypervisor_type=in_hypervisor_type AND
|
||||
hypervisor_version=in_hypervisor_version AND
|
||||
guest_os_id = in_guest_os_id))
|
||||
THEN
|
||||
INSERT INTO `cloud`.`guest_os_hypervisor` (
|
||||
uuid,
|
||||
hypervisor_type,
|
||||
hypervisor_version,
|
||||
guest_os_name,
|
||||
guest_os_id,
|
||||
created,
|
||||
is_user_defined)
|
||||
VALUES (
|
||||
UUID(),
|
||||
in_hypervisor_type,
|
||||
in_hypervisor_version,
|
||||
in_guest_os_name,
|
||||
in_guest_os_id,
|
||||
utc_timestamp(),
|
||||
is_user_defined
|
||||
); END IF; END;;
|
||||
@ -0,0 +1,26 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- in usage
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,27 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- in usage Idempotent CHANGE COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_CHANGE_COLUMN`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_CHANGE_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_old_column_name VARCHAR(200)
|
||||
, IN in_new_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' CHANGE COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_old_column_name); SET @ddl = CONCAT(@ddl, ' ', in_new_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -0,0 +1,25 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
-- in usage
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_DROP_INDEX`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_DROP_INDEX` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('DROP INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
@ -19,51 +19,6 @@
|
||||
-- Schema upgrade from 4.10.0.0 to 4.11.0.0
|
||||
--;
|
||||
|
||||
--;
|
||||
-- Stored procedure to do idempotent column add;
|
||||
--;
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_foreign_key_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' DROP FOREIGN KEY '); SET @ddl = CONCAT(@ddl, ' ', in_foreign_key_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_INDEX`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_INDEX` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('DROP INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_CREATE_UNIQUE_INDEX` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
, IN in_index_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('CREATE UNIQUE INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', in_index_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Add For VPC flag
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','for_vpc', 'INT(1) NOT NULL DEFAULT 0');
|
||||
|
||||
|
||||
@ -123,20 +123,6 @@ CREATE VIEW `cloud`.`service_offering_view` AS
|
||||
GROUP BY
|
||||
`service_offering`.`id`;
|
||||
|
||||
--;
|
||||
-- Stored procedure to do idempotent column add;
|
||||
-- This is copied from schema-41000to41100.sql
|
||||
--;
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200),
|
||||
IN in_column_name VARCHAR(200),
|
||||
IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.account','created', 'datetime DEFAULT NULL COMMENT ''date created'' AFTER `state` ');
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.domain','created', 'datetime DEFAULT NULL COMMENT ''date created'' AFTER `next_child_seq` ');
|
||||
@ -730,39 +716,6 @@ ALTER TABLE `cloud`.`annotations` ADD COLUMN `admins_only` tinyint(1) unsigned N
|
||||
-- Add uuid for ssh keypairs
|
||||
ALTER TABLE `cloud`.`ssh_keypairs` ADD COLUMN `uuid` varchar(40) AFTER `id`;
|
||||
|
||||
-- PR#4699 Drop the procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` if it already exist.
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING`;
|
||||
|
||||
-- PR#4699 Create the procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` to add guest_os and guest_os_hypervisor mapping.
|
||||
CREATE PROCEDURE `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` (
|
||||
IN guest_os_category_id bigint(20) unsigned,
|
||||
IN guest_os_display_name VARCHAR(255),
|
||||
IN guest_os_hypervisor_hypervisor_type VARCHAR(32),
|
||||
IN guest_os_hypervisor_hypervisor_version VARCHAR(32),
|
||||
IN guest_os_hypervisor_guest_os_name VARCHAR(255)
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO cloud.guest_os (uuid, category_id, display_name, created)
|
||||
SELECT UUID(), guest_os_category_id, guest_os_display_name, now()
|
||||
FROM DUAL
|
||||
WHERE not exists( SELECT 1
|
||||
FROM cloud.guest_os
|
||||
WHERE cloud.guest_os.category_id = guest_os_category_id
|
||||
AND cloud.guest_os.display_name = guest_os_display_name)
|
||||
|
||||
; INSERT INTO cloud.guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created)
|
||||
SELECT UUID(), guest_os_hypervisor_hypervisor_type, guest_os_hypervisor_hypervisor_version, guest_os_hypervisor_guest_os_name, guest_os.id, now()
|
||||
FROM cloud.guest_os
|
||||
WHERE guest_os.category_id = guest_os_category_id
|
||||
AND guest_os.display_name = guest_os_display_name
|
||||
AND NOT EXISTS (SELECT 1
|
||||
FROM cloud.guest_os_hypervisor as hypervisor
|
||||
WHERE hypervisor_type = guest_os_hypervisor_hypervisor_type
|
||||
AND hypervisor_version = guest_os_hypervisor_hypervisor_version
|
||||
AND hypervisor.guest_os_id = guest_os.id
|
||||
AND hypervisor.guest_os_name = guest_os_hypervisor_guest_os_name)
|
||||
;END;
|
||||
|
||||
-- PR#4699 Call procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` to add new data to guest_os and guest_os_hypervisor.
|
||||
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (10, 'Ubuntu 20.04 LTS', 'KVM', 'default', 'Ubuntu 20.04 LTS');
|
||||
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (10, 'Ubuntu 21.04', 'KVM', 'default', 'Ubuntu 21.04');
|
||||
|
||||
@ -21,60 +21,6 @@
|
||||
|
||||
ALTER TABLE `cloud`.`vm_work_job` ADD COLUMN `secondary_object` char(100) COMMENT 'any additional item that must be checked during queueing' AFTER `vm_instance_id`;
|
||||
|
||||
-- Stored procedures to handle cloud and cloud_schema changes
|
||||
|
||||
-- Idempotent ADD COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent ADD COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent DROP INDEX
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_DROP_INDEX`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_DROP_INDEX` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1091 BEGIN END; SET @ddl = CONCAT('DROP INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', ' ON ') ; SET @ddl = CONCAT(@ddl, ' ', in_table_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent ADD UNIQUE INDEX
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_ADD_UNIQUE_INDEX`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_ADD_UNIQUE_INDEX` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_index_name VARCHAR(200)
|
||||
, IN in_index_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD UNIQUE INDEX ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', in_index_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent CHANGE COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_CHANGE_COLUMN`;
|
||||
CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_CHANGE_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_old_column_name VARCHAR(200)
|
||||
, IN in_new_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' CHANGE COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_old_column_name); SET @ddl = CONCAT(@ddl, ' ', in_new_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Invoke stored procedures to add primary keys on missing tables
|
||||
|
||||
-- Add PK to cloud.op_user_stats_log
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.op_user_stats_log', 'id', 'BIGINT(20) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)');
|
||||
|
||||
|
||||
@ -219,21 +219,6 @@ CREATE VIEW `cloud`.`service_offering_view` AS
|
||||
`service_offering`.`id`;
|
||||
|
||||
|
||||
--;
|
||||
-- Stored procedure to do idempotent column add;
|
||||
-- This is copied from schema-41000to41100.sql
|
||||
--;
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200),
|
||||
IN in_column_name VARCHAR(200),
|
||||
IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes','external_uuid', 'VARCHAR(40) DEFAULT null ');
|
||||
|
||||
DROP VIEW IF EXISTS `cloud`.`volume_view`;
|
||||
@ -937,35 +922,5 @@ INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(uuid, hypervisor_type, hype
|
||||
-- Copy XenServer 8.2.0 hypervisor guest OS mappings to XenServer 8.2.1
|
||||
INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) SELECT UUID(),'Xenserver', '8.2.1', guest_os_name, guest_os_id, utc_timestamp(), 0 FROM `cloud`.`guest_os_hypervisor` WHERE hypervisor_type='Xenserver' AND hypervisor_version='8.2.0';
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING`;
|
||||
CREATE PROCEDURE `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` (
|
||||
IN guest_os_category_id bigint(20) unsigned,
|
||||
IN guest_os_display_name VARCHAR(255),
|
||||
IN guest_os_hypervisor_hypervisor_type VARCHAR(32),
|
||||
IN guest_os_hypervisor_hypervisor_version VARCHAR(32),
|
||||
IN guest_os_hypervisor_guest_os_name VARCHAR(255)
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO cloud.guest_os (uuid, category_id, display_name, created)
|
||||
SELECT UUID(), guest_os_category_id, guest_os_display_name, now()
|
||||
FROM DUAL
|
||||
WHERE not exists( SELECT 1
|
||||
FROM cloud.guest_os
|
||||
WHERE cloud.guest_os.category_id = guest_os_category_id
|
||||
AND cloud.guest_os.display_name = guest_os_display_name)
|
||||
|
||||
; INSERT INTO cloud.guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created)
|
||||
SELECT UUID(), guest_os_hypervisor_hypervisor_type, guest_os_hypervisor_hypervisor_version, guest_os_hypervisor_guest_os_name, guest_os.id, now()
|
||||
FROM cloud.guest_os
|
||||
WHERE guest_os.category_id = guest_os_category_id
|
||||
AND guest_os.display_name = guest_os_display_name
|
||||
AND NOT EXISTS (SELECT 1
|
||||
FROM cloud.guest_os_hypervisor as hypervisor
|
||||
WHERE hypervisor_type = guest_os_hypervisor_hypervisor_type
|
||||
AND hypervisor_version = guest_os_hypervisor_hypervisor_version
|
||||
AND hypervisor.guest_os_id = guest_os.id
|
||||
AND hypervisor.guest_os_name = guest_os_hypervisor_guest_os_name)
|
||||
;END;
|
||||
|
||||
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (2, 'Debian GNU/Linux 11 (64-bit)', 'XenServer', '8.2.1', 'Debian Bullseye 11');
|
||||
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (2, 'Debian GNU/Linux 11 (32-bit)', 'XenServer', '8.2.1', 'Debian Bullseye 11');
|
||||
|
||||
@ -214,16 +214,6 @@ CREATE VIEW `cloud`.`domain_router_view` AS
|
||||
and async_job.instance_type = 'DomainRouter'
|
||||
and async_job.job_status = 0;
|
||||
|
||||
-- Idempotent ADD COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Add passphrase table
|
||||
CREATE TABLE IF NOT EXISTS `cloud`.`passphrase` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
@ -433,45 +423,6 @@ WHERE roles.role_type != 'Admin' AND roles.is_default = 1 AND role_perm.rule = '
|
||||
|
||||
-- VM autoscaling
|
||||
|
||||
-- Idempotent ADD COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent RENAME COLUMN
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_CHANGE_COLUMN`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_CHANGE_COLUMN` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_column_name VARCHAR(200)
|
||||
, IN in_column_new_name VARCHAR(200)
|
||||
, IN in_column_new_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1054 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'CHANGE COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_new_name); SET @ddl = CONCAT(@ddl, ' ', in_column_new_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent ADD UNIQUE KEY
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_key_name VARCHAR(200)
|
||||
, IN in_key_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD UNIQUE KEY ', in_key_name); SET @ddl = CONCAT(@ddl, ' ', in_key_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Idempotent DROP FOREIGN KEY
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`;
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY` (
|
||||
IN in_table_name VARCHAR(200)
|
||||
, IN in_foreign_key_name VARCHAR(200)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE CONTINUE HANDLER FOR 1091, 1025 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' DROP FOREIGN KEY '); SET @ddl = CONCAT(@ddl, ' ', in_foreign_key_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
-- Add column 'supports_vm_autoscaling' to 'network_offerings' table
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings', 'supports_vm_autoscaling', 'boolean default false');
|
||||
@ -1186,16 +1137,6 @@ CREATE TABLE IF NOT EXISTS `cloud`.`tungsten_lb_health_monitor` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
--- #6888 add index to speed up querying IPs in the network-tab
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_KEY`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_KEY` (
|
||||
IN in_index_name VARCHAR(200)
|
||||
, IN in_table_name VARCHAR(200)
|
||||
, IN in_key_definition VARCHAR(1000)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' ADD KEY ') ; SET @ddl = CONCAT(@ddl, ' ', in_index_name); SET @ddl = CONCAT(@ddl, ' ', in_key_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||
|
||||
CALL `cloud`.`IDEMPOTENT_ADD_KEY`('i_user_ip_address_state','user_ip_address', '(state)');
|
||||
|
||||
|
||||
@ -19,42 +19,6 @@
|
||||
-- Schema upgrade from 4.9.1.0 to 4.9.2.0;
|
||||
--;
|
||||
|
||||
--;
|
||||
-- Stored procedure to do idempotent insert;
|
||||
--;
|
||||
|
||||
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`;
|
||||
|
||||
CREATE PROCEDURE `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`(
|
||||
IN in_hypervisor_type VARCHAR(32),
|
||||
IN in_hypervisor_version VARCHAR(32),
|
||||
IN in_guest_os_name VARCHAR(255),
|
||||
IN in_guest_os_id BIGINT(20) UNSIGNED,
|
||||
IN is_user_defined int(1) UNSIGNED)
|
||||
BEGIN
|
||||
IF NOT EXISTS ((SELECT * FROM `cloud`.`guest_os_hypervisor` WHERE
|
||||
hypervisor_type=in_hypervisor_type AND
|
||||
hypervisor_version=in_hypervisor_version AND
|
||||
guest_os_id = in_guest_os_id))
|
||||
THEN
|
||||
INSERT INTO `cloud`.`guest_os_hypervisor` (
|
||||
uuid,
|
||||
hypervisor_type,
|
||||
hypervisor_version,
|
||||
guest_os_name,
|
||||
guest_os_id,
|
||||
created,
|
||||
is_user_defined)
|
||||
VALUES (
|
||||
UUID(),
|
||||
in_hypervisor_type,
|
||||
in_hypervisor_version,
|
||||
in_guest_os_name,
|
||||
in_guest_os_id,
|
||||
utc_timestamp(),
|
||||
is_user_defined
|
||||
); END IF; END;;
|
||||
|
||||
CALL `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`('Xenserver', '7.0.0', 'CentOS 4.5 (32-bit)', 1, 0);
|
||||
CALL `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`('Xenserver', '7.0.0', 'CentOS 4.6 (32-bit)', 2, 0);
|
||||
CALL `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`('Xenserver', '7.0.0', 'CentOS 4.7 (32-bit)', 3, 0);
|
||||
@ -234,5 +198,3 @@ CALL `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`('Xenserver', '7.0.0'
|
||||
|
||||
CALL `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`('Xenserver', '7.0.0', 'Ubuntu Trusty Tahr 14.04', 255, 0);
|
||||
CALL `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`('Xenserver', '7.0.0', 'Ubuntu Trusty Tahr 14.04', 256, 0);
|
||||
|
||||
DROP PROCEDURE `cloud`.`IDEMPOTENT_INSERT_GUESTOS_HYPERVISOR_MAPPING`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user