This commit is contained in:
2026-11-02 08:10:00 +02:00
parent 504b01b244
commit b44378b899
14 changed files with 655 additions and 121 deletions
@@ -2,24 +2,39 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::create('warehouse_reservations',function(Blueprint $table) {
$table->id(); $table->foreignId('tenant_id')->constrained()->restrictOnDelete();
return new class extends Migration
{
public function up(): void
{
Schema::create('warehouse_reservations', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->restrictOnDelete();
$table->foreignId('warehouse_request_id')->constrained()->restrictOnDelete();
$table->unsignedInteger('line_index'); $table->foreignId('stock_item_id')->constrained()->restrictOnDelete();
$table->unsignedInteger('line_index');
$table->foreignId('stock_item_id')->constrained()->restrictOnDelete();
$table->foreignId('warehouse_id')->constrained()->restrictOnDelete();
$table->foreignId('authorization_event_id')->constrained('warehouse_request_events')->restrictOnDelete();
$table->foreignId('actor_id')->constrained('users')->restrictOnDelete();
$table->uuid('command_key'); $table->string('kind'); $table->bigInteger('quantity_milli'); $table->timestampTz('created_at');
$table->unique(['warehouse_request_id','line_index','command_key','kind'],'warehouse_reservation_command_unique');
$table->index(['tenant_id','stock_item_id','warehouse_id']);
$table->uuid('command_key');
$table->string('kind');
$table->bigInteger('quantity_milli');
$table->timestampTz('created_at');
$table->unique(['warehouse_request_id', 'line_index', 'command_key', 'kind'], 'warehouse_reservation_command_unique');
$table->index(['tenant_id', 'stock_item_id', 'warehouse_id']);
});
if(DB::getDriverName()==='sqlite')DB::unprepared("CREATE TRIGGER warehouse_reservations_update BEFORE UPDATE ON warehouse_reservations BEGIN SELECT RAISE(ABORT, 'Preservar reservas'); END; CREATE TRIGGER warehouse_reservations_delete BEFORE DELETE ON warehouse_reservations BEGIN SELECT RAISE(ABORT, 'Preservar reservas'); END;");
if(DB::getDriverName()==='pgsql')DB::unprepared("CREATE FUNCTION preserve_warehouse_reservations() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'Preservar reservas'; END $$; CREATE TRIGGER warehouse_reservations_immutable BEFORE UPDATE OR DELETE ON warehouse_reservations FOR EACH ROW EXECUTE FUNCTION preserve_warehouse_reservations();");
if (DB::getDriverName() === 'sqlite') {
DB::unprepared("CREATE TRIGGER warehouse_reservations_update BEFORE UPDATE ON warehouse_reservations BEGIN SELECT RAISE(ABORT, 'Preservar reservas'); END; CREATE TRIGGER warehouse_reservations_delete BEFORE DELETE ON warehouse_reservations BEGIN SELECT RAISE(ABORT, 'Preservar reservas'); END;");
}
if (DB::getDriverName() === 'pgsql') {
DB::unprepared("CREATE FUNCTION preserve_warehouse_reservations() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'Preservar reservas'; END $$; CREATE TRIGGER warehouse_reservations_immutable BEFORE UPDATE OR DELETE ON warehouse_reservations FOR EACH ROW EXECUTE FUNCTION preserve_warehouse_reservations();");
}
}
public function down(): void
{
Schema::dropIfExists('warehouse_reservations');
}
public function down(): void { Schema::dropIfExists('warehouse_reservations'); }
};