Skip to content

Commit

Permalink
Fix #90. Upgrade script: Remove constraint fk_msprost_stock_warehouse…
Browse files Browse the repository at this point in the history
…id (#91)

in addition to fk_msprost_whid before renaming `warehouseid` column.
This existence of this foreign key is mysterious. A possibility is
a wrong execution order of the update scripts.
It is determined from pre and post dependencies (see comments in #90).

As the error is far down (out of immediate sight of the updating admin)
it may easily go unnoticed.
This commit serves as a precaution to prevent fatal consequencies of
such early termination of update script(s) (no more scripts are
run after the failure).
  • Loading branch information
faerietree authored and aimeos committed May 4, 2017
1 parent 880b363 commit 1f5cba5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/mshoplib/setup/ProductRenameStockWarehouse.php
Expand Up @@ -16,6 +16,7 @@ class ProductRenameStockWarehouse extends \Aimeos\MW\Setup\Task\Base
{
private $stmts = array(
'constraint' => 'ALTER TABLE "mshop_product_stock" DROP FOREIGN KEY "fk_msprost_whid"',
'constraint2' => 'ALTER TABLE "mshop_product_stock" DROP FOREIGN KEY "fk_msprost_stock_warehouseid"',
'typeid' => 'ALTER TABLE "mshop_product_stock" CHANGE COLUMN "warehouseid" "typeid" INTEGER NOT NULL',
'table' => 'ALTER TABLE "mshop_product_stock_warehouse" RENAME TO "mshop_product_stock_type"',
);
Expand Down Expand Up @@ -76,6 +77,20 @@ public function migrate()
}


$this->msg( 'Drop "mshop_product_stock.fk_msprost_stock_warehouseid"', 1 );

if( $schema->tableExists( 'mshop_product_stock' )
&& $schema->constraintExists( 'mshop_product_stock', 'fk_msprost_stock_warehouseid' )
) {
$this->execute( $this->stmts['constraint2'], 'db-product' );
$this->status( 'done' );
}
else
{
$this->status( 'OK' );
}


$this->msg( 'Rename "mshop_product_stock.wareshouseid"', 1 );

if( $schema->tableExists( 'mshop_product_stock' )
Expand All @@ -102,4 +117,4 @@ public function migrate()
$this->status( 'OK' );
}
}
}
}

0 comments on commit 1f5cba5

Please sign in to comment.