From 0b2b10946fb1c59e9470f52a0d1b7ea954344ddd Mon Sep 17 00:00:00 2001 From: Marcos Oliveira Soares Date: Fri, 26 Apr 2024 00:32:38 -0300 Subject: [PATCH 1/5] Adjusting the migration to get the table name from the model --- .../2014_10_12_000000_create_users_table.php | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 6863b0a..ded912f 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -5,6 +5,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; +use Modules\Auth\Models\User; return new class() extends Migration { @@ -13,18 +14,20 @@ */ public function up(): void { - Schema::create('users', function (Blueprint $table) { - $table->id(); - $table->uuid(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->string('role'); - $table->boolean('active')->default(true); - $table->rememberToken(); - $table->timestamps(); - }); + if (! Schema::hasTable(User::getModelTable())) { + Schema::create(User::getModelTable(), function (Blueprint $table) { + $table->id(); + $table->uuid(); + $table->string('name'); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->string('role'); + $table->boolean('active')->default(true); + $table->rememberToken(); + $table->timestamps(); + }); + } } /** @@ -32,6 +35,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('users'); + Schema::dropIfExists(User::getModelTable()); } }; From c170bf71ab52ea1abd09575d29237de75502db6b Mon Sep 17 00:00:00 2001 From: Marcos Oliveira Soares Date: Fri, 26 Apr 2024 00:33:13 -0300 Subject: [PATCH 2/5] Adjusting the filling of the initial database load for the User model --- database/seeders/DatabaseSeeder.php | 10 ++------ database/seeders/UserSeeder.php | 38 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 database/seeders/UserSeeder.php diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 28d6d45..699b30a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,10 +4,7 @@ namespace Database\Seeders; -// use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; -use Modules\Auth\Models\User; -use Modules\Auth\Support\Role; class DatabaseSeeder extends Seeder { @@ -16,11 +13,8 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - User::query()->create([ - 'name' => 'Admin', - 'email' => 'admin@example.com', - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'role' => Role::ADMIN->value, + $this->call([ + UserSeeder::class ]); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php new file mode 100644 index 0000000..393ce1f --- /dev/null +++ b/database/seeders/UserSeeder.php @@ -0,0 +1,38 @@ +first(); + + if ($user) { + $user->update([ + 'name' => 'Admin', + 'password' => Hash::make('password'), + 'role' => Role::ADMIN->value, + ]); + } else { + User::create([ + 'email' => 'admin@example.com', + 'name' => 'Admin', + 'password' => Hash::make('password'), + 'role' => Role::ADMIN->value, + ]); + } + } +} From 222f6d59067d4342c1abe44335eede5602a9a77d Mon Sep 17 00:00:00 2001 From: Marcos Oliveira Soares Date: Fri, 26 Apr 2024 00:33:36 -0300 Subject: [PATCH 3/5] Adjusting docker-compose to include container readiness check --- docker-compose.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 1010bd8..ecde3a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,15 @@ services: - "${APP_EXTERNAL_PORT_SSL}:443" networks: - laravel-exa + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + depends_on: + - redis + - mysql # REDIS redis: @@ -32,6 +41,12 @@ services: - ./docker/redis/data:/data networks: - laravel-exa + healthcheck: + test: ["CMD", "redis-cli", "-h", "${REDIS_HOST:-localhost}", "-p", "${REDIS_PORT}:-6379", "-a", "${REDIS_PASSWORD:-null}", "ping"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s # MYSQL mysql: @@ -48,6 +63,12 @@ services: MYSQL_USER: ${DB_USERNAME} networks: - laravel-exa + healthcheck: + test: ["CMD-SHELL", "mysqladmin ping -h localhost -u${DB_USER:-exa} -p${DB_PASSWORD:-secret}"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s # MAILPIT mailpit: From 3e93d0d7978d7931220fb961ba474d8df97e7641 Mon Sep 17 00:00:00 2001 From: Marcos Oliveira Soares Date: Fri, 26 Apr 2024 10:28:03 -0300 Subject: [PATCH 4/5] Resolved requested changes --- database/seeders/DatabaseSeeder.php | 2 +- database/seeders/UserSeeder.php | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 699b30a..3619ab1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,7 +14,7 @@ class DatabaseSeeder extends Seeder public function run(): void { $this->call([ - UserSeeder::class + UserSeeder::class, ]); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 393ce1f..3e2d1e2 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -13,26 +13,26 @@ class UserSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ public function run(): void { - $user = User::where('email', 'admin@example.com')->first(); + $user = User::query()->where('email', 'admin@example.com')->first(); - if ($user) { - $user->update([ - 'name' => 'Admin', - 'password' => Hash::make('password'), - 'role' => Role::ADMIN->value, - ]); - } else { - User::create([ + if (! $user) { + User::query()->create([ 'email' => 'admin@example.com', 'name' => 'Admin', 'password' => Hash::make('password'), 'role' => Role::ADMIN->value, ]); + + return; } + + $user->update([ + 'name' => 'Admin', + 'password' => Hash::make('password'), + 'role' => Role::ADMIN->value, + ]); } } From 58f3726063eedbca8a8495f79ced2c2565eff6c5 Mon Sep 17 00:00:00 2001 From: Marcos Oliveira Soares Date: Fri, 26 Apr 2024 10:39:03 -0300 Subject: [PATCH 5/5] Resolved requested changes --- database/seeders/UserSeeder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 3e2d1e2..1bc588e 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -16,7 +16,9 @@ class UserSeeder extends Seeder */ public function run(): void { - $user = User::query()->where('email', 'admin@example.com')->first(); + $user = User::query() + ->where('email', 'admin@example.com') + ->first(); if (! $user) { User::query()->create([