lots o updates

This commit is contained in:
2023-04-18 21:47:44 +10:00
parent b53fca9648
commit 36c71da4bb
29 changed files with 656 additions and 547 deletions

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::table('users')->whereNull('phone')->update(['phone' => '']);
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->default("")->nullable(false)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->nullable(true)->change();
});
}
};

View File

@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('display_name')->default("");
});
// Update existing rows with display_name
DB::table('users')->select('id', 'username')->orderBy('id')->chunk(100, function ($users) {
foreach ($users as $user) {
DB::table('users')->where('id', $user->id)->update(['display_name' => $user->username]);
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('display_name');
});
}
};