database-transactions
Skill4 starsChanged 5 months agoMITView on GitHub
Keep Laravel writes atomic and consistent with transactions, locks, retries, idempotency, side-effect boundaries, and after-commit dispatch.
In this repository75 other files it gives its agents.
- AGENTS.mdAGENTS.md
- templates/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- actions-and-servicesSkill
- ai-sdkSkill
- api-resources-and-paginationSkill
- api-surface-evolutionSkill
- architectureSkill
- blade-components-and-layoutsSkill
- brainstormingSkill
- code-review-requestsSkill
- complexity-guardrailsSkill
- config-env-storageSkill
- constants-and-configurationSkill
- controller-cleanupSkill
- controller-testsSkill
- custom-helpersSkill
- daily-workflowSkill
- data-chunking-large-datasetsSkill
- debugging-promptsSkill
- dependencies-trim-packagesSkill
- documentation-best-practicesSkill
- e2e-playwrightSkill
- effective-contextSkill
- eloquent-patternsSkill
- eloquent-relationshipsSkill
- exception-handling-and-loggingSkill
- executing-plansSkill
- extract-laravel-standardsSkill
- filesystem-uploadsSkill
- form-requestsSkill
- horizon-metrics-and-dashboardsSkill
- http-client-resilienceSkill
- integrate-whatsapp-baileys-laravelSkill
- interfaces-and-diSkill
- internationalization-and-translationSkill
- iterating-on-codeSkill
- laravel-11-12-app-guidelinesSkill
- laravel-database-optimizationSkill
- laravel-prompting-patternsSkill
- laravel-specialistSkill
- least-codeSkill
- livewire-developmentSkill
- memory-managementSkill
- migrations-and-factoriesSkill
- module-per-menuSkill
- nova-resource-patternsSkill
- performance-cachingSkill
- performance-eager-loadingSkill
- performance-select-columnsSkill
- php-attributesSkill
- policies-and-authorizationSkill
- ports-and-adaptersSkill
- prompt-structureSkill
- quality-checksSkill
- queues-and-jobsSkill
- rate-limitingSkill
- request-forgery-protectionSkill
- responsive-ui-testingSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 8 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Use database transactions for write operations that must be atomic.
- Very specific: line 19
Use DB::transaction() when a workflow:
- Distinctive: line 25
must not partially succeed.
- Distinctive: line 72
Use row locks for concurrent updates to shared counters, balances, or ordered state.
- Distinctive: line 85
Keep transactions short. Make retry behavior idempotent when deadlock retries are used.
- Distinctive: line 98
Keep lock ordering consistent across workflows to reduce deadlocks.
- Distinctive: line 99
Use optimistic checks when conflicts should be reported rather than serialized.
- Distinctive: line 100
Prefer explicit compensating behavior for filesystem or provider operations that cannot participate in the database transaction.
- Distinctive: line 109
after-commit behavior for important workflows.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Transactions
Use database transactions for write operations that must be atomic.
This is the canonical transaction skill. It consolidates the former transactions-and-consistency topic.
Transaction boundaries usually belong inside an Action or Service, not spread across controllers.
Required Transaction Cases
Use DB::transaction() when a workflow:
- writes multiple related records;
- updates counters, balances, inventory, or state machines;
- coordinates audit records with domain writes;
- creates records and related child rows;
- must not partially succeed.
final class CreateRecord
{
public function handle(User $actor, array $data): Record
{
return DB::transaction(function () use ($actor, $data) {
$record = Record::create([
'owner_id' => $actor->id,
'name' => $data['name'],
]);
$record->items()->createMany($data['items'] ?? []);
return $record->fresh(['items']);
});
}
}Filesystem Side Effects
Database rollbacks do not roll back files. Track stored paths and clean them up when the database write fails.
$storedPaths = [];
try {
DB::transaction(function () use ($request, &$storedPaths) {
$record = Record::create([...]);
foreach ($request->file('attachments', []) as $file) {
$storedPaths[] = $file->store("records/{$record->id}", 'public');
}
});
} catch (Throwable $exception) {
Storage::disk('public')->delete($storedPaths);
throw $exception;
}For delete flows, prefer committing database/audit changes first, then deleting files after the successful transaction unless the product explicitly requires the opposite failure mode.
Locks And Retries
Use row locks for concurrent updates to shared counters, balances, or ordered state.
DB::transaction(function () use ($recordId) {
$record = Record::query()
->whereKey($recordId)
->lockForUpdate()
->firstOrFail();
$record->increment('sequence');
});Keep transactions short. Make retry behavior idempotent when deadlock retries are used.
After-Commit Work
Dispatch queued jobs/events after commit when they depend on committed records.
Do not hold a database transaction open during slow HTTP calls, mail delivery, document generation, or other remote side effects. Persist the state needed to continue, commit it, and dispatch after commit. Use an outbox or equivalent durable handoff when losing the side effect would be unacceptable.
Idempotency And Consistency
- Protect retried commands, webhooks, and queued jobs with a stable idempotency key or a domain state check.
- Enforce uniqueness in the database when duplicate prevention is a data invariant.
- Make retry behavior return or recover the original result instead of repeating side effects.
- Keep lock ordering consistent across workflows to reduce deadlocks.
- Use optimistic checks when conflicts should be reported rather than serialized.
- Prefer explicit compensating behavior for filesystem or provider operations that cannot participate in the database transaction.
Test:
- success path;
- rollback path;
- duplicate or retried execution;
- concurrent updates when locking matters;
- filesystem cleanup when applicable;
- after-commit behavior for important workflows.
Context Efficiency
Layer: 3 (Implementation)
Load this skill only when writes need atomicity or consistency. Do not load with unrelated skills. Keep transactions short, idempotent, and after-commit for side effects. No open transaction during slow HTTP calls or mail delivery.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

