Export users 500k+ lines, seed, supervisord setup

This commit is contained in:
Ilya Rogozhin
2026-06-09 18:52:21 +02:00
parent 299ab41b7d
commit 792e4d7f28
15 changed files with 469 additions and 223 deletions
@@ -26,6 +26,8 @@ class UserFactory extends Factory
{
return [
'name' => fake()->name(),
'surname' => fake()->lastName(),
'phone_number' => fake()->phoneNumber(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('surname')->after('name');
$table->string('phone_number')->after('surname');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('surname');
$table->dropColumn('phone_number');
});
}
};
@@ -15,11 +15,6 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
//
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$totalToCreate = 525000;
$chunkSize = 1000;
\Illuminate\Support\Facades\DB::disableQueryLog();
$this->command->getOutput()->progressStart($totalToCreate);
for ($i = 0; $i < $totalToCreate; $i += $chunkSize) {
$createCount = min($chunkSize, $totalToCreate - $i);
User::factory($createCount)->create();
$this->command->getOutput()->progressAdvance($createCount);
}
$this->command->getOutput()->progressFinish();
}
}