@@ -0,0 +1,47 @@
|
||||
<?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('quotation_exchange_rates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained()->restrictOnDelete();
|
||||
$table->foreignId('requisition_id')->constrained()->restrictOnDelete();
|
||||
$table->foreignId('recorded_by')->constrained('users')->restrictOnDelete();
|
||||
$table->string('currency', 3);
|
||||
$table->string('rate', 20);
|
||||
$table->date('quoted_on');
|
||||
$table->string('source', 1000);
|
||||
$table->uuid('operation_id');
|
||||
$table->string('payload_hash', 64);
|
||||
$table->timestamp('created_at');
|
||||
$table->unique(['tenant_id', 'requisition_id', 'currency'], 'quotation_fx_process_currency');
|
||||
$table->unique(['tenant_id', 'operation_id'], 'quotation_fx_operation');
|
||||
});
|
||||
Schema::table('quotations', function (Blueprint $table) {
|
||||
$table->json('exchange_basis')->nullable();
|
||||
});
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
DB::unprepared("CREATE TRIGGER quotation_fx_no_update BEFORE UPDATE ON quotation_exchange_rates BEGIN SELECT RAISE(ABORT, 'Frozen process exchange rate'); END");
|
||||
DB::unprepared("CREATE TRIGGER quotation_fx_no_delete BEFORE DELETE ON quotation_exchange_rates BEGIN SELECT RAISE(ABORT, 'Frozen process exchange rate'); END");
|
||||
} elseif (DB::getDriverName() === 'pgsql') {
|
||||
DB::unprepared("CREATE FUNCTION quotation_fx_immutable() RETURNS trigger LANGUAGE plpgsql AS \$\$ BEGIN RAISE EXCEPTION 'Frozen process exchange rate'; END \$\$");
|
||||
DB::unprepared('CREATE TRIGGER quotation_fx_immutable BEFORE UPDATE OR DELETE ON quotation_exchange_rates FOR EACH ROW EXECUTE FUNCTION quotation_fx_immutable()');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('quotations', fn (Blueprint $table) => $table->dropColumn('exchange_basis'));
|
||||
Schema::dropIfExists('quotation_exchange_rates');
|
||||
if (DB::getDriverName() === 'pgsql') {
|
||||
DB::unprepared('DROP FUNCTION IF EXISTS quotation_fx_immutable()');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
Schema::table('supplier_bank_details', function (Blueprint $table) {
|
||||
// NULL is the entire existing version chain. No historical account is revived.
|
||||
$table->uuid('account_key')->nullable();
|
||||
$table->index(['tenant_id', 'supplier_id', 'account_key', 'revision'], 'supplier_bank_account_versions');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
throw new LogicException('Preservar identidades, versões bancárias e validações.');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user