Git Product home page Git Product logo

departure's Introduction

Departure Build Status Code Climate

Departure is an ActiveRecord connection adapter that allows running MySQL online and non-blocking DDL through ActiveRecord::Migration without needing to use a different DSL other than Rails' migrations DSL.

It uses pt-online-schema-change command-line tool of Percona Toolkit which runs MySQL alter table statements without downtime.

Rename from "Percona Migrator"

This project was formerly known as "Percona Migrator", but this incurs in an infringement of Percona's trade mark policy and thus has to be renamed. Said name is likely to cause confusion as to the source of the wrapper.

The next major versions will use "Departure" as gem name.

Installation

Departure relies on pt-online-schema-change from Percona Toolkit

Mac

brew install percona-toolkit

Linux

Ubuntu/Debian based

apt-get install percona-toolkit

Arch Linux

pacman -S percona-toolkit perl-dbd-mysql

Other distros

For other Linux distributions check out the Percona Toolkit download page to find the package that fits your distribution.

You can also get it from Percona's apt repository

Once installed, add this line to your application's Gemfile:

gem 'percona_migrator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install percona_migrator

Usage

Once you added it to your app's Gemfile, you can create and run Rails migrations as usual.

All the ALTER TABLE statements will be executed with pt-online-schema-change, which will provide additional output to the migration.

LHM support

If you moved to Soundcloud's Lhm already, we got you covered. Departure overrides Lhm's DSL so that all the alter statements also go through pt-online-schema-change as well.

You can keep your Lhm migrations and start using Rails migration's DSL back again in your next migration.

Configuration

You can override any of the default values from an initializer:

PerconaMigrator.configure do |config|
  config.tmp_path = '/tmp/'
end

It's strongly recommended to name it after this gems name, such as config/initializers/percona_migrator.rb

How it works

When booting your Rails app, Departure extends the ActiveRecord::Migration#migrate method to reset the connection and reestablish it using the PerconaAdapter instead of the one you defined in your config/database.yml.

Then, when any migration DSL methods such as add_column or create_table are executed, they all go to the PerconaAdapter. There, the methods that require ALTER TABLE SQL statements, like add_column, are overriden to get executed with PerconaMigrator::Runner, which deals with the pt-online-schema-change binary. All the others, like create_table, are delegated to the ActiveRecord's built in Mysql2Adapter and so they follow the regular path.

PerconaMigrator::Runner spawns a new process that runs the pt-online-schema-change binary present in the system, with the apropriate arguments for the generated SQL.

When an any error occurs, an ActiveRecord::StatementInvalid exception is raised and the migration is aborted, as all other ActiveRecord connection adapters.

Development

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/redbooth/percona_migrator.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Check the code of conduct here

Changelog

You can consult the changelog here

License

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

departure's People

Contributors

enricostano avatar franciscoj avatar ivanilves avatar morantron avatar sauloperez avatar sdonataccio-handy avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.