Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

gemified table_migrator #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gem
1 change: 0 additions & 1 deletion init.rb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/table_migration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'active_record'
require 'table_migrator/base'

class TableMigration < ActiveRecord::Migration
class << self
attr_reader :table_migrator
Expand Down
3 changes: 3 additions & 0 deletions lib/table_migrator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'table_migration'
require 'table_migrator/base'

module TableMigrator
extend self

Expand Down
5 changes: 5 additions & 0 deletions lib/table_migrator/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
require 'active_record'
require 'table_migrator/copy_engine'
require 'table_migrator/change_table_strategy'
require 'table_migrator/raw_sql_strategy'

module TableMigrator
class Base

Expand Down
3 changes: 3 additions & 0 deletions lib/table_migrator/change_table_strategy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'active_record'
require 'table_migrator/copy_strategy'

module TableMigrator

class ChangeTableStrategy < CopyStrategy
Expand Down
2 changes: 2 additions & 0 deletions lib/table_migrator/copy_engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_record'

module TableMigrator
class CopyEngine

Expand Down
2 changes: 2 additions & 0 deletions lib/table_migrator/raw_sql_strategy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'table_migrator/copy_strategy'

module TableMigrator
class RawSqlStrategy < CopyStrategy
attr_accessor :base_copy_query, :schema_changes
Expand Down
26 changes: 26 additions & 0 deletions table_migrator.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = "table_migrator"
s.version = '0.0.1.dev'
s.platform = Gem::Platform::RUBY
s.authors = ["Matt Freels", "Rohith Ravi", "Rick Olson",]
s.email = ["[email protected]"]
s.homepage = "http://github.com/freels/table_migrator"
s.summary = "Zero-downtime table migration in MySQL"
s.description = <<-EOF
TableMigrator is a method for altering large MySQL tables while incurring
as little downtime as possible. First, we create a new table like the
original one, and then apply one or more ALTER TABLE statements to the
unused, empty table. Second we copy all rows from the original table into
the new one. All this time, reads and writes are going to the original
table, so the two tables are not consistent. Finally, we acquire a write
lock on the original table before copying over all new/changed rows, and
swapping in the new table.
EOF

s.add_dependency "activerecord", "~>2.3.5"

s.files = Dir.glob("lib/**/*") +%w[README.md]
s.require_path = 'lib'
end