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

Message Repository Table Schema Laravel Package

eventsauce/message-repository-table-schema

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event Sourcing & CQRS Alignment: The package excels in event-sourced architectures where events are stored as immutable records in a relational database. It enforces a structured schema (e.g., aggregate_id, message_type, payload, metadata), aligning with Laravel’s need for auditability and replayability. However, it assumes EventSaucePHP as the event bus, which may not align with Laravel’s native event system (e.g., Illuminate\Events). For CQRS, the package enables projection services but requires additional Laravel-specific glue code (e.g., read models).
  • Laravel Compatibility: While not Laravel-native, the package integrates via Doctrine DBAL (used by EventSaucePHP) and Laravel’s Migrations. The schema is database-agnostic (PostgreSQL/MySQL) but lacks Laravel-specific optimizations (e.g., Eloquent relationships, query builder hooks). The rigid schema may conflict with Laravel’s dynamic event payloads (e.g., JSON columns).
  • Schema Rigidity vs. Flexibility: The package’s normalized table design ensures data integrity but limits flexibility for polyglot persistence or ad-hoc event attributes. Laravel’s JSON:B (PostgreSQL) or JSON (MySQL) columns might offer more flexibility but sacrifice schema enforcement.

Integration Feasibility

  • EventSaucePHP Dependency: The package requires EventSaucePHP (or a compatible event repository interface). If Laravel already uses EventSaucePHP, integration is low-effort. Otherwise, a custom adapter layer is needed to bridge Laravel’s Event facade to EventSaucePHP’s MessageRepository. Example:
    // Pseudocode: Laravel Event → EventSaucePHP Event
    Event::listen('OrderCreated', function ($event) {
        $domainEvent = new OrderCreatedEvent(
            $event->orderId,
            json_encode($event->details)
        );
        $messageRepository->save($domainEvent);
    });
    
  • Database Schema Conflicts: The package’s schema assumes UUIDs for IDs and JSON for payloads. Laravel’s default event storage (e.g., jobs table) may use integers or serialized arrays, requiring migration planning. For example:
    • Existing Events: If events are stored in a jobs table, a data migration is needed to backfill the new schema.
    • Custom Columns: Adding Laravel-specific fields (e.g., user_id, tenant_id) requires schema extensions.
  • Serialization Mismatches: Laravel events may include non-JSON-serializable objects (e.g., Carbon instances, Eloquent models). EventSaucePHP expects strict JSON payloads, necessitating custom serializers.

Technical Risk

  • Schema Lock-In: The package’s immutable schema design makes future changes (e.g., adding event metadata) migration-heavy. Laravel’s dynamic event structures (e.g., arbitrary payloads) may not fit neatly.
  • Performance Tradeoffs:
    • Reads: Normalized tables may outperform JSON blobs for filtered queries (e.g., WHERE aggregate_id = ?), but complex joins could slow down projections.
    • Writes: Synchronous saves may bottleneck under high throughput. Laravel’s queues can mitigate this, but the package itself doesn’t support async writes.
  • Laravel Ecosystem Gaps:
    • No Native Laravel Support: Missing features like queue listeners, event broadcasting, or Laravel Scout indexing.
    • Testing Complexity: Debugging event-sourcing issues (e.g., out-of-order events, corrupted payloads) requires EventSaucePHP expertise, which may not overlap with Laravel’s debugging tools.
  • Documentation and Community: With 1 star and minimal docs, production reliability is unproven. Critical edge cases (e.g., concurrent writes, large payloads) may need custom validation.

