ghost_adapter

Run ActiveRecord migrations through gh-ost


Keywords
activerecord, gh-ost, ghost, mysql, rails, ruby
License
Hippocratic-2.1
Install
gem install ghost_adapter -v 0.2.0

Documentation

Ghost Adapter

ghost

Gem GitHub Actions Workflow Hippocratic License gh-ost version

A tiny, very configurable ActiveRecord adapter built for running gh-ost migrations. When not running migrations, it'll stay the heck out of the way.

Installation

First, you'll need to install gh-ost. You can find the latest release here. You can check the allowed version range in the version checker (current range: [>= 1.1.0, < 2]). Once you've got that installed, install the gem!

Add this line to your application's Gemfile:

gem 'ghost_adapter'

And then execute:

$ bundle install

Usage

Connect with ActiveRecord

Configure your ActiveRecord connection to use mysql2_ghost as the adapter in whichever environments you'd like to use gh-ost.

For a standard rails project, in config/database.yml set adapter: mysql2_ghost.

For usage with DATABASE_URL, only a very tiny modification is necessary. The URL should be like: mysql2-ghost:// (notice the - instead of _). This is because the scheme of a URI must be either alphanumeric or one of [-, ., +] (more details)

Configuration

You can configure ghost_adapter with (nearly) all of the arguments allowed gh-ost in the command line. The arguments are up to date as of gh-ost version 1.1.0.

Read more about configuration methods in the docs.

Running Migrations

Since most database activity isn't a migration, we default to just using the Mysql2Adapter. No need to be executing a bunch of extra logic per query when you're only getting any value for migrations.

To enable the ghost adapter, you have two options. First (recommended) is to use the provided rails generator:

rails g ghost_adapter:install

This does everything you need. All migrations will run through gh-ost and otherwise the adapter will be ignored.

Alternatively, you can enable (or disable) gh-ost migrations with an environment variable.

GHOST_MIGRATE=1 rake db:...

If you have used the rails generator, you can set the variable to a falsey value and it will override the behavior not to use gh-ost.

  • "truthy" values: [1, t, true, y, yes]
  • "falsey" values: [0, f, false, n, no]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wetransfer/ghost_adapter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct. Please add your name to the CONTRIBUTORS.md

License

The gem is available as open source under the terms of the Hippocratic License.

Code of Conduct

Everyone interacting in the Ghost Adapter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.


Illustration by Icons 8 from Icons8