Skip to content

MigrationParser: recognize tables passed via keyword arguments, ignore comments#1

Merged
amberpixels merged 1 commit into
mainfrom
fix-migration-parser-helper-tables
Jul 23, 2026
Merged

MigrationParser: recognize tables passed via keyword arguments, ignore comments#1
amberpixels merged 1 commit into
mainfrom
fix-migration-parser-helper-tables

Conversation

@amberpixels

@amberpixels amberpixels commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Problem

Migrations that touch their tables only through project-level helper methods render an empty tables column in db:migrate:status. Example: a partition-conversion migration whose entire body is

convert_to_monthly_partitions(table: :apples, indexes: INDEXES)

has no create_table, no SQL literal, and no model constant, so MigrationParser returned []. Any codebase with migration helpers (strong_migrations-style shims, bulk-change DSLs, gem helpers) hits the same blind spot.

Separately, the SQL patterns scan raw text, so a Ruby comment mentioning ALTER TABLE foo produced a phantom table.

Changes

  • Keyword-argument pattern: table:, to_table:, and from_table: keywords now yield their table name regardless of the method they're passed to - one pattern covers the whole helper family with no per-project configuration. Bare from:/to: are deliberately excluded: change_column_default :apples, :status, from: nil, to: "ripe" would extract "nil"/"ripe" as tables.
  • Comment stripping: Ruby # comments are removed before any pattern scan (#{} interpolation is preserved), so commented-out DDL and explanatory SQL mentions no longer count.
  • Small allow-list fixes: dual-table methods (add_foreign_key/remove_foreign_key) now contribute their first argument even when the second is passed as to_table:; change_column_default and change_column_null joined the single-table methods.

Tests

9 new examples covering keyword extraction (symbol/string values, to_table:, the from:/to: guard, a realistic partition-conversion migration body) and comment stripping (comment-only SQL mentions, commented-out DSL, interpolation preservation). Full suite: 298 examples, 0 failures; standardrb clean.

Migrations that touch tables only through helper methods (e.g.
partition-conversion DSLs calling with table: :events) rendered an empty
tables column, since the parser only knew a closed list of ActiveRecord
DDL methods. A generic keyword pattern (table:, to_table:, from_table:)
now catches the whole helper family. Bare from:/to: are deliberately
excluded: change_column_default would yield phantom tables.

Ruby comments are stripped before scanning, so explanatory comments
mentioning ALTER TABLE or commented-out DSL calls no longer produce
phantom tables; #{} interpolation is preserved.

Also: dual-table methods now contribute their first argument even when
the second is passed as to_table:, and change_column_default /
change_column_null joined the single-table method list.
@amberpixels
amberpixels force-pushed the fix-migration-parser-helper-tables branch from b69e76f to 7199b3b Compare July 23, 2026 09:38
@amberpixels
amberpixels merged commit 83967e5 into main Jul 23, 2026
4 checks passed
@amberpixels
amberpixels deleted the fix-migration-parser-helper-tables branch July 23, 2026 09:58
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