Skip to content

Commit

Permalink
Allow migration to unsigned of existing users_* tables
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jan 24, 2019
1 parent 182951a commit d9c32bc
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions lib/custom/setup/UsersRemoveSignedConstraints.php
@@ -0,0 +1,91 @@
<?php

/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2019
*/


namespace Aimeos\MW\Setup\Task;


/**
* Removes signed constraints from users_* tables before migrating to unsigned
*/
class UsersRemoveSignedConstraints extends \Aimeos\MW\Setup\Task\Base
{
/**
* Returns the list of task names which this task depends on.
*
* @return string[] List of task names
*/
public function getPreDependencies()
{
return [];
}


/**
* Returns the list of task names which depends on this task.
*
* @return array List of task names
*/
public function getPostDependencies()
{
return ['TablesCreateMShop'];
}


/**
* Executes the task
*/
public function migrate()
{
$sql = 'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = \'users\' AND COLUMN_NAME = \'id\'';

if( $this->getValue( $sql, 'COLUMN_TYPE', 'db-customer' ) === 'int(10)' )
{
$this->msg( sprintf( 'Remove signed constraints in users related tables' ), 0 );
$this->status( '' );


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


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

0 comments on commit d9c32bc

Please sign in to comment.