mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2025-12-24 01:57:51 -05:00
Add check to migration to prevent errors (#4032)
* Add check to migration - Only drop the constraint if it exists. Signed-off-by: objecttothis <objecttothis@gmail.com> * Automatic bump of package-lock.json Signed-off-by: objecttothis <objecttothis@gmail.com> --------- Signed-off-by: objecttothis <objecttothis@gmail.com>
This commit is contained in:
@@ -11,7 +11,14 @@ class Migration_fix_keys_for_db_upgrade extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') . ' DROP FOREIGN KEY ospos_sales_items_taxes_ibfk_1');
|
||||
$checkSql = "SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = '" . $this->db->prefixTable('sales_items_taxes') . "' AND CONSTRAINT_NAME = 'ospos_sales_items_taxes_ibfk_1'";
|
||||
$foreignKeyExists = $this->db->query($checkSql)->getRow();
|
||||
|
||||
if($foreignKeyExists)
|
||||
{
|
||||
$this->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)');
|
||||
@@ -22,7 +29,14 @@ class Migration_fix_keys_for_db_upgrade extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_items_taxes') . ' DROP CONSTRAINT ospos_sales_items_taxes_ibfk_1');
|
||||
$checkSql = "SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = '" . $this->db->prefixTable('sales_items_taxes') . "' AND CONSTRAINT_NAME = 'ospos_sales_items_taxes_ibfk_1'";
|
||||
$foreignKeyExists = $this->db->query($checkSql)->getRow();
|
||||
|
||||
if($foreignKeyExists)
|
||||
{
|
||||
$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)');
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -18,9 +18,9 @@
|
||||
"bootstrap-tagsinput-2021": "^0.8.6",
|
||||
"bootstrap-toggle": "^2.2.2",
|
||||
"bootstrap3-dialog": "github:nakupanda/bootstrap3-dialog#master",
|
||||
"bootstrap5": "npm:bootstrap@^5.3.2",
|
||||
"bootstrap5": "npm:bootstrap@^5.3.3",
|
||||
"bootswatch": "^3.4.1",
|
||||
"bootswatch5": "npm:bootswatch@^5.3.2",
|
||||
"bootswatch5": "npm:bootswatch@^5.3.3",
|
||||
"chartist": "^0.11.4",
|
||||
"chartist-plugin-axistitle": "^0.0.7",
|
||||
"chartist-plugin-barlabels": "^0.0.5",
|
||||
|
||||
Reference in New Issue
Block a user