Repository navigation
fix(migrations): keep the fork's migrations out of upstream's schema versions - #89
Conversation
…on above upstream's Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…tabase moved back still runs its migrations Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…ves no version above upstream's Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
… upstream's migrate still sees what it has not run Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…o a later migrate cannot mistake upstream's 1.5.0 for the fork's Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…oes not read as an upstream version Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…now moving back to upstream is safe Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit f049d15. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 25 minutes. View limit details
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Define and initialize fork migration state lib/event_store/sql/init.ex, lib/event_store/tasks/migrations.ex, priv/event_store/fork_migrations/*, priv/event_store/migrations/v1.5.0.sql |
Initialization creates fork_schema_migrations and records subscription_lock_generation. The fork migration is represented by name and conditionally adds subscriptions.lock_generation; the versioned v1.5.0.sql migration is removed. |
Discover, list, and run migrations lib/event_store/tasks/migrate.ex, lib/event_store/tasks/migrations.ex, test/list_event_store_migrations_test.exs, test/migrate_event_store_test.exs, guides/Upgrades.md |
Migration discovery separates pending fork migrations from upstream migrations. Listing reports fork migration state, and execution uses each migration’s supplied name and path. Tests cover migration state, version reporting, and repeat runs. The guide describes the separate migration histories and moving a database back to upstream. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant Migrate as EventStore.Tasks.Migrate
participant Init as EventStore.Sql.Init
participant ForkTable as fork_schema_migrations
participant ForkSQL as subscription_lock_generation.sql
participant SchemaTable as schema_migrations
Migrate->>Init: Create fork migration table
Init->>ForkTable: Create table if absent
Migrate->>ForkTable: Read recorded fork migration names
Migrate->>ForkSQL: Execute pending fork migration
ForkSQL->>SchemaTable: Remove version 1.5.0 when lock_generation exists
ForkSQL->>ForkTable: Record subscription_lock_generation
Possibly related issues
- Test gaps at a2ce825: surviving mutants and two unreliable test barriers #81 — The PR replaces the migration-selection logic discussed in the issue and adds tests for pending and completed fork migration states.
Possibly related PRs
- TrogonStack/commanded_eventstore#25 — Introduced the fork’s
subscriptions.lock_generationmigration as upstream version1.5.0, which this PR replaces with named fork migration tracking. - TrogonStack/commanded_eventstore#75 — Addressed the
1.5.0migration collision; this PR continues that work by separating fork and upstream migration history.
Suggested reviewers: slashdotdash, kaikuchn
Merge Risk: 
Minimal · previous review 237aa
-
No concrete issue requiring a change before merge is established by the supplied evidence. Normal migration tests should still be run.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#86requires that moving a database from the fork back to upstream does not skip unapplied upstream migrations numbered 1.5.0 or lower. The reviewed head meets this for databases the fork creates or migrates:- lib/event_store/sql/init.ex: Init.statements/1 now records schema version 1.3.2 through record_event_store_schema_version/0. It no longer records 1.5.0. Upstream's newer_migrations filter (run only versions greater than the highest recorded) therefore still sees 1.3.2 as the highest version and runs an upstream 1.5.0 if one ships.
- Init creates fork_schema_migrations and records 'subscription_lock_generation' there, so fork-specific state no longer occupies upstream's schema_migrations rows.
- lib/event_store/tasks/migrate.ex: fork migrations are computed from fork_schema_migrations. The upstream newer-migration filter is unchanged.
- priv/event_store/migrations/v1.5.0.sql is deleted. priv/event_store/fork_migrations/subscription_lock_generation.sql adds lock_generation when absent. When the column already exists, it deletes the (1,5,0) row from schema_migrations. This addresses databases the fork recorded as 1.5.0 before this change.
Residual risk, not a failing condition for
#86: for a fork database whose only schema_migrations row was (1,5,0), the delete leaves schema_migrations empty. Upstream migrate then treats the database as unversioned and selects all Migrations.available_migrations() (0.13.0 through 1.3.2) on later runs. I did not verify that these upstream scripts are safe to run on an existing schema. The migrate test summary (a 1.5.0-recorded store ends at reported version 1.3.2) depends on test setup I did not read. I did not run the test suite.
Full details: Out of Scope Changes check
-
Explanation
Every changed area ties to issue
#86, which asks that fork and upstream migration records stay separate:- lib/event_store/sql/init.ex: records 1.3.2 and creates fork_schema_migrations (required by
#86). - lib/event_store/tasks/migrate.ex and lib/event_store/tasks/migrations.ex: discover, list, and run fork migrations from fork_schema_migrations (required by
#86). The ForkMigration struct and available_fork_migrations/0 support that listing. - priv/event_store/fork_migrations/subscription_lock_generation.sql and deletion of priv/event_store/migrations/v1.5.0.sql: move the fork's lock_generation change out of upstream's version 1.5.0 (required by
#86). - guides/Upgrades.md: documents where the fork records its migrations. This supports the operator move-back case described in the PR and commit messages.
- Tests in test/list_event_store_migrations_test.exs and test/migrate_event_store_test.exs: cover the changed listing and migration behavior.
The summary shows no unrelated functional change.
- lib/event_store/sql/init.ex: records 1.3.2 and creates fork_schema_migrations (required by
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 5 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the schema’s name,
Fork and upstream track their claim.
A lock-generation column grows,
While migration history shows.
Run the steps, then hop away,
The records tell what’s done today.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 237aa73. Configure here.
…0 was the only one recorded Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…k's 1.5.0 was the only one Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

Closes #86