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->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']); }); 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'); } };