Fix broken users table in database causing validation errors.

This commit is contained in:
Dane Everitt 2018-02-25 16:08:01 -06:00
parent 8daf97021a
commit 4cfb8941d5
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RemoveDefaultNullValueOnTable extends Migration
{
/**
* Run the migrations.
*
* @throws \Exception
* @throws \Throwable
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('external_id')->default(null)->change();
});
DB::transaction(function () {
DB::table('users')->where('external_id', '=' , 'NULL')->update([
'external_id' => null,
]);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// This should not be rolled back.
}
}

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DefineUniqueIndexOnUsersExternalId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->index(['external_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropIndex(['external_id']);
});
}
}