From 7f180eb6d9bcada7274d42bac429d6e1015a794d Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 7 Mar 2026 18:47:28 -0500 Subject: [PATCH] Migrate Invoice Quote Recurring Invoice Items to their new respecting tables --- admin/database_updates.php | 101 +++++++++++++++++++++++++++++++++- db.sql | 2 +- includes/database_version.php | 2 +- 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/admin/database_updates.php b/admin/database_updates.php index 80be56c1..86d0a061 100644 --- a/admin/database_updates.php +++ b/admin/database_updates.php @@ -4240,10 +4240,105 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.1'"); } - // if (CURRENT_DATABASE_VERSION == '2.4.1') { - // // Insert queries here required to update to DB version 2.4.2 + if (CURRENT_DATABASE_VERSION == '2.4.1') { + + // Migrate Items + mysqli_query($mysqli, " + INSERT INTO `recurring_invoice_items` ( + `item_name`, + `item_description`, + `item_quantity`, + `item_price`, + `item_subtotal`, + `item_tax`, + `item_total`, + `item_order`, + `item_created_at`, + `item_updated_at`, + `item_archived_at`, + `item_tax_id`, + `item_product_id`, + `item_recurring_invoice_id` + ) + SELECT + `item_name`, + `item_description`, + `item_quantity`, + `item_price`, + `item_subtotal`, + `item_tax`, + `item_total`, + `item_order`, + `item_created_at`, + `item_updated_at`, + `item_archived_at`, + `item_tax_id`, + `item_product_id`, + `item_recurring_invoice_id` + FROM `invoice_items` + WHERE `item_recurring_invoice_id` != 0 + "); + + mysqli_query($mysqli, " + INSERT INTO `quote_items` ( + `item_name`, + `item_description`, + `item_quantity`, + `item_price`, + `item_subtotal`, + `item_tax`, + `item_total`, + `item_order`, + `item_created_at`, + `item_updated_at`, + `item_archived_at`, + `item_tax_id`, + `item_product_id`, + `item_quote_id` + ) + SELECT + `item_name`, + `item_description`, + `item_quantity`, + `item_price`, + `item_subtotal`, + `item_tax`, + `item_total`, + `item_order`, + `item_created_at`, + `item_updated_at`, + `item_archived_at`, + `item_tax_id`, + `item_product_id`, + `item_quote_id` + FROM `invoice_items` + WHERE `item_quote_id` != 0 + "); + + mysqli_query($mysqli, " + DELETE FROM `invoice_items` + WHERE `item_recurring_invoice_id` != 0 + "); + + mysqli_query($mysqli, " + DELETE FROM `invoice_items` + WHERE `item_quote_id` != 0 + "); + + mysqli_query($mysqli, " + ALTER TABLE `invoice_items` + DROP COLUMN `item_quote_id`, + DROP COLUMN `item_recurring_invoice_id` + "); + + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.2'"); + + } + // + // // if (CURRENT_DATABASE_VERSION == '2.4.2') { + // // Insert queries here required to update to DB version 2.4.3 // // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.2'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.4.3'"); // } } else { diff --git a/db.sql b/db.sql index fbbbf534..997b7e53 100644 --- a/db.sql +++ b/db.sql @@ -3123,4 +3123,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2026-03-07 18:20:44 +-- Dump completed on 2026-03-07 18:46:25 diff --git a/includes/database_version.php b/includes/database_version.php index 0b24573c..d848c3e8 100644 --- a/includes/database_version.php +++ b/includes/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "2.4.1"); +DEFINE("LATEST_DATABASE_VERSION", "2.4.2");