From ab39035af0718b4094c6de8c0ef1664482c5a961 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Wed, 17 Feb 2021 16:35:57 -0300 Subject: [PATCH 1/6] Add new registers in guest_os --- .../META-INF/db/schema-41510to41600.sql | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql index eec9bcd671b3..2c0882dced3a 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql @@ -303,3 +303,44 @@ from -- Update name for global configuration user.vm.readonly.ui.details Update configuration set name='user.vm.readonly.details' where name='user.vm.readonly.ui.details'; + +-- PR#4699 Create a temporary table to use as a list of new guest_os to insert. +CREATE TEMPORARY TABLE temp_new_guest_os_to_insert (name varchar(50)); + +-- PR#4699 Populate the temporary table with the new guest_os to insert. +INSERT INTO temp_new_guest_os_to_insert (name) +VALUES +('Ubuntu 20.04 LTS'), +('Ubuntu 21.04'), +('pfSense 2.4'), +('OpenBSD 6.7'), +('OpenBSD 6.8'), +('AlmaLinux 8.3'); + +-- PR#4699 Insert the new guest_os if they do not already exists in the table. +INSERT INTO cloud.guest_os (uuid, category_id, display_name, created, is_user_defined) +SELECT UUID(), '1', new_guest_os.name, now(), '0' +FROM temp_new_guest_os_to_insert AS new_guest_os +WHERE NOT EXISTS (SELECT 1 + FROM cloud.guest_os + WHERE cloud.guest_os.category_id = 1 + AND cloud.guest_os.is_user_defined = 0 + AND cloud.guest_os.display_name = new_guest_os.name); + +-- PR#4699 Insert the new guest_os_hypervisor if they do not already exists in the table. +INSERT INTO cloud.guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) +SELECT UUID(), 'KVM', 'default', new_guest_os.name, guest_os.id, now(), 0 +FROM temp_new_guest_os_to_insert AS new_guest_os +INNER JOIN cloud.guest_os AS guest_os ON (guest_os.category_id = 1 + AND guest_os.is_user_defined = 0 + AND guest_os.display_name = new_guest_os.name) +WHERE NOT EXISTS (SELECT 1 + FROM cloud.guest_os_hypervisor AS hypervisor + WHERE hypervisor.hypervisor_type = 'KVM' + AND hypervisor.hypervisor_version = 'default' + AND hypervisor.guest_os_id = guest_os.id + AND hypervisor.guest_os_name = new_guest_os.name); + +-- PR#4699 Drop temporary table after use it. +DROP TEMPORARY TABLE temp_new_guest_os_to_insert; + From 7c865ca7d9be781e7ec96d53448101c5f4b660ad Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Thu, 18 Feb 2021 14:54:55 -0300 Subject: [PATCH 2/6] Create a procedure to insert guest_os and guest_os_hypervisor data --- .../META-INF/db/schema-41510to41600.sql | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql index 2c0882dced3a..04ed66cc3abd 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql @@ -304,43 +304,42 @@ from -- Update name for global configuration user.vm.readonly.ui.details Update configuration set name='user.vm.readonly.details' where name='user.vm.readonly.ui.details'; --- PR#4699 Create a temporary table to use as a list of new guest_os to insert. -CREATE TEMPORARY TABLE temp_new_guest_os_to_insert (name varchar(50)); +-- 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 Populate the temporary table with the new guest_os to insert. -INSERT INTO temp_new_guest_os_to_insert (name) -VALUES -('Ubuntu 20.04 LTS'), -('Ubuntu 21.04'), -('pfSense 2.4'), -('OpenBSD 6.7'), -('OpenBSD 6.8'), -('AlmaLinux 8.3'); - --- PR#4699 Insert the new guest_os if they do not already exists in the table. -INSERT INTO cloud.guest_os (uuid, category_id, display_name, created, is_user_defined) -SELECT UUID(), '1', new_guest_os.name, now(), '0' -FROM temp_new_guest_os_to_insert AS new_guest_os -WHERE NOT EXISTS (SELECT 1 - FROM cloud.guest_os - WHERE cloud.guest_os.category_id = 1 - AND cloud.guest_os.is_user_defined = 0 - AND cloud.guest_os.display_name = new_guest_os.name); - --- PR#4699 Insert the new guest_os_hypervisor if they do not already exists in the table. -INSERT INTO cloud.guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) -SELECT UUID(), 'KVM', 'default', new_guest_os.name, guest_os.id, now(), 0 -FROM temp_new_guest_os_to_insert AS new_guest_os -INNER JOIN cloud.guest_os AS guest_os ON (guest_os.category_id = 1 - AND guest_os.is_user_defined = 0 - AND guest_os.display_name = new_guest_os.name) -WHERE NOT EXISTS (SELECT 1 - FROM cloud.guest_os_hypervisor AS hypervisor - WHERE hypervisor.hypervisor_type = 'KVM' - AND hypervisor.hypervisor_version = 'default' - AND hypervisor.guest_os_id = guest_os.id - AND hypervisor.guest_os_name = new_guest_os.name); - --- PR#4699 Drop temporary table after use it. -DROP TEMPORARY TABLE temp_new_guest_os_to_insert; +-- 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() + 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 (1, 'Ubuntu 20.04 LTS', 'KVM', 'default', 'Ubuntu 20.04 LTS'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'Ubuntu 21.04', 'KVM', 'default', 'Ubuntu 21.04'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'pfSense 2.4', 'KVM', 'default', 'pfSense 2.4'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'OpenBSD 6.7', 'KVM', 'default', 'OpenBSD 6.7'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'OpenBSD 6.8', 'KVM', 'default', 'OpenBSD 6.8'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'AlmaLinux 8.3', 'KVM', 'default', 'AlmaLinux 8.3'); \ No newline at end of file From 1f0b2357fed9f4b734c51261f50a666365c2dc88 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Thu, 25 Feb 2021 09:58:17 -0300 Subject: [PATCH 3/6] Remove ';' as the last char of the procedure --- .../src/main/resources/META-INF/db/schema-41510to41600.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql index 04ed66cc3abd..19f574380f86 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql @@ -334,7 +334,7 @@ BEGIN 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; +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 (1, 'Ubuntu 20.04 LTS', 'KVM', 'default', 'Ubuntu 20.04 LTS'); @@ -342,4 +342,4 @@ CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'Ubuntu 21.04', 'KVM', 'default', ' CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'pfSense 2.4', 'KVM', 'default', 'pfSense 2.4'); CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'OpenBSD 6.7', 'KVM', 'default', 'OpenBSD 6.7'); CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'OpenBSD 6.8', 'KVM', 'default', 'OpenBSD 6.8'); -CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'AlmaLinux 8.3', 'KVM', 'default', 'AlmaLinux 8.3'); \ No newline at end of file +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'AlmaLinux 8.3', 'KVM', 'default', 'AlmaLinux 8.3'); From 6aaf1c2ff3f252ef179ced18d2919e2cdfd9dc8d Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Thu, 25 Feb 2021 10:17:10 -0300 Subject: [PATCH 4/6] Set the right category_id on guest_os Ubuntu 20.04 LTS - Ubuntu - Linux Ubuntu 21.04 - Ubuntu - Linux pfSense 2.4 - FreeBSD - Unix OpenBSD 6.7 - Unix OpenBSD 6.8 - Unix AlmaLinux 8.3 - CentOS --- .../main/resources/META-INF/db/schema-41510to41600.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql index 19f574380f86..6a749ae9eda0 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql @@ -337,9 +337,9 @@ BEGIN 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 (1, 'Ubuntu 20.04 LTS', 'KVM', 'default', 'Ubuntu 20.04 LTS'); -CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'Ubuntu 21.04', 'KVM', 'default', 'Ubuntu 21.04'); -CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'pfSense 2.4', 'KVM', 'default', 'pfSense 2.4'); -CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'OpenBSD 6.7', 'KVM', 'default', 'OpenBSD 6.7'); -CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'OpenBSD 6.8', 'KVM', 'default', 'OpenBSD 6.8'); +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'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (9, 'pfSense 2.4', 'KVM', 'default', 'pfSense 2.4'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (9, 'OpenBSD 6.7', 'KVM', 'default', 'OpenBSD 6.7'); +CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (9, 'OpenBSD 6.8', 'KVM', 'default', 'OpenBSD 6.8'); CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'AlmaLinux 8.3', 'KVM', 'default', 'AlmaLinux 8.3'); From fb26e239bab80d74838283e86fd4dd831816c3a4 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Mon, 1 Mar 2021 11:40:46 -0300 Subject: [PATCH 5/6] Fix SQL line's last character --- .../main/resources/META-INF/db/schema-41510to41600.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql index 6a749ae9eda0..ac192216fc0d 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql @@ -321,9 +321,9 @@ BEGIN 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); + 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) +; 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 @@ -333,8 +333,8 @@ BEGIN 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 + 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'); From 73c503c2348c531d16fda9c27cc366a14382d042 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:23:05 -0300 Subject: [PATCH 6/6] Add from with dummy table --- .../src/main/resources/META-INF/db/schema-41510to41600.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql index 4a36730d7372..1518cb6ae03f 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql @@ -525,7 +525,8 @@ CREATE PROCEDURE `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` ( ) BEGIN INSERT INTO cloud.guest_os (uuid, category_id, display_name, created) - SELECT UUID(), guest_os_category_id, guest_os_display_name, now() + 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