Browse Source
Fix #1315 "Ugly" migration fix for MariaDB after a beavior change in a minor release, dropping and recreating the foreign key
Fix #1315 "Ugly" migration fix for MariaDB after a beavior change in a minor release, dropping and recreating the foreign key
New migration to sync up a forgotten table during that fixed migrationpull/1356/head
4 changed files with 127 additions and 6 deletions
-
68database/migrations/20180510141439_change_length_contacts_id.php
-
8database/migrations/20180612215122_update_unique_constraint_sessions.php
-
51database/migrations/20240827184020_change_encrypted_passwords_user_id_length.php
-
6src/Movim/Migration.php
@ -0,0 +1,51 @@ |
|||
<?php |
|||
|
|||
use Movim\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
|
|||
class ChangeEncryptedPasswordsUserIdLength extends Migration |
|||
{ |
|||
public function up() |
|||
{ |
|||
$this->disableForeignKeyCheck(); |
|||
$this->dropMySQLForeignKeys(); |
|||
|
|||
$this->schema->table('encrypted_passwords', function (Blueprint $table) { |
|||
$table->string('user_id', 256)->change(); |
|||
}); |
|||
|
|||
$this->recreateMySQLForeignKeys(); |
|||
$this->enableForeignKeyCheck(); |
|||
} |
|||
|
|||
public function down() |
|||
{ |
|||
$this->disableForeignKeyCheck(); |
|||
$this->dropMySQLForeignKeys(); |
|||
|
|||
$this->schema->table('encrypted_passwords', function (Blueprint $table) { |
|||
$table->string('user_id', 64)->change(); |
|||
}); |
|||
|
|||
$this->recreateMySQLForeignKeys(); |
|||
$this->enableForeignKeyCheck(); |
|||
} |
|||
|
|||
private function dropMySQLForeignKeys() |
|||
{ |
|||
if ($this->schema->getConnection()->getDriverName() == 'mysql') { |
|||
$this->schema->table('encrypted_passwords', function (Blueprint $table) { |
|||
$table->dropForeign('encrypted_passwords_user_id_foreign'); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
private function recreateMySQLForeignKeys() |
|||
{ |
|||
if ($this->schema->getConnection()->getDriverName() == 'mysql') { |
|||
$this->schema->table('encrypted_passwords', function (Blueprint $table) { |
|||
$table->foreign('user_id')->references('id')->on('users'); |
|||
}); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue