Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Rewind Laravel Package

avocet-shores/laravel-rewind

Full version control for Eloquent models: rewind, fast-forward, restore, diff, and query point-in-time state. Uses hybrid diffs + snapshots for efficient storage and fast reconstruction, with locking for safe concurrent writes, batching, queues, and pruning.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Hybrid Storage Model: The package’s diff/snapshot hybrid approach aligns well with Laravel’s Eloquent ORM and database-centric workflows. It avoids the overhead of full snapshots while maintaining fast reconstruction, making it ideal for high-write applications (e.g., CMS, CRM, or audit-heavy systems).
  • Non-Destructive History: The linear, non-destructive history model ensures compliance with regulatory requirements (e.g., GDPR, HIPAA) where audit trails must be immutable. This fits systems where "undo" or "rollback" is a core feature.
  • State Transition Tracking: Specialized support for stateful models (e.g., orders, workflows) with rewindStateFields reduces boilerplate for tracking critical transitions (e.g., status, payment_status), which is valuable for domain-driven applications.

Integration Feasibility

  • Eloquent-Centric: The package is designed for Laravel’s Eloquent ORM, requiring minimal changes to existing models (add a trait and column). This lowers the barrier for adoption in Laravel-heavy codebases.
  • Database Schema Changes: Requires adding a current_version column to tracked models and a versions table for storing history. This is non-intrusive but requires migration planning.
  • Queue Support: Version creation can be queued (listener_should_queue), which is critical for high-traffic applications to avoid blocking user requests. This integrates seamlessly with Laravel’s queue system (e.g., Redis, database queues).
  • Customization Points: Supports extending the RewindVersion model, custom metadata, and event hooks, allowing for tailored behavior (e.g., adding soft-deletes, custom scopes, or notifications).

Technical Risk

  • Performance Overhead:
    • Write Path: Each model update triggers version creation (unless amended), which adds database writes and potential queue delays. For high-frequency updates (e.g., >1000 writes/sec), this could become a bottleneck. Mitigation: Use amendCurrentVersion for non-critical updates or disable versioning for high-volume models.
    • Read Path: Reconstructing versions from diffs/snapshots adds CPU overhead, especially for large models or deep history. The snapshot_interval config helps balance this, but testing with production-like data volumes is essential.
  • Concurrency Risks:
    • Cache-based locking prevents version sequence breaks, but misconfigured lock timeouts (on_lock_timeout) could lead to race conditions or lost updates. Defaults to logging, but production systems may need to throw exceptions or use events for custom handling.
  • Storage Growth:
    • Unchecked version retention can bloat the database. The pruning system (rewind:prune) is robust but requires proactive management (e.g., scheduled jobs, monitoring). Misconfiguration (e.g., keep=0) could lead to data loss.
  • Compatibility:
    • Assumes Laravel 9+ (based on recent releases). Older versions may require polyfills or manual adjustments.
    • No active dependents suggest limited real-world validation, though the MIT license and active maintenance (2026 releases) reduce risk.

Key Questions

  1. Use Case Alignment:
    • Is versioning a core requirement (e.g., compliance, undo/redo), or is it a "nice-to-have"? If the latter, evaluate if the overhead justifies the benefit.
    • Are there stateful models (e.g., orders, subscriptions) where rewindStateFields would add significant value?
  2. Performance Trade-offs:
    • What is the expected write volume per model? For >100 writes/sec, queuing and amendCurrentVersion may be critical.
    • How deep is the expected version history? Long histories (>1000 versions) may require tuning snapshot_interval or pruning policies.
  3. Operational Impact:
    • Who will manage pruning and storage growth? Automated jobs (e.g., daily pruning) should be tested in staging.
    • How will versioning interact with existing backup/restore processes? The hybrid storage model complicates traditional backups.
  4. Customization Needs:
    • Are there requirements for custom metadata, events, or version queries that exceed the package’s built-in features?
    • Will the RewindVersion model need extensions (e.g., soft deletes, additional columns)?
  5. Migration Strategy:
    • How will existing data be versioned? The initVersion() method can seed initial versions, but backfilling large datasets may require custom scripts.
    • Are there models with sensitive fields (e.g., passwords) that must be excluded from versioning?