Key Questions

  1. Event Storage Strategy:
    • Does Laravel’s current event system (e.g., jobs table) need to coexist with this package, or is this a full replacement?
    • How will event versioning (e.g., schema evolution) be handled in Laravel’s context?
  2. Database Compatibility:
    • Are there collation/encoding issues with UUIDs or JSON columns in the target DB?
    • Will the schema conflict with existing Laravel migrations (e.g., schema.php)?
  3. EventSaucePHP Adoption:
    • Is the team willing to adopt EventSaucePHP as a dependency, or will a minimal adapter suffice?
    • How will Laravel’s event listeners map to EventSaucePHP’s aggregate roots?
  4. Query Requirements:
    • Will the normalized schema meet performance needs for event replay or projections?
    • Are there Laravel-specific query patterns (e.g., Eloquent relationships) that the schema must support?
  5. Migration Strategy:
    • How will existing event data (if stored in jobs or elsewhere) be migrated to the new schema?
    • What’s the rollback plan if migrations fail?
  6. Failure Modes:
    • How will database corruption or schema migration failures be detected and recovered?
    • Are there circuit breakers for event storage failures in Laravel’s event loop?

Integration Approach

Stack Fit

  • PHP/Laravel: The package is composer-installable and works with Laravel 5.5+ via Doctrine DBAL. It fits best in Laravel apps using:
    • EventSaucePHP (or willing to adopt it).
    • Relational databases (PostgreSQL/MySQL) for event storage.
    • Event sourcing or CQRS patterns.
  • Alternatives Considered:
    • Laravel’s Native Events: Stores events in jobs tables (less structured, no replayability).
    • Custom JSON Columns: More flexible but lacks schema enforcement.
    • EventSaucePHP’s Default Storage: May use a different schema (e.g., event_store).
  • Laravel-Specific Gaps:
    • No integration with Laravel Queues, Broadcasting, or Scout.
    • Requires manual setup for read models (e.g., projections).

Migration Path

  1. Assess Current Event Storage:
    • Audit where events are stored (e.g., jobs table, custom tables, or no storage).
    • Identify schema mismatches (e.g., integer IDs vs. UUIDs, serialized arrays vs. JSON).
  2. Dependency Setup:
    • Install packages:
      composer require eventsauce/event-sauce eventsauce/message-repository-table-schema doctrine/dbal
      
    • Configure Laravel’s config/app.php to include:
      EventSauce\MessageRepositoryTableSchema\MessageRepositoryTableSchemaServiceProvider::class,
      
  3. Schema Migration:
    • Run the package’s migration generator:
      php artisan vendor:publish --provider="EventSauce\MessageRepositoryTableSchema\MessageRepositoryTableSchemaServiceProvider"
      php artisan migrate
      
    • For Laravel, extend the migration to include custom columns (e.g., tenant_id):
      Schema::table('message_store', function (Blueprint $table) {
          $table->unsignedBigInteger('tenant_id')->nullable();
      });
      
  4. Event Adapter Layer:
    • Create a service to bridge Laravel events to EventSaucePHP:
      class LaravelEventToDomainEventAdapter
      {
          public function __construct(private MessageRepository $messageRepository) {}
      
          public function handle(LaravelEvent $event): void
          {
              $domainEvent = new DomainEvent(
                  $event->aggregateId,
                  $event->name,
                  json_encode($event->payload)
              );
              $this->messageRepository->save($domainEvent);
          }
      }
      
    • Register the adapter in Laravel’s EventServiceProvider:
      protected $listen = [
          'OrderCreated' => [LaravelEventToDomainEventAdapter::class],
      ];
      
  5. Projection Services:
    • For CQRS, create read models using Laravel’s Eloquent or raw queries:
      // Example: Project events to an Order model
      $events = $messageRepository->load($aggregateId);
      $order = new Order();
      foreach ($events as $event) {
          $order->apply($event);
      }
      $order->save();
      

Compatibility

  • Database:
    • Supported: PostgreSQL, MySQL (via Doctrine DBAL).
    • Unsupported: SQLite (no UUID support), SQL Server (unless configured).
    • Laravel .env: Ensure DB_CONNECTION matches the package’s expectations.
  • PHP Version: Requires **PHP 8.
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony