Repository navigation
feat(laravel): make the audit transaction requirement optional - #19
Merged
Merged
Conversation
LogsAudit and AuditOutbox::record() throw when a write runs outside an explicit transaction. That protects atomicity, but it blocks adoption in applications that save models outside transactions, such as cb3-backend replacing its spatie activity log. New setting traceflow.audit.require_transaction (TRACEFLOW_AUDIT_REQUIRE_TRANSACTION), default true, so existing installations keep the current behaviour. With false, a write outside a transaction stores the outbox row right after the model write (the same guarantee as an activity log written from model events); writes inside a transaction stay atomic. AuditOutbox::requireTransaction() still always enforces a transaction. Bumps the Laravel package to 2.8.0, the first release with the audit API. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LogsAuditandAuditOutbox::record()throw aLogicExceptionwhen a write runs outside an explicit transaction. That keeps the business write and its outbox row atomic, but it blocks adoption in applications that save models outside transactions. cb3-backend is the first case: it will replace its spatie activity log with the Traceflow audit log, and its models are saved from controllers, jobs, imports and webhooks without transactions.This adds an opt-in policy:
traceflow.audit.require_transaction(TRACEFLOW_AUDIT_REQUIRE_TRANSACTION), defaulttrue: existing installations keep the current behaviour.false:AuditOutbox::record()follows the same setting.AuditOutbox::requireTransaction()keeps always enforcing a transaction, for callers that rely on it. The trait andrecord()now go throughAuditOutbox::guardTransaction().composer.jsonversion 2.7.2 → 2.8.0. No tag contains the audit API yet (v2.7.2was created before it, and its split totraceflow-laravelfailed in May, so Composer only seesv2.7.1). After merge, tagv2.8.0sosplit-laravelpublishes it.Test plan
vendor/bin/phpunit --testsuite Unit: 155 tests pass (same 8 PHPUnit notices asmain)record()follows the policy;requireTransaction()still throws. The two behaviour tests fail without the change.pint --teston the changed filessrc/Auditv2.8.0after merge and checktraceflow-laravelgets the tag