- Can I use andreo/eventsauce-snapshotting with Laravel’s Eloquent ORM?
- No, this package requires Doctrine DBAL for snapshot storage and isn’t compatible with Eloquent. You’ll need to use raw DBAL queries or adapt Laravel’s migrations to work with the snapshot table schema provided by the package.
- What Laravel versions are supported by this package?
- The package itself doesn’t enforce Laravel version constraints, but it requires PHP 8.2+ and Doctrine DBAL 3.1+. Ensure your Laravel app meets these PHP requirements and integrates Doctrine DBAL via `doctrine/dbal`.
- How do I configure conditional snapshotting (e.g., every N events)?
- Wrap your `AggregateRootRepositoryWithSnapshotting` in `AggregateRootRepositoryWithConditionalSnapshot` and configure it with a strategy like `EveryNEventConditionalSnapshotStrategy`. Pass the desired event threshold (e.g., 100) to control snapshot frequency.
- Will this package work if I’m not already using EventSauce?
- No, this package extends EventSauce’s functionality and assumes you’re already using it for event sourcing. You’d need to migrate from Laravel’s native event system to EventSauce’s message repository and event bus first.
- How do I handle schema changes in aggregates with versioned snapshots?
- Implement `VersionedSnapshotState` for each schema version (e.g., `FooSnapshotStateV1`, `FooSnapshotStateV2`) and return the version via `getSnapshotVersion()`. The package’s `SnapshotVersionInflector` and `SnapshotVersionComparator` will manage compatibility during aggregate reconstitution.
- Are there performance implications for using snapshots in production?
- Snapshots reduce event replay overhead but add storage and write costs. Conditional snapshotting (e.g., every 100 events) balances performance and storage. Monitor snapshot creation frequency and aggregate reconstitution times under load.
- Can I integrate this with Laravel’s caching system for snapshots?
- The package doesn’t cache snapshots by default, but you can manually cache loaded snapshots using Laravel’s cache system. Store snapshots in cache with a key like `snapshot:{aggregate_id}:{version}` and implement logic to invalidate or refresh them.
- What database systems are supported for snapshot storage?
- Any database supported by Doctrine DBAL (MySQL, PostgreSQL, SQLite) works, as long as your Laravel app’s connection is configured. The package provides a `SnapshotTableSchema` to generate the required table structure.
- How do I test aggregates that use versioned snapshots?
- Test snapshot reconstitution by replaying events and verifying the aggregate state matches the snapshot. Use PHPUnit to mock the `DoctrineSnapshotRepository` and assert that `VersionedSnapshotState` implementations return correct versions and data.
- Are there alternatives to this package for Laravel event-sourcing snapshots?
- If you’re not using EventSauce, consider Laravel’s native event system with manual snapshot storage (e.g., serialized aggregates in a database table). For EventSauce users, this package is the most feature-complete option, but you could build custom snapshot logic with Doctrine DBAL.