Skip to content

Commit

Permalink
Merge pull request #14 from msoares94/refactoring/migration
Browse files Browse the repository at this point in the history
Refactoring migration e seeder
  • Loading branch information
WendellAdriel authored Apr 26, 2024
2 parents 4c7a856 + 58f3726 commit e368835
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
29 changes: 16 additions & 13 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -13,25 +14,27 @@
*/
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();
});
}
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists(User::getModelTable());
}
};
10 changes: 2 additions & 8 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
]);
}
}
40 changes: 40 additions & 0 deletions database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Modules\Auth\Models\User;
use Modules\Auth\Support\Role;

class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$user = User::query()
->where('email', 'admin@example.com')
->first();

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,
]);
}
}
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit e368835

Please sign in to comment.