@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('order_cancellation_policies', function (Blueprint $t) {
|
||||
$t->id();
|
||||
$t->foreignId('tenant_id')->constrained();
|
||||
$t->foreignId('created_by')->constrained('users');
|
||||
$t->unsignedInteger('revision');
|
||||
$t->string('status')->default('pending');
|
||||
$t->string('mode');
|
||||
$t->boolean('enabled');
|
||||
$t->date('valid_from');
|
||||
$t->date('valid_until');
|
||||
$t->text('reason');
|
||||
$t->timestamp('decided_at')->nullable();
|
||||
$t->timestamps();
|
||||
$t->unique(['tenant_id', 'revision']);
|
||||
});
|
||||
Schema::create('order_cancellation_policy_reviews', function (Blueprint $t) {
|
||||
$t->id();
|
||||
$t->foreignId('tenant_id')->constrained();
|
||||
$t->foreignId('purchase_control_policy_id')->constrained('order_cancellation_policies');
|
||||
$t->foreignId('reviewed_by')->constrained('users');
|
||||
$t->string('decision');
|
||||
$t->text('reason');
|
||||
$t->timestamp('created_at');
|
||||
$t->unique(['purchase_control_policy_id', 'reviewed_by'], 'order_cancel_policy_reviewer_unique');
|
||||
});
|
||||
Schema::create('order_cancellations', function (Blueprint $t) {
|
||||
$t->id();
|
||||
$t->foreignId('tenant_id')->constrained();
|
||||
$t->foreignId('purchase_order_id')->constrained();
|
||||
$t->foreignId('policy_id')->constrained('order_cancellation_policies');
|
||||
$t->foreignId('created_by')->constrained('users');
|
||||
$t->uuid('operation_key');
|
||||
$t->string('input_hash', 64);
|
||||
$t->string('basis_hash', 64);
|
||||
$t->json('snapshot');
|
||||
$t->string('status')->default('pending');
|
||||
$t->text('reason');
|
||||
$t->text('evidence');
|
||||
$t->foreignId('reviewed_by')->nullable()->constrained('users');
|
||||
$t->text('review_reason')->nullable();
|
||||
$t->timestamp('reviewed_at')->nullable();
|
||||
$t->foreignId('revised_requisition_id')->nullable()->constrained('requisitions');
|
||||
$t->timestamps();
|
||||
$t->unique(['tenant_id', 'created_by', 'operation_key'], 'order_cancel_operation_unique');
|
||||
});
|
||||
foreach (['pending', 'approved'] as $state) {
|
||||
DB::statement("CREATE UNIQUE INDEX order_cancel_{$state}_unique ON order_cancellations (purchase_order_id) WHERE status = '{$state}'");
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
throw new LogicException('Preservar políticas, pedidos e decisões de cancelamento.');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
foreach (['tenants', 'suppliers'] as $table) {
|
||||
Schema::table($table, function (Blueprint $blueprint) {
|
||||
$blueprint->json('geography_reference')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
throw new LogicException('Preservar referências geográficas: reversão exige plano explícito.');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
foreach (['warehouses', 'equipment'] as $table) {
|
||||
Schema::table($table, function (Blueprint $blueprint) {
|
||||
$blueprint->json('geography_reference')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
throw new LogicException('Preservar localizações operacionais; reversão exige plano explícito.');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user