commit melhorias compras3
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-22 10:56:58 +02:00
parent 4fac443dda
commit efd97e265b
130 changed files with 8917 additions and 363 deletions
@@ -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('tenants', function (Blueprint $table) {
$table->json('company_details')->nullable();
});
}
public function down(): void
{
Schema::table('tenants', function (Blueprint $table) {
$table->dropColumn('company_details');
});
}
};
@@ -0,0 +1,53 @@
<?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
{
$this->guardSqlite();
Schema::table('requisitions', function (Blueprint $table) {
$table->foreignId('cost_center_id')->nullable()->change();
$table->date('needed_by')->nullable()->change();
$table->text('justification')->nullable()->change();
$table->unsignedBigInteger('subtotal_minor')->nullable()->change();
$table->unsignedBigInteger('tax_minor')->nullable()->change();
$table->unsignedBigInteger('total_minor')->nullable()->change();
$table->json('draft_input')->nullable();
});
if (DB::getDriverName() === 'pgsql') {
DB::statement("ALTER TABLE requisitions ADD CONSTRAINT requisitions_complete_before_submission CHECK (status IN ('draft', 'cancelled') OR (cost_center_id IS NOT NULL AND needed_by IS NOT NULL AND justification IS NOT NULL AND subtotal_minor IS NOT NULL AND tax_minor IS NOT NULL AND total_minor IS NOT NULL AND draft_input IS NULL))");
}
}
public function down(): void
{
if (DB::table('requisitions')->whereNotNull('draft_input')->orWhereNull('cost_center_id')->orWhereNull('needed_by')->orWhereNull('justification')->orWhereNull('subtotal_minor')->orWhereNull('tax_minor')->orWhereNull('total_minor')->exists()) {
throw new LogicException('Complete ou preserve os rascunhos antes de reverter a estrutura; não substituir dados em falta por valores fictícios.');
}
$this->guardSqlite();
if (DB::getDriverName() === 'pgsql') {
DB::statement('ALTER TABLE requisitions DROP CONSTRAINT requisitions_complete_before_submission');
}
Schema::table('requisitions', function (Blueprint $table) {
$table->foreignId('cost_center_id')->nullable(false)->change();
$table->date('needed_by')->nullable(false)->change();
$table->text('justification')->nullable(false)->change();
$table->unsignedBigInteger('subtotal_minor')->nullable(false)->change();
$table->unsignedBigInteger('tax_minor')->nullable(false)->change();
$table->unsignedBigInteger('total_minor')->nullable(false)->change();
$table->dropColumn('draft_input');
});
}
private function guardSqlite(): void
{
if (DB::getDriverName() === 'sqlite' && DB::table('requisitions')->exists()) {
throw new LogicException('Alteração de schema SQLite preenchido recusada para preservar as referências. O destino operacional e o ensaio de migração com dados são PostgreSQL; SQLite apenas em testes com schema vazio.');
}
}
};