2015-03-17 10:11:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
|
|
|
|
class UniqueEmailAndNameUserFields extends AbstractMigration
|
|
|
|
{
|
|
|
|
public function up()
|
|
|
|
{
|
2018-02-23 11:40:56 +01:00
|
|
|
$table = $this->table('user');
|
2016-05-07 08:43:21 +02:00
|
|
|
|
2018-02-23 11:40:56 +01:00
|
|
|
if (!$table->hasIndex('email')) {
|
|
|
|
$table->addIndex('email', ['unique' => true])->save();
|
2016-05-05 18:33:12 +02:00
|
|
|
}
|
2016-05-07 08:43:21 +02:00
|
|
|
|
2018-02-23 11:40:56 +01:00
|
|
|
if (!$table->hasIndex('name')) {
|
|
|
|
$table->addIndex('name', ['unique' => true])->save();
|
2016-05-05 18:33:12 +02:00
|
|
|
}
|
2015-03-17 10:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down()
|
|
|
|
{
|
2018-02-23 11:40:56 +01:00
|
|
|
$table = $this->table('user');
|
2016-05-07 08:43:21 +02:00
|
|
|
|
2018-02-23 11:40:56 +01:00
|
|
|
if ($table->hasIndex('email')) {
|
|
|
|
$table->removeIndex(['email'])->save();
|
2016-05-05 18:33:12 +02:00
|
|
|
}
|
2016-05-07 08:43:21 +02:00
|
|
|
|
2018-02-23 11:40:56 +01:00
|
|
|
if ($table->hasIndex('name')) {
|
|
|
|
$table->removeIndex(['name'])->save();
|
2016-05-05 18:33:12 +02:00
|
|
|
}
|
2015-03-17 10:11:05 +01:00
|
|
|
}
|
|
|
|
}
|