php-censor/src/Migrations/20150324174958_unique_email_and_name_user_fields.php
2018-03-09 13:46:18 +07:00

33 lines
711 B
PHP

<?php
use Phinx\Migration\AbstractMigration;
class UniqueEmailAndNameUserFields extends AbstractMigration
{
public function up()
{
$table = $this->table('user');
if (!$table->hasIndex('email')) {
$table->addIndex('email', ['unique' => true])->save();
}
if (!$table->hasIndex('name')) {
$table->addIndex('name', ['unique' => true])->save();
}
}
public function down()
{
$table = $this->table('user');
if ($table->hasIndex('email')) {
$table->removeIndex(['email'])->save();
}
if ($table->hasIndex('name')) {
$table->removeIndex(['name'])->save();
}
}
}