From 1a0e5b916af322011f44f5c1b07ccd679b424aee Mon Sep 17 00:00:00 2001 From: objecttothis Date: Sat, 4 Feb 2023 16:36:06 +0400 Subject: [PATCH] Migrations fixes - Minor formating changes - Adding migration helper calls where needed - Adding locale helper calls where needed - Add use statement to tax_lib for sale_lib - pass gcaptcha enabled to the login view after checking to see if the key exists so that we don't get code errors before migrations 20170501150000 - Fixed getWhere in Appconfig model --- .../20210422000000_database_optimizations.php | 2 +- .../3.4.0_database_optimizations.sql | 45 ++++++++++++++++--- app/Models/Attribute.php | 11 ++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app/Database/Migrations/20210422000000_database_optimizations.php b/app/Database/Migrations/20210422000000_database_optimizations.php index b9478a7d7..231bfad1c 100644 --- a/app/Database/Migrations/20210422000000_database_optimizations.php +++ b/app/Database/Migrations/20210422000000_database_optimizations.php @@ -90,7 +90,7 @@ class Migration_database_optimizations extends Migration $builder->select("$column, attribute_id"); $builder->groupBy($column); $builder->having("COUNT($column) > 1"); - $duplicated_values = $builder->get('attribute_values'); + $duplicated_values = $builder->get(); foreach($duplicated_values->getResultArray() as $duplicated_value) { diff --git a/app/Database/Migrations/sqlscripts/3.4.0_database_optimizations.sql b/app/Database/Migrations/sqlscripts/3.4.0_database_optimizations.sql index 38b2e40f1..8306d019f 100644 --- a/app/Database/Migrations/sqlscripts/3.4.0_database_optimizations.sql +++ b/app/Database/Migrations/sqlscripts/3.4.0_database_optimizations.sql @@ -14,6 +14,10 @@ ALTER TABLE `ospos_attribute_links` ADD UNIQUE INDEX `attribute_links_uq2` (`ite ALTER TABLE `ospos_cash_up` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; #ospos_customers table +ALTER TABLE `ospos_customers` DROP FOREIGN KEY `ospos_customers_ibfk_1`; +ALTER TABLE `ospos_customers_points` DROP FOREIGN KEY `ospos_customers_points_ibfk_1`; +ALTER TABLE `ospos_sales` DROP FOREIGN KEY `ospos_sales_ibfk_2`; + DROP INDEX `person_id` ON `ospos_customers`; ALTER TABLE `ospos_customers` MODIFY `taxable` tinyint(1) DEFAULT 1 NOT NULL; ALTER TABLE `ospos_customers` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; @@ -21,6 +25,10 @@ ALTER TABLE `ospos_customers` MODIFY `discount_type` tinyint(1) DEFAULT 0 NOT NU ALTER TABLE `ospos_customers` ADD PRIMARY KEY(`person_id`); ALTER TABLE `ospos_customers` ADD INDEX(`company_name`); +ALTER TABLE `ospos_customers` ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people`(`person_id`); +ALTER TABLE `ospos_customers_points` ADD CONSTRAINT `ospos_customers_points_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_customers` (`person_id`); +ALTER TABLE `ospos_sales` ADD CONSTRAINT `ospos_sales_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `ospos_customers` (`person_id`); + #ospos_customers_packages table ALTER TABLE `ospos_customers_packages` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; @@ -29,11 +37,31 @@ ALTER TABLE `ospos_dinner_tables` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL ALTER TABLE `ospos_dinner_tables` ADD INDEX(`status`); #ospos_employees table +ALTER TABLE `ospos_sales_payments` DROP FOREIGN KEY `ospos_sales_payments_ibfk_2`; +ALTER TABLE `ospos_sales` DROP FOREIGN KEY `ospos_sales_ibfk_1`; +ALTER TABLE `ospos_receivings` DROP FOREIGN KEY `ospos_receivings_ibfk_1`; +ALTER TABLE `ospos_inventory` DROP FOREIGN KEY `ospos_inventory_ibfk_2`; +ALTER TABLE `ospos_grants` DROP FOREIGN KEY `ospos_grants_ibfk_2`; +ALTER TABLE `ospos_expenses` DROP FOREIGN KEY `ospos_expenses_ibfk_2`; +ALTER TABLE `ospos_employees` DROP FOREIGN KEY `ospos_employees_ibfk_1`; +ALTER TABLE `ospos_cash_up` DROP FOREIGN KEY `ospos_cash_up_ibfk_1`; +ALTER TABLE `ospos_cash_up` DROP FOREIGN KEY `ospos_cash_up_ibfk_2`; + DROP INDEX `person_id` ON `ospos_employees`; ALTER TABLE `ospos_employees` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_employees` MODIFY `hash_version` tinyint(1) DEFAULT 2 NOT NULL; ALTER TABLE `ospos_employees` ADD PRIMARY KEY(`person_id`); +ALTER TABLE `ospos_sales_payments` ADD CONSTRAINT `ospos_sales_payments_ibfk_2` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`); +ALTER TABLE `ospos_sales` ADD CONSTRAINT `ospos_sales_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`); +ALTER TABLE `ospos_receivings` ADD CONSTRAINT `ospos_receivings_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`); +ALTER TABLE `ospos_inventory` ADD CONSTRAINT `ospos_inventory_ibfk_2` FOREIGN KEY (`trans_user`) REFERENCES `ospos_employees` (`person_id`); +ALTER TABLE `ospos_grants` ADD CONSTRAINT `ospos_grants_ibfk_2` foreign key (`person_id`) references `ospos_employees` (`person_id`) ON DELETE CASCADE; +ALTER TABLE `ospos_expenses` ADD CONSTRAINT `ospos_expenses_ibfk_2` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`); +ALTER TABLE `ospos_employees` ADD CONSTRAINT `ospos_employees_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`); +ALTER TABLE `ospos_cash_up` ADD CONSTRAINT `ospos_cash_up_ibfk_1` FOREIGN KEY (`open_employee_id`) REFERENCES `ospos_employees` (`person_id`); +ALTER TABLE `ospos_cash_up` ADD CONSTRAINT `ospos_cash_up_ibfk_2` FOREIGN KEY (`close_employee_id`) REFERENCES `ospos_employees` (`person_id`); + #ospos_expenses table ALTER TABLE `ospos_expenses` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_expenses` ADD INDEX(`payment_type`); @@ -51,7 +79,7 @@ ALTER TABLE `ospos_items` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_items` MODIFY `stock_type` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_items` MODIFY `item_type` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_items` ADD INDEX(`deleted`, `item_type`); -ALTER TABLE `ospos_items` ADD INDEX(`PRIMARY`, `deleted`); +ALTER TABLE `ospos_items` ADD INDEX (`item_id`,`deleted`); ALTER TABLE `ospos_items` ADD UNIQUE INDEX `items_uq1` (`supplier_id`, `item_id`, `deleted`, `item_type`); #ospos_item_kits table @@ -60,9 +88,6 @@ ALTER TABLE `ospos_item_kits` MODIFY `price_option` tinyint(1) DEFAULT 0 NOT NUL ALTER TABLE `ospos_item_kits` MODIFY `print_option` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_item_kits` ADD INDEX(`name`,`description`); -#ospos_item_quantities table -ALTER TABLE `ospos_item_quantities` ADD INDEX(`PRIMARY`,`item_id`,`location_id`); - #ospos_people table ALTER TABLE `ospos_people` ADD INDEX(`first_name`, `last_name`, `email`, `phone_number`); @@ -94,6 +119,11 @@ ALTER TABLE `ospos_sessions` ADD INDEX(`ip_address`); ALTER TABLE `ospos_stock_locations` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; #ospos_suppliers table +ALTER TABLE `ospos_expenses` DROP FOREIGN KEY `ospos_expenses_ibfk_3`; +ALTER TABLE `ospos_items` DROP FOREIGN KEY `ospos_items_ibfk_1`; +ALTER TABLE `ospos_receivings` DROP FOREIGN KEY `ospos_receivings_ibfk_2`; +ALTER TABLE `ospos_suppliers` DROP FOREIGN KEY `ospos_suppliers_ibfk_1`; + DROP INDEX `person_id` ON `ospos_suppliers`; ALTER TABLE `ospos_suppliers` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_suppliers` MODIFY `category` tinyint(1) NOT NULL; @@ -101,6 +131,11 @@ ALTER TABLE `ospos_suppliers` ADD PRIMARY KEY(`person_id`); ALTER TABLE `ospos_suppliers` ADD INDEX(`category`); ALTER TABLE `ospos_suppliers` ADD INDEX(`company_name`, `deleted`); +ALTER TABLE `ospos_expenses` ADD CONSTRAINT `ospos_expenses_ibfk_3` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`); +ALTER TABLE `ospos_items` ADD CONSTRAINT `ospos_items_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`); +ALTER TABLE `ospos_receivings` ADD CONSTRAINT `ospos_receivings_ibfk_2` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`); +ALTER TABLE `ospos_suppliers` ADD CONSTRAINT `ospos_suppliers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`); + #ospos_tax_categories table ALTER TABLE `ospos_tax_categories` MODIFY `deleted` tinyint(1) DEFAULT 0 NOT NULL; ALTER TABLE `ospos_tax_categories` MODIFY `tax_group_sequence` tinyint(1) NOT NULL; @@ -114,4 +149,4 @@ ALTER TABLE `ospos_tax_jurisdictions` MODIFY `tax_group_sequence` tinyint(1) DEF ALTER TABLE `ospos_tax_jurisdictions` MODIFY `cascade_sequence` tinyint(1) DEFAULT 0 NOT NULL; #ospos_tax_rates table -ALTER TABLE `ospos_tax_rates` MODIFY `tax_rounding_code` tinyint(1) DEFAULT 0 NOT NULL; \ No newline at end of file +ALTER TABLE `ospos_tax_rates` MODIFY `tax_rounding_code` tinyint(1) DEFAULT 0 NOT NULL; diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 2fef29da7..910812179 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -784,13 +784,14 @@ class Attribute extends Model */ public function delete_orphaned_values(): bool { - $builder = $this->db->table('attribute_values'); - $builder->distinct()->select('attribute_id'); - $attribute_ids = $builder->getCompiledSelect('attribute_links'); + $subquery = $this->db->table('attribute_links') + ->distinct() + ->select('attribute_id'); $this->db->transStart(); - $builder->whereNotIn('attribute_id', $attribute_ids, FALSE); + $builder = $this->db->table('attribute_values'); + $builder->whereNotIn('attribute_id', $subquery, FALSE); $builder->delete(); $this->db->transComplete(); @@ -852,4 +853,4 @@ class Attribute extends Model return $builder->get()->getResultArray(); } -} \ No newline at end of file +}