From c972cdfaf4cb65f8f1c60f20e24e3312cccd0fba Mon Sep 17 00:00:00 2001 From: Steve Ireland Date: Mon, 1 Jul 2024 13:25:11 -0400 Subject: [PATCH] Correct a constraint that wasn't using the full unique key based on composite keys. (#4014) --- ...20240630000001_fix_keys_for_db_upgrade.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/Database/Migrations/20240630000001_fix_keys_for_db_upgrade.php diff --git a/app/Database/Migrations/20240630000001_fix_keys_for_db_upgrade.php b/app/Database/Migrations/20240630000001_fix_keys_for_db_upgrade.php new file mode 100644 index 000000000..2d929400b --- /dev/null +++ b/app/Database/Migrations/20240630000001_fix_keys_for_db_upgrade.php @@ -0,0 +1,30 @@ +db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') . ' DROP FOREIGN KEY ospos_sales_items_taxes_ibfk_1'); + $this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') + . ' ADD CONSTRAINT ospos_sales_items_taxes_ibfk_1 FOREIGN KEY (sale_id, item_id, line) ' + . ' REFERENCES ' . $this->db->prefixTable('sales_items') . ' (sale_id, item_id, line)'); + } + + /** + * Revert a migration step. + */ + public function down(): void + { + $this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') . ' DROP CONSTRAINT ospos_sales_items_taxes_ibfk_1'); + $this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') + . ' ADD CONSTRAINT ospos_sales_items_taxes_ibfk_1 FOREIGN KEY (sale_id) ' + . ' REFERENCES ' . $this->db->prefixTable('sales_items') . ' (sale_id)'); + } +}