Integration Approach

Stack Fit

  • Laravel Ecosystem: The package is a first-class Laravel citizen, leveraging Eloquent, Facades, Artisan commands, and Laravel’s queue/locking systems. It integrates cleanly with:
    • Eloquent Models: Minimal changes required (trait + column).
    • Queues: Supports async version creation for scalability.
    • Scheduling: Pruning and maintenance tasks can be scheduled via Laravel’s task scheduler.
    • Events: Extensible via RewindVersionLockTimeout events or custom event listeners.
  • Database Compatibility: Works with MySQL, PostgreSQL, SQLite, and SQL Server (standard Laravel support). No vendor-specific features.
  • Testing: Includes PHPUnit tests and supports mocking for unit/integration tests.

Migration Path

  1. Assessment Phase:
    • Audit target models to identify:
      • Models requiring versioning (prioritize stateful or compliance-critical ones).
      • Fields to exclude (e.g., password, api_token).
      • Expected write volumes and history depth.
    • Design a pruning strategy (e.g., keep=100, days=365) and test with staging data.
  2. Setup:
    • Install the package and publish migrations/config:
      composer require avocet-shores/laravel-rewind
      php artisan vendor:publish --provider="AvocetShores\LaravelRewind\LaravelRewindServiceProvider"
      php artisan migrate
      
    • Add the Rewindable trait to target models and define excludedFromVersioning/rewindStateFields as needed.
  3. Incremental Rollout:
    • Start with non-critical models in staging to validate performance and behavior.
    • Gradually enable versioning for high-priority models, monitoring:
      • Database write load (e.g., versions table growth).
      • Queue backlog (if using async versioning).
      • Application latency (especially for diff() or goTo() operations).
  4. Backfill Existing Data (Optional):
    • Use initVersion() to seed initial versions for existing records. For large datasets, consider a custom script to batch-insert versions.
  5. Pruning and Maintenance:
    • Schedule pruning jobs (e.g., daily) with safe defaults (e.g., --keep=100 --pretend for dry runs).
    • Monitor storage growth and adjust snapshot_interval or pruning policies as needed.

Compatibility

  • Laravel Version: Confirmed compatibility with Laravel 9+. For older versions, check for breaking changes in the changelog.
  • Model Requirements:
    • Models must extend Illuminate\Database\Eloquent\Model.
    • Requires a created_at and updated_at timestamp column (standard for Eloquent).
  • Database Drivers: Supports all Laravel-supported databases. No transactions or features specific to a single vendor.
  • Third-Party Conflicts: Minimal risk, but ensure no other packages modify the same models’ updated_at timestamps or use the current_version column.

Sequencing

  1. Development:
    • Implement versioning in a feature branch, testing with a subset of models.
    • Validate edge cases (e.g., concurrent updates, restores, diffs).
  2. Staging:
    • Deploy to staging with monitoring for:
      • Database performance (e.g., versions table size, query times).
      • Queue performance (if using async versioning).
    • Test pruning commands and rollback scenarios.
  3. Production:
    • Enable versioning for low-traffic models first.
    • Gradually expand to high-traffic models, adjusting snapshot_interval or queue settings as needed.
    • Document the new Rewind API for developers (e.g., goTo(), diff(), restore()).

Operational Impact

Maintenance

  • Pruning:
    • Requires regular maintenance to manage storage growth. The rewind:prune command is automated but should be monitored (e.g., via Laravel Horizon or external monitoring).
    • Configure defaults in config/rewind.php (e.g., prune_keep_versions, prune_older_than_days) to align with retention policies.
  • Schema Updates:
    • Future migrations (e.g., new columns in RewindVersion) may require manual intervention. Monitor the changelog for breaking changes.
  • Logging:
    • Enable debug logging for AvocetShores\LaravelRewind to troubleshoot issues (e.g., lock timeouts, version creation failures).

Support

  • Developer Onboarding:
    • Document the new Rewind API and its implications (e.g
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport