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)'); + } +}