From 459a438de3f18fa419349de08f8801cc85580356 Mon Sep 17 00:00:00 2001 From: Aimeos Date: Fri, 23 Apr 2021 10:26:31 +0200 Subject: [PATCH] Fixed migration for PostgreSQL --- .../setup/CustomerRemoveConstraints.php | 51 +++++-------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/lib/custom/setup/CustomerRemoveConstraints.php b/lib/custom/setup/CustomerRemoveConstraints.php index 700dad2..130204e 100644 --- a/lib/custom/setup/CustomerRemoveConstraints.php +++ b/lib/custom/setup/CustomerRemoveConstraints.php @@ -41,52 +41,25 @@ public function getPostDependencies() : array */ public function migrate() { - $schema = $this->getSchema( 'db-customer' ); + $this->msg( sprintf( 'Remove constraints in users related tables' ), 0, '' ); + + $rname = 'db-customer'; + $schema = $this->getSchema( $rname ); if( $schema->tableExists( 'users' ) && $schema->columnExists( 'users', 'id' ) && $schema->getColumnDetails( 'users', 'id' )->getDataType() !== 'bigint' ) { - $this->msg( sprintf( 'Remove constraints in users related tables' ), 0 ); - $this->status( '' ); - + $conn = $this->acquire( $rname ); + $dbal = $conn->getRawObject(); - $this->msg( 'Checking constraint in "users_address"', 1 ); - - if( $schema->constraintExists( 'users_address', 'fk_lvuad_pid' ) ) - { - $this->execute( 'ALTER TABLE "users_address" DROP FOREIGN KEY "fk_lvuad_pid"', 'db-customer' ); - $this->status( 'done' ); - } - else - { - $this->status( 'OK' ); + if( !( $dbal instanceof \Doctrine\DBAL\Connection ) ) { + throw new \Aimeos\MW\Setup\Exception( 'Not a DBAL connection' ); } - - $this->msg( 'Checking constraint in "users_list"', 1 ); - - if( $schema->constraintExists( 'users_list', 'fk_lvuli_pid' ) ) - { - $this->execute( 'ALTER TABLE "users_list" DROP FOREIGN KEY "fk_lvuli_pid"', 'db-customer' ); - $this->status( 'done' ); - } - else - { - $this->status( 'OK' ); - } - - - $this->msg( 'Checking constraint in "users_property"', 1 ); - - if( $schema->constraintExists( 'users_property', 'fk_lvupr_pid' ) ) - { - $this->execute( 'ALTER TABLE "users_property" DROP FOREIGN KEY "fk_lvupr_pid"', 'db-customer' ); - $this->status( 'done' ); - } - else - { - $this->status( 'OK' ); - } + $dbalManager = $dbal->getSchemaManager(); + $dbalManager->tryMethod( 'dropForeignKey', 'fk_lvuad_pid', 'users_address' ); + $dbalManager->tryMethod( 'dropForeignKey', 'fk_lvupr_pid', 'users_property' ); + $dbalManager->tryMethod( 'dropForeignKey', 'fk_lvuli_pid', 'users_list' ); } } }