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 a hybrid engine (diffs + snapshots) with configurable intervals, thread-safe locking, batch revisions, queued writes, and pruning.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Eloquent-Centric: Perfectly aligned with Laravel’s Eloquent ORM, requiring minimal architectural changes. The Rewindable trait integrates seamlessly with existing models, avoiding invasive modifications to core logic.
  • Hybrid Storage: The diff/snapshot hybrid approach balances storage efficiency (diffs) and reconstruction speed (snapshots), making it ideal for high-write systems where both performance and auditability are critical.
  • Non-Destructive Design: Preserves all historical data, even after restores or pruning, which aligns with compliance-heavy applications (e.g., financial, healthcare).
  • Event-Driven Extensibility: Supports custom event types (e.g., restored, deleted) and metadata, enabling tailored workflows (e.g., triggering notifications on state transitions).

Integration Feasibility

  • Low Friction: Requires only:
    1. Adding the Rewindable trait to target models.
    2. Running a single migration (current_version column).
    3. Publishing config (optional).
  • Backward Compatibility: Non-versioned models remain unaffected. Existing queries/updates work unchanged.
  • Database Impact: Adds a rewind_versions table and a column per tracked model. Minimal schema changes if using the default configuration.
  • Performance Overhead:
    • Write Path: Version creation is queued by default (configurable), reducing latency spikes.
    • Read Path: Diff reconstruction is optimized (incremental, not per-version), with configurable snapshot intervals to trade storage for speed.

Technical Risk

  • Concurrency Conflicts:
    • Cache-based locking prevents version sequence breaks, but misconfigured timeouts (e.g., on_lock_timeout: 'throw') could block writes. Mitigate via queue retries or event-based handling.
    • Mitigation: Test under high concurrency with listener_should_queue: true and monitor RewindVersionLockTimeout events.
  • Storage Bloat:
    • Unchecked growth of versions can inflate database size. Pruning is automatic but requires proactive configuration (e.g., max_versions per model or prune:keep).
    • Mitigation: Set defaults in config/rewind.php and schedule pruning (e.g., daily via Laravel Scheduler).
  • State Transition Complexity:
    • Custom state fields ($rewindStateFields) add query flexibility but require explicit definition. Overuse may complicate diffs.
    • Mitigation: Document state-tracked fields in model docs and validate transitions in tests.
  • Snapshot Reconstruction:
    • Large snapshot intervals (e.g., snapshot_interval: 50) may slow down goTo() or diff() for older versions.
    • Mitigation: Benchmark with production-like data volumes and adjust intervals.

Key Questions

  1. Model Scope:
    • Which models require versioning? Prioritize high-churn entities (e.g., Order, UserProfile) and exclude low-impact ones (e.g., Setting).
  2. Audit Requirements:
    • Are state transitions (e.g., status changes) critical for compliance? If so, define $rewindStateFields explicitly.
  3. Performance SLAs:
    • What’s the acceptable latency for rewind()/diff()? Test with snapshot_interval tuned to your workload.
  4. Storage Budget:
    • How long to retain versions? Configure prune_older_than_days and max_versions conservatively.
  5. Concurrency Model:
    • Is write contention expected? Enable queued listeners (listener_should_queue: true) and monitor lock timeouts.
  6. Migration Strategy:
    • For existing tables, use initVersion() to backfill v1 or accept manual initialization.
  7. Customization Needs:
    • Does the default RewindVersion model suffice, or are extensions (e.g., soft deletes) required?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Native support for Eloquent, Queues, Events, and Scheduler. Integrates with Laravel’s caching (for locks) and database (for storage).
    • Compatible with Laravel 10+ (based on last release date: 2026-03-31).
  • Database:
    • Works with MySQL, PostgreSQL, SQLite (via Eloquent). No vendor-specific features.
    • Requires current_version column (integer) and rewind_versions table (supports indexes for model_type, model_id, version).
  • Queue Systems:
    • Supports Redis, database, or other Laravel queue drivers for async version creation.
  • Testing:
    • Built-in test suite (PHPUnit) and coverage reports. Easily integrated into Laravel’s testing pipeline.

