Skip to content

Stop auto-creating schema on store construction - #10

Merged
jcviljoen merged 3 commits into
mainfrom
database/do-not-immediately-trigger-migrations
May 16, 2026
Merged

Stop auto-creating schema on store construction#10
jcviljoen merged 3 commits into
mainfrom
database/do-not-immediately-trigger-migrations

Conversation

@jcviljoen

@jcviljoen jcviljoen commented May 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • SqlEventStore::__construct and SqlRedeliveryStore::__construct no longer call ensure*Schema(). The stores assume their tables already exist.
  • New top-level migrations/{mysql,sqlite}/ directory ships versioned, pure-DDL files (0001_create_event_outbox.sql, 0001_create_event_outbox_redelivery.sql) for host migration tools to consume. Future schema changes will land here as new numbered files.
  • The existing Schema/*::create() helpers are unchanged and remain the explicit opt-in path for projects without their own migration tooling. They stay idempotent.
  • Tests now call Schema::create($pdo) in setUp(). The two _schema_is_idempotent_across_multiple_instantiations tests are rewritten as _schema_create_is_idempotent against the helper directly.
  • README has a new "Setting up the schema" section explaining both paths and which to pick. The ROADMAP "Schema migrations" item is reframed around the new stance.

Motivation

Auto-create-on-construct raced with host migration tooling — see hivesper/vesper-identity-api#191, which had to work around this package triggering DDL at boot. With this change, schema installation is a deliberate act in whichever system the host already uses.

Breaking change

Existing consumers will get "table doesn't exist" errors on first boot after upgrading until they either:

  1. Add a migration in their own tool that runs the SQL from vendor/hivesper/php-events/migrations/{driver}/0001_*.sql (recommended), or
  2. Call MysqlEventStoreSchema::create(\$pdo) (and MysqlRedeliverySchema::create(\$pdo) if using redelivery) once at boot.

🤖 Generated with Claude Code

`SqlEventStore` and `SqlRedeliveryStore` previously created their tables
on first boot inside the constructor. That raced with host applications
that own their own migration tooling and could trigger DDL at unexpected
times.

Constructors are now no-ops. Two installation paths are documented:
versioned DDL templates in `migrations/{mysql,sqlite}/` for host
migration tools, or the existing `Schema::create()` helper for opt-in
boot-time setup. Tests now invoke `Schema::create()` explicitly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jcviljoen
jcviljoen marked this pull request as ready for review May 16, 2026 20:43
jcviljoen and others added 2 commits May 16, 2026 22:44
Future schema changes now ship as new numbered files in `migrations/`;
host migration tools handle ordering and idempotency. Nothing left for
the package to build, so the item doesn't belong on the roadmap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jcviljoen
jcviljoen merged commit cca62da into main May 16, 2026
1 check passed
@jcviljoen
jcviljoen deleted the database/do-not-immediately-trigger-migrations branch May 17, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant