MigrationHistory
migration_history is a gem that helps track migration history in Rails projects. It provides a simple way to see when tables and columns were added, along with other details from your migration files. You can view this information in either CLI or HTML format.
Installation
Add this line to your application's Gemfile:
gem 'migration_history'And then execute:
$ bundle
Or install it yourself as:
$ gem install migration_history
Usage
Track When a Table or Column Was Added with Filters
With the filter command, you can query the migration history to find out when a specific table or column was added to your database. This allows you to focus on specific changes to your schema, such as the creation of a table or the addition of a column.
Example: Filter by Table Name To find out when a specific table, such as users, was created, you can filter the migration history by table name. For example:
bundle exec migration_history filter --table usersExample Output:
ClassName: AddUsersTable, Timestamp: 2020-01-02 12:30:45Example: Filter by Table Name and Column Name To find out when a specific column, such as email, was added to a table, you can filter the migration history by table and column name. For example:
bundle exec migration_history filter --table users --column emailExample Output:
ClassName: AddEmailColumnToUsersTable, Timestamp: 2020-01-02 12:30:45Example: No Filter, All migration history To view the entire migration history in the terminal:
bundle exec migration_history allHTML and JSON Output
You can have more readable output by using the --format option to output the result in HTML or JSON formats.
Example: with HTML Output
bundle exec migration_history all --format=htmlBy default, the output file name will be migration_history.html. You can specify the output file name by using the --output option.
The generated HTML file looks like this:
In this HTML file, you can filter the migration history by table name, column name, keyword search, target table, action, and date range.
Example: with JSON Output
bundle exec migration_history all --format=jsonDevelopment
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/a5-stable/migration_history. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the MigrationHistory project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.