docs: show the migration version the provider generator actually emits

Merged
JA
2mo ago
+7-2

Fork pre-flight: jaysbeekay/sure#176. Cherry-picks, not the same branch. #176's branch holds this PR's first two commits under different SHAs, with identical content (its head 1ae890d11 matches this PR's 6a19926d8). It is rooted at the fork's copy of upstream main, so the fork's CI and review gates ran first without drift inflating the diff. This PR's third commit, 097c71035 (the CodeRabbit fix), exists only here.

Summary

docs/api/rails_provider_generator.md, under the heading "What Gets Generated (Detailed)", shows the migration the provider generators produce as:

class CreateMyBankTablesAndAccounts < ActiveRecord::Migration[7.2]

Both generators derive that version from Rails at generation time, so on main today they emit [8.1]. The guide documents output the tool does not produce.

Closes #3621.

Evidence

The version is computed, not hardcoded — identically in both generators:

# lib/generators/provider/family/family_generator.rb:870
# lib/generators/provider/global/global_generator.rb:181
def migration_version
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
# lib/generators/provider/family/templates/migration.rb.tt:3
class Create<%= class_name %>ItemsAndAccounts < ActiveRecord::Migration<%= migration_version %>

main is on rails (8.1.3.1) and db/schema.rb declares ActiveRecord::Schema[8.1]. Confirmed in a console on main:

Rails::VERSION::STRING                  = 8.1.3.1
generator would emit                    = [8.1]
ActiveRecord::Migration.current_version = 8.1

And the tree agrees. db/migrate/20260911165424_create_fio_items_and_accounts.rb is exactly the Create<X>ItemsAndAccounts shape this template produces, and it declares ActiveRecord::Migration[8.1]. The generator is behaving correctly; only the guide is out of step.

What changed

One line in the example, plus prose saying the version is derived rather than fixed — so the example is not "corrected" back to a literal later, and so the next reader after a Rails upgrade can tell a stale number from a current one.

  • 9a17392c Show the migration version the provider generator actually emits
  • 6a19926d Separate what the generator emits from what a migration keeps

The second commit is the wording. The first version said the version "will read differently after an upgrade", which reads as your migration's version changing later — and it does not. The generator writes the version in use when it runs, and what it writes is then fixed: it pins the semantics the migration was written against. A guide that can be read as "your migration version changes later" teaches something false, so the paragraph now separates the two statements.

docs/api/rails_provider_generator.md:173 is the only ActiveRecord::Migration[...] reference in the repository outside db/migrate, so this is the whole of it.

Why it is worth a PR

The line sits under a heading that promises generated output, in a fenced block, in a guide written for people adding a provider. AGENTS.md line 13 already states the rule:

New migrations use the current Rails migration version; leave historical migration versions intact.

So the example contradicted both the documented rule and the tool it documents.

What I am not claiming: migrations on main are currently mixed between [7.2] and [8.1], but I have not traced any of them to this guide and I am not asserting it caused them. The defect is that the documentation is factually wrong about the generator's output, and that stands on its own.

Validation

Docs only — no code, no schema, no behaviour, nothing to test. The claims above were verified rather than assumed: the generator methods and template were read at main, the emitted version was confirmed in a console, and the resulting version was checked against a real generated migration in the tree.

Note on #3620

@janbuchar's #3620 edits the same file, in the item-model section around lines 244–271. This touches line 173. Different hunks, and git merge-tree confirms the two do not conflict — I mention it only so whoever merges the second one is not surprised to see the file already touched. Happy to rebase behind it, or to fold this line into that PR instead if that is easier.

Rebased onto main (6 Oct)

Rebased onto main at eb34c06f0; the commits carry the same changes, under new SHAs. SHAs elsewhere in this description refer to the commits as they were before.

  • 9a17392c7 → 31e8076e9 Show the migration version the provider generator actually emits
  • 6a19926d8 → a9e7a6ff2 Separate what the generator emits from what a migration keeps
  • 097c71035 → 6c8cda974 Name both version constants the generator reads

Conflicts: none.

bin/rails test on 6c8cda974: 10,565 runs, 44,978 assertions, 0 failures, 0 errors, 33 skips. bin/rubocop on the changed files: no offenses.

Summary by CodeRabbit

  • Documentation
    • Clarified that generated migrations use the current Rails major and minor version and retain that version afterward.
    • Updated the migration version example to 8.1.