Migration Path

  1. Assessment Phase:
    • Audit target models for versioning needs (e.g., Order, Invoice).
    • Identify state-tracked fields and excluded attributes (e.g., password).
  2. Setup:
    • Install via Composer: composer require avocet-shores/laravel-rewind.
    • Publish config and migrations: php artisan vendor:publish --provider="AvocetShores\LaravelRewind\LaravelRewindServiceProvider".
    • Run migrations: php artisan migrate.
  3. Model Integration:
    • Add use Rewindable; to target models.
    • Define $rewindStateFields (if needed) and excludedFromVersioning().
    • For existing data, run php artisan rewind:add-version or manually call initVersion().
  4. Configuration:
    • Tune config/rewind.php:
      • snapshot_interval: Balance storage vs. reconstruction speed.
      • max_versions: Per-model limits.
      • prune_keep_versions: Retention policy.
      • listener_should_queue: Enable for high-write models.
  5. Testing:
    • Validate versioning with:
      • Rewind::rewind($model), Rewind::diff($model, v1, v2).
      • State transitions (if applicable).
      • Pruning (php artisan rewind:prune --pretend).
    • Load-test with production-like data volumes.
  6. Deployment:
    • Roll out in stages (e.g., non-critical models first).
    • Monitor queue backlogs and lock timeouts.
    • Schedule pruning (e.g., php artisan rewind:prune --keep=100 --days=365 daily).

Compatibility

  • Existing Code:
    • Non-versioned models and queries remain unchanged.
    • Updates via Eloquent ($model->update()) trigger versioning automatically.
  • Third-Party Packages:
    • Conflicts unlikely unless other packages modify Eloquent’s saving/updating events. Use Rewind::amendCurrentVersion() for counter/denormalized fields.
  • Legacy Systems:
    • For pre-existing data, backfill v1 manually or via initVersion().
    • Ensure current_version column is nullable (default) to avoid migration errors.

Sequencing

  1. Critical Path:
    • Install → Publish → Migrate → Add Trait → Test.
  2. Non-Blocking Steps:
    • Configure pruning/snapshots post-deployment.
    • Enable queued listeners after verifying baseline performance.
  3. Rollback Plan:
    • Drop rewind_versions table and current_version column if needed.
    • Use amendCurrentVersion() to bypass versioning temporarily during debugging.

Operational Impact

Maintenance

  • Configuration Drift:
    • Centralized in config/rewind.php. Use Laravel’s config caching (php artisan config:cache) in production.
    • Document snapshot intervals and pruning rules per environment (dev/staging/prod).
  • Schema Changes:
    • Minimal. Only the rewind_versions table and current_version column. Use migrations for future updates.
  • Dependency Updates:
    • Monitor for Laravel version compatibility (e.g., if upgrading Laravel 10→11).
    • Test with new PHP versions (e.g., 8.2→8.3) for BC breaks.

Support

  • Debugging:
    • Logs version creation/pruning via Laravel’s logging system.
    • Use RewindVersion::forModel($model)->get() to inspect history.
    • Enable on_lock_timeout: 'event' to catch concurrency issues.
  • Common Issues:
    • Missing Versions: Verify Rewindable trait is added and current_version column exists.
    • Slow Rewinds: Increase snapshot_interval or optimize queries on rewind_versions.
    • Queue Stalls: Monitor failed_jobs table and adjust queue workers.
  • Documentation:
    • Add model-level docs for $rewindStateFields and excluded attributes.
    • Create runbooks for pruning and lock timeout scenarios.

Scaling

  • Horizontal Scaling:
    • Stateless design (locks via cache). No single point of failure.
    • Queue-based version creation scales writes independently of reads.
  • Database Scaling:
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai