Skip to content

Allow custom migration table name#433

Open
sandbergja wants to merge 1 commit into
hanami:mainfrom
sandbergja:configurable-migrations-table
Open

Allow custom migration table name#433
sandbergja wants to merge 1 commit into
hanami:mainfrom
sandbergja:configurable-migrations-table

Conversation

@sandbergja

@sandbergja sandbergja commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

This was suggested by FrankP on the forum. It has a sibling PR in hanami: hanami/hanami#1615

I implemented this as a configuration option in the hanami gem, so this has a sibling PR in the hanami gem. My reasoning was that this should be a relatively stable configuration option, rather than an argument that you need to remember to pass to hanami db migrate each time, since if you forget to specify your custom table name even once, you could potentially get your database into an odd state.

However, I would definitely be open to other ideas -- I also wasn't sure what the best practice was for testing a configuration setting that isn't yet in the hanami gem, or for backwards compatibility.

To try it out:

  1. hanami new octopus
  2. cd octopus
  3. Adjust the gemfile to point to versions of hanami and hanami-cli with the relevant commits.
  4. In config/app.rb, add config.db.migrations_table = :hanami_migrations
  5. Use hanami g migration to create a new migration. Add a table to it.
  6. hanami db migrate
  7. Verify that your database does not have a table named schema_migrations, and that it instead has a table named hanami_migrations.

This was suggested by FrankP on the forum here: https://discourse.hanakai.org/t/customize-schema-migrations-table-name-on-a-gateway/1463

I implemented this as a configuration option in the hanami gem, so this
has a sibling PR in the hanami gem.  My reasoning was that this should
be a relatively stable configuration option, rather than an argument
that you need to remember to pass to `hanami db migrate` each time,
since if you forget to specify your custom table name even once,
you could potentially get your database into an odd state.

However, I would definitely be open to other ideas -- I also wasn't sure
what the best practice was for testing a configuration setting that
isn't yet in the `hanami` gem, or for backwards compatibility.

To try it out:
1. `hanami new octopus`
1. `cd octopus`
1. Adjust the gemfile to point to versions of `hanami` and `hanami-cli`
   with the relevant commits.
1. In `config/app.rb`, add `config.db.migrations_table = :hanami_migrations`
1. Use `hanami g migration` to create a new migration.  Add a table to
   it.
1. `hanami db migrate`
1. Verify that your database does not have a table named
   `schema_migrations`, and that it instead has a table named
   `hanami_migrations`.
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

ℹ️ Optional job failed: Ruby jruby

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