luismottacampos / pt-osc

Ruby on Rails migrations via pt-online-schema-change
MIT License
24 stars 9 forks source link

Travis CI Code Climate Code Coverage Gem Version Dependencies

pt-online-schema-change migrations

Runs regular Rails/ActiveRecord migrations via the Percona Toolkit pt-online-schema-change tool.

WARNING: I am not actively contributing this project any more.
PRs to fix bugs and add features are welcome, but do not expect feature requests to go answered.

Installation

Add this line to your application's Gemfile:

gem 'pt-osc'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pt-osc

Usage

Set your database adapter to be mysql_pt_osc in your application's database.yml. Specify pt-online-schema-change flags in a percona hash in the config. e.g.

environment:
  host: localhost
  username: root
  database: rails
  percona:
    defaults-file: /etc/mysql/percona-user.cnf
    recursion-method: "'dsn=D=percona,t=slaves'"

Additional/modified options for the percona hash include:

Migrations

To run migrations with pt-online-schema-change, you need to explicitly opt them in by changing their parent class to ActiveRecord::PtOscMigration. For instance, if your migration was

class CreateTeams < ActiveRecord::Migration

you should change it to

class CreateTeams < ActiveRecord::PtOscMigration

If you have migrations that you do not want to be run with pt-online-schema-change, leave the same parent class and they will be run normally.

Caveats

This gem is not considered production ready. There will be bugs.

Requirements and Compatibility
ActiveRecord
Ruby
Percona Toolkit

Support for other versions of these tools is unknown and not guaranteed.

pt-osc requires the use of pt-online-schema-change 2.0 or later. Some options may not work with all versions.

pt-osc is compatible with versions 0.5.0 and later of zdennis/activerecord-import. It will not work with earlier versions.

Testing

create a machine for pt-osc, this should only be needed once

docker-machine create pt-osc --driver virtualbox

every new shell that needs to access pt-osc within docker needs to run:

eval $(docker-machine env pt-osc)

to access the docker shell

docker-compose run pt-osc bash

useful commands in docker shell

create the initial database within mysql for tests, only needed once

bundle exec rake db:test_create

run the tests in docker

bundle exec rake