d,6); DB::statement('ALTER TABLE permission_grants DROP CONSTRAINT permission_grants_scope_check'); DB::statement("ALTER TABLE permission_grants ADD CONSTRAINT permission_grants_scope_check CHECK (($old) OR (permission IN ('service_receivables.view','service_receivables.prepare','service_receivables.confirm','service_receivables.allocate','service_receivables.reconcile','service_receivables.correction_request','service_receivables.correction_approve') AND unit_id IS NOT NULL))"); DB::unprepared(file_get_contents(__DIR__.'/../sql/receivables.sql')); foreach (['sr_records','sr_effects','sr_commands','sr_events','sr_outbox','sr_deliveries'] as $table) { DB::statement("CREATE TRIGGER {$table}_immutable BEFORE UPDATE OR DELETE ON {$table} FOR EACH ROW EXECUTE FUNCTION sgf_append_only_audit()"); DB::statement("CREATE TRIGGER {$table}_test_only BEFORE INSERT ON {$table} FOR EACH ROW EXECUTE FUNCTION sgf_sr_test_insert()"); } } public function down(): void { throw new RuntimeException('Immutable history requires a reviewed preservation procedure.'); } };