From ba9c80cd7db33e5fdda85c9de273deb89a198256 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 16 Aug 2023 17:56:32 -0400 Subject: [PATCH] Feature: Recurring Expenses - Part 1 - Initial DB Structure Created --- database_updates.php | 34 +++++++++++++++++++++++++++++++--- database_version.php | 2 +- db.sql | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/database_updates.php b/database_updates.php index 2458f3fa..71b0038b 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1187,11 +1187,39 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.6.7'"); } - //if (CURRENT_DATABASE_VERSION == '0.6.7') { - //Insert queries here required to update to DB version 0.6.8 + if (CURRENT_DATABASE_VERSION == '0.6.7') { + + mysqli_query($mysqli, "CREATE TABLE `recurring_expenses` ( + `recurring_expense_id` INT(11) NOT NULL AUTO_INCREMENT, + `recurring_expense_frequency` TINYINT(1) NOT NULL, + `recurring_expense_day` TINYINT DEFAULT NULL, + `recurring_expense_month` TINYINT DEFAULT NULL, + `recurring_expense_last_sent` DATE NULL DEFAULT NULL, + `recurring_expense_next_date` DATE NOT NULL, + `recurring_expense_status` TINYINT(1) NOT NULL DEFAULT 1, + `recurring_expense_description` TEXT DEFAULT NULL, + `recurring_expense_amount` DECIMAL(15,2) NOT NULL, + `recurring_expense_payment_method` VARCHAR(200) DEFAULT NULL, + `recurring_expense_payment_reference` VARCHAR(200) DEFAULT NULL, + `recurring_expense_currency_code` VARCHAR(200) NOT NULL, + `recurring_expense_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(), + `recurring_expense_updated_at` DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `recurring_expense_archived_at` DATETIME DEFAULT NULL, + `recurring_expense_vendor_id` INT(11) NOT NULL, + `recurring_expense_client_id` INT(11) NOT NULL DEFAULT 0, + `recurring_expense_category_id` INT(11) NOT NULL, + `recurring_expense_account_id` INT(11) NOT NULL, + PRIMARY KEY (`recurring_expense_id`) + )"); + + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.6.8'"); + } + + //if (CURRENT_DATABASE_VERSION == '0.6.8') { + //Insert queries here required to update to DB version 0.6.9 // Then, update the database to the next sequential version - //mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.6.8'"); + //mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.6.9'"); //} } else { diff --git a/database_version.php b/database_version.php index 5dbf1e07..f362bdf4 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.6.7"); +DEFINE("LATEST_DATABASE_VERSION", "0.6.8"); diff --git a/db.sql b/db.sql index a5b864d2..497f898d 100644 --- a/db.sql +++ b/db.sql @@ -934,6 +934,37 @@ CREATE TABLE `recurring` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `recurring_expenses` +-- + +DROP TABLE IF EXISTS `recurring_expenses`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `recurring_expenses` ( + `recurring_expense_id` int(11) NOT NULL AUTO_INCREMENT, + `recurring_expense_frequency` tinyint(1) NOT NULL, + `recurring_expense_day` tinyint(4) DEFAULT NULL, + `recurring_expense_month` tinyint(4) DEFAULT NULL, + `recurring_expense_last_sent` date DEFAULT NULL, + `recurring_expense_next_date` date NOT NULL, + `recurring_expense_status` tinyint(1) NOT NULL DEFAULT 1, + `recurring_expense_description` text DEFAULT NULL, + `recurring_expense_amount` decimal(15,2) NOT NULL, + `recurring_expense_payment_method` varchar(200) DEFAULT NULL, + `recurring_expense_payment_reference` varchar(200) DEFAULT NULL, + `recurring_expense_currency_code` varchar(200) NOT NULL, + `recurring_expense_created_at` datetime NOT NULL DEFAULT current_timestamp(), + `recurring_expense_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), + `recurring_expense_archived_at` datetime DEFAULT NULL, + `recurring_expense_vendor_id` int(11) NOT NULL, + `recurring_expense_client_id` int(11) NOT NULL DEFAULT 0, + `recurring_expense_category_id` int(11) NOT NULL, + `recurring_expense_account_id` int(11) NOT NULL, + PRIMARY KEY (`recurring_expense_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `revenues` -- @@ -1638,4 +1669,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-08-16 13:24:12 +-- Dump completed on 2023-08-16 17:56:01