Skip to content

fix(migrations): keep the fork's migrations out of upstream's schema versions - #89

Merged
yordis merged 11 commits into
mainfrom
yordis/fix-fork-migration-versions
Oct 27, 2026
Merged

yordis merged 11 commits into
mainfrom
yordis/fix-fork-migration-versions

Conversation

@yordis

@yordis yordis commented Oct 27, 2026

Copy link
Copy Markdown
Member
  • Upstream's migrate runs only versions above the highest one recorded, so the 1.5.0 the fork recorded would make a database moved back to upstream skip any upstream migration numbered 1.5.0 or lower while reporting itself migrated.
  • Recording the fork's migrations under their own names keeps upstream's numbering free for upstream, rather than depending on upstream adopting the fork's 1.5.0.

Closes #86

…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>
@cursor

cursor Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes how schema version history is written and repairs existing DBs that recorded fork 1.5.0; incorrect repair logic could confuse upstream migrate or skip/duplicate migrations.

Overview
Fork-only schema changes no longer bump schema_migrations to upstream-style versions (e.g. the old fork 1.5.0). They run from priv/event_store/fork_migrations/ and are tracked in a new fork_schema_migrations table by name (starting with subscription_lock_generation). Upstream versioned SQL under priv/event_store/migrations/ is unchanged in numbering; v1.5.0.sql is removed from this fork’s upstream list.

mix event_store.migrate runs pending upstream migrations first, then pending fork migrations. Fresh init seeds schema_migrations at 1.3.2 (upstream’s latest in this fork) and records the fork migration in fork_schema_migrations. The subscription_lock_generation script is idempotent: add lock_generation when missing, or repair databases that already had the column but recorded fork 1.5.0 (strip that row and avoid an empty history that would re-run all upstream migrations).

event_store.migrations lists fork migrations alongside version rows. Upgrades.md documents the split so moving a DB back to upstream EventStore still applies any upstream migrations it has not run.

Reviewed by Cursor Bugbot for commit f049d15. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e8d8b3bb-9cf4-4b09-8e1e-34122792674e
Commits

Reviewing files that changed from the base of the PR and between 237aa73 and f049d15.

Files selected for processing: 2
  • priv/event_store/fork_migrations/subscription_lock_generation.sql
  • test/migrate_event_store_test.exs

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d183e3cf-b68e-4eaf-b98a-cb24f4a550c0
Commits

Reviewing files that changed from the base of the PR and between d3d3ec0 and 237aa73.

Files selected for processing: 8
  • guides/Upgrades.md
  • lib/event_store/sql/init.ex
  • lib/event_store/tasks/migrate.ex
  • lib/event_store/tasks/migrations.ex
  • priv/event_store/fork_migrations/subscription_lock_generation.sql
  • priv/event_store/migrations/v1.5.0.sql
  • test/list_event_store_migrations_test.exs
  • test/migrate_event_store_test.exs
Files with no reviewable changes: 1
  • priv/event_store/migrations/v1.5.0.sql

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The migration system now records fork migrations by name in fork_schema_migrations, separately from upstream versions in schema_migrations. Migration discovery, listing, and execution handle the two migration types. The upgrade guide describes moving a database back to upstream.

Changes

Fork Migration Tracking

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: Normal

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
Loading

Possibly related issues

Possibly related PRs

  • TrogonStack/commanded_eventstore#25 — Introduced the fork’s subscriptions.lock_generation migration as upstream version 1.5.0, which this PR replaces with named fork migration tracking.
  • TrogonStack/commanded_eventstore#75 — Addressed the 1.5.0 migration 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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: keeping fork migrations separate from upstream schema versions.
Description check Passed The description explains the migration-version collision and the change to record fork migrations by name. It directly matches the changeset and objectives.
Linked Issues check Passed Issue #86 requires 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 create…
Out of Scope Changes check Passed 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 #8…
Full details: Linked Issues check

Explanation

Issue #86 requires 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.

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.

❤️ Share

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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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>
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.

A database moved from the fork back to upstream can skip upstream migrations numbered 1.5.0 or lower

1 participant