make app database
This commit is contained in:
@@ -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::create('loan_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->boolean('is_active')->default(true)->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loan_types');
|
||||
}
|
||||
};
|
||||
@@ -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::create('stage_definitions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->boolean('is_active')->default(true)->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('stage_definitions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use App\Domain\Loan\Enums\WorkflowConfigurationStatus;
|
||||
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.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('workflow_configurations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('loan_type_id')->constrained()->restrictOnDelete();
|
||||
$table->string('name');
|
||||
$table->unsignedInteger('version');
|
||||
$table->string('status')->default(WorkflowConfigurationStatus::Draft->value)->index();
|
||||
$table->timestamp('published_at')->nullable()->index();
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['loan_type_id', 'version']);
|
||||
$table->unique(['id', 'loan_type_id']);
|
||||
});
|
||||
|
||||
if (DB::getDriverName() === 'pgsql') {
|
||||
DB::statement("CREATE UNIQUE INDEX workflow_configurations_one_published_per_loan_type ON workflow_configurations (loan_type_id) WHERE status = 'PUBLISHED'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('workflow_configurations');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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::create('workflow_configuration_steps', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('workflow_configuration_id')->constrained()->restrictOnDelete();
|
||||
$table->foreignId('stage_definition_id')->constrained()->restrictOnDelete();
|
||||
$table->unsignedInteger('position');
|
||||
$table->json('rules');
|
||||
$table->boolean('is_enabled')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['workflow_configuration_id', 'position']);
|
||||
$table->unique(['workflow_configuration_id', 'stage_definition_id']);
|
||||
$table->unique(['id', 'workflow_configuration_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('workflow_configuration_steps');
|
||||
}
|
||||
};
|
||||
49
database/migrations/2026_07_22_114910_create_loans_table.php
Normal file
49
database/migrations/2026_07_22_114910_create_loans_table.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use App\Domain\Loan\Enums\LoanStatus;
|
||||
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::create('loans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('public_id')->unique();
|
||||
$table->string('customer_id')->index();
|
||||
$table->foreignId('loan_type_id');
|
||||
$table->foreignId('workflow_configuration_id');
|
||||
$table->foreignId('current_workflow_configuration_step_id')->nullable();
|
||||
$table->unsignedBigInteger('amount');
|
||||
$table->string('phone', 11);
|
||||
$table->unsignedBigInteger('monthly_income');
|
||||
$table->unsignedInteger('credit_score');
|
||||
$table->boolean('has_guarantor');
|
||||
$table->string('status')->default(LoanStatus::Submitted->value)->index();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign(['workflow_configuration_id', 'loan_type_id'])
|
||||
->references(['id', 'loan_type_id'])
|
||||
->on('workflow_configurations')
|
||||
->restrictOnDelete();
|
||||
$table->foreign(['current_workflow_configuration_step_id', 'workflow_configuration_id'])
|
||||
->references(['id', 'workflow_configuration_id'])
|
||||
->on('workflow_configuration_steps')
|
||||
->restrictOnDelete();
|
||||
$table->index('current_workflow_configuration_step_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loans');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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::create('loan_histories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('loan_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('workflow_configuration_step_id')->constrained()->restrictOnDelete();
|
||||
$table->string('stage_code');
|
||||
$table->json('rules_snapshot');
|
||||
$table->string('result');
|
||||
$table->string('reason');
|
||||
$table->timestamp('executed_at')->index();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['loan_id', 'workflow_configuration_step_id']);
|
||||
$table->index(['loan_id', 'executed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loan_histories');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user