first commit
This commit is contained in:
55
database/factories/MigrationScheduleFactory.php
Normal file
55
database/factories/MigrationScheduleFactory.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\MigrationSchedule;
|
||||
use App\Models\SourceDatabase;
|
||||
use App\Models\TargetDatabase;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\MigrationSchedule>
|
||||
*/
|
||||
class MigrationScheduleFactory extends Factory
|
||||
{
|
||||
protected $model = MigrationSchedule::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->sentence(3),
|
||||
'source_database_id' => SourceDatabase::factory(),
|
||||
'target_database_id' => TargetDatabase::factory(),
|
||||
'tables' => [1, 2, 3],
|
||||
'cron_expression' => fake()->randomElement(['0 * * * *', '0 0 * * *', '0 0 * * 0']),
|
||||
'timezone' => 'UTC',
|
||||
'is_active' => true,
|
||||
'run_in_parallel' => false,
|
||||
'batch_size' => 1000,
|
||||
'truncate_before_migration' => false,
|
||||
'create_indexes_after' => true,
|
||||
'description' => fake()->optional()->sentence(),
|
||||
];
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function daily(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'cron_expression' => '0 0 * * *',
|
||||
]);
|
||||
}
|
||||
|
||||
public function hourly(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'cron_expression' => '0 * * * *',
|
||||
]);
|
||||
}
|
||||
}
|
||||
36
database/factories/SourceDatabaseFactory.php
Normal file
36
database/factories/SourceDatabaseFactory.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SourceDatabase;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SourceDatabase>
|
||||
*/
|
||||
class SourceDatabaseFactory extends Factory
|
||||
{
|
||||
protected $model = SourceDatabase::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->company() . ' DB',
|
||||
'host' => fake()->randomElement(['localhost', '127.0.0.1', 'db.example.com']),
|
||||
'port' => 5432,
|
||||
'database' => fake()->unique()->word() . '_db',
|
||||
'username' => fake()->userName(),
|
||||
'password' => fake()->password(16),
|
||||
'driver' => 'pgsql',
|
||||
'description' => fake()->optional()->sentence(),
|
||||
'is_active' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
36
database/factories/TargetDatabaseFactory.php
Normal file
36
database/factories/TargetDatabaseFactory.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\TargetDatabase;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TargetDatabase>
|
||||
*/
|
||||
class TargetDatabaseFactory extends Factory
|
||||
{
|
||||
protected $model = TargetDatabase::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->company() . ' Target DB',
|
||||
'host' => fake()->randomElement(['localhost', '127.0.0.1', 'target.db.example.com']),
|
||||
'port' => 5432,
|
||||
'database' => fake()->unique()->word() . '_target_db',
|
||||
'username' => fake()->userName(),
|
||||
'password' => fake()->password(16),
|
||||
'driver' => 'pgsql',
|
||||
'description' => fake()->optional()->sentence(),
|
||||
'is_active' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
45
database/factories/UserFactory.php
Normal file
45
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user