Browse Source

Fix the latest migration for MySQL DB

pull/647/head
Timothée Jaussoin 8 years ago
parent
commit
5640c8e3c8
  1. 8
      database/migrations/20180510141439_change_length_contacts_id.php
  2. 14
      src/Movim/Migration.php

8
database/migrations/20180510141439_change_length_contacts_id.php

@ -7,6 +7,8 @@ class ChangeLengthContactsId extends Migration
{
public function up()
{
$this->disableForeignKeyCheck();
$this->schema->table('contacts', function(Blueprint $table) {
$table->string('id', 256)->change();
$table->string('nickname', 256)->change();
@ -49,10 +51,14 @@ class ChangeLengthContactsId extends Migration
$table->string('jidfrom', 256)->change();
$table->string('resource', 256)->change();
});
$this->enableForeignKeyCheck();
}
public function down()
{
$this->disableForeignKeyCheck();
$this->schema->table('contacts', function(Blueprint $table) {
$table->string('id', 64)->change();
$table->string('nickname', 64)->change();
@ -95,5 +101,7 @@ class ChangeLengthContactsId extends Migration
$table->string('jidfrom', 96)->change();
$table->string('resource', 96)->change();
});
$this->enableForeignKeyCheck();
}
}

14
src/Movim/Migration.php

@ -20,4 +20,18 @@ class Migration extends AbstractMigration
$this->schema = Capsule::schema();
}
public function enableForeignKeyCheck()
{
if ($this->schema->getConnection()->getDriverName() == 'mysql') {
$this->schema->getConnection()->unprepared('SET foreign_key_checks = 1');
}
}
public function disableForeignKeyCheck()
{
if ($this->schema->getConnection()->getDriverName() == 'mysql') {
$this->schema->getConnection()->unprepared('SET foreign_key_checks = 0');
}
}
}
Loading…
Cancel
Save