vivrass / no_downtime_migrations

Collection of tools to ease migrations without downtime

Home Page:http://www.pagerduty.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no_downtime_migrations

No Downtime Migrations is useful when you want to limit as possible your downtime when upgrading the production environment.

Strategies

Mirror columns (Rename database columns)

The strategy to rename a database column is the following:

  1. Add a new column(s) in the table with the expected characteristic

  2. Add database trigger (keep old and new columns in sync)

  3. Update your code

  4. Remove the old columns and the triggers

To create the triggers, the method call in migration is : add_mirror_column TABLE_NAME, {OLD_COLUMN => NEW_COLUMN}. You can see an example in test_app/db/migrate/2_create_mirror_columns.rb.

To remove the triggers, the method call in migration is : remove_mirror_column TABLE_NAME, {OLD_COLUMN => NEW_COLUMN}. You can see an example in test_app/db/migrate/3_remove_mirror_columns.rb.

Advantages

You don’t need to stop you application to migrate your database. Once the migration with triggers is made your old and new code will be compatible with the database without any more effort in you application. You’ll even be able to rollback you application if any problem occur during the update without loosing any data.

Performance

In the sample app in test_app for 100k users in the database

  • add_mirror_columns takes around 4s (with the column data copy) + column creation time (1.5s)

  • remove_mirror_columns takes around 0.006s + column remove time (1.3s)

  • read is constant before, during and after triggers

  • write while trigger is present is 0.1ms slower (1s / 10000 users)

Contributing to no_downtime_migrations

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2012 PagerDuty inc. See LICENSE.txt for further details.

About

Collection of tools to ease migrations without downtime

http://www.pagerduty.com

License:MIT License


Languages

Language:Ruby 98.9%Language:JavaScript 1.1%