Skip to content

Use shared-context helpers in migration specs - #5529

Open
philippthun wants to merge 1 commit into
cloudfoundry:mainfrom
sap-contributions:fix-migration-idempotency-tests
Open

philippthun wants to merge 1 commit into
cloudfoundry:mainfrom
sap-contributions:fix-migration-idempotency-tests

Conversation

@philippthun

@philippthun philippthun commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Replace raw Sequel::Migrator.run calls in migration specs with the run_migration and revert_migration helpers, and use the test_up_migration_idempotency / test_down_migration_idempotency helpers for idempotency checks.

The idempotency helpers delete or insert the schema_migrations row before re-running, so the migration body is genuinely re-executed. Re-running the migrator to the same target only is a no-op and does not test idempotency.

Apply each helper only where the migration body supports it: options like add_column(if_not_exists:) are honoured on PostgreSQL but ignored on MySQL, so such migrations assert idempotency in a database-gated context. Single-database migrations are exercised only there, and migrations with unguarded DDL or no reversible down assert only the steps that apply. Each added step asserts state in the same style as the rest of its spec.

Update spec/migrations/Readme.md to document the four helpers.

Add two custom cops: UseMigrationHelpers flags raw Sequel::Migrator.run calls in specs that include the shared context, and RequireMigrationSharedContext flags per-migration specs that omit it. Legacy and bigint-step specs are excluded via .rubocop_cc.yml.

This change was developed with AI assistance; all code was reviewed and tested by me.

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

jochenehret
jochenehret previously approved these changes Nov 3, 2026
@philippthun
philippthun force-pushed the fix-migration-idempotency-tests branch from d121ca4 to 6428955 Compare November 12, 2026 08:57
@philippthun
philippthun force-pushed the fix-migration-idempotency-tests branch 2 times, most recently from 07dbabe to c5ef235 Compare November 13, 2026 11:09
Replace raw Sequel::Migrator.run calls in migration specs with the
run_migration and revert_migration helpers, and use the
test_up_migration_idempotency / test_down_migration_idempotency
helpers for idempotency checks.

The idempotency helpers delete or insert the schema_migrations row
before re-running, so the migration body is genuinely re-executed.
Re-running the migrator to the same target only is a no-op and does
not test idempotency.

Apply each helper only where the migration body supports it: options
like add_column(if_not_exists:) are honoured on PostgreSQL but ignored
on MySQL, so such migrations assert idempotency in a database-gated
context. Single-database migrations are exercised only there, and
migrations with unguarded DDL or no reversible down assert only the
steps that apply. Each added step asserts state in the same style as
the rest of its spec.

Update spec/migrations/Readme.md to document the four helpers.

Add two custom cops: UseMigrationHelpers flags raw Sequel::Migrator.run
calls in specs that include the shared context, and
RequireMigrationSharedContext flags per-migration specs that omit it.
Legacy and bigint-step specs are excluded via .rubocop_cc.yml.
@philippthun
philippthun force-pushed the fix-migration-idempotency-tests branch from c5ef235 to 5730218 Compare November 13, 2026 11:10

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants