Permalink
Browse files

allow you to set the epoch for the 2nd part of a two-phase migration

  • Loading branch information...
1 parent f3f27cd commit 9ee6798c7fc0552e34caa3518fea9448760c4146 @technoweenie technoweenie committed with Feb 16, 2010
Showing with 11 additions and 2 deletions.
  1. +5 −1 README.md
  2. +2 −1 lib/table_migrator/base.rb
  3. +4 −0 lib/table_migrator/copy_engine.rb
View
@@ -167,17 +167,21 @@ First, you deploy the code with the migration and manually run the `#create_tabl
# if you use a TableMigration sublcass
>> require 'db/migrate/13423423_my_migration.rb'
+ >> now = Time.now
>> MyMigration.create_table_and_copy_info
+ >> puts %(NEXT_EPOCH="#{now}")
+ NEXT_EPOCH="Tue Feb 16 13:22:14 -0800 2010"
This creates the temporary table, copies the data over without locking anything. You can safely run this without halting your application.
Finally, you put up whatever downtime notices you have and run your typical migration task. Since the table is already created, the script will only
copy data (if multi_pass is enabled) and perform the actual table move. It assumes the temporary table has been created already.
+ $ NEXT_EPOCH="Tue Feb 16 13:22:14 -0800 2010" RAILS_ENV=production rake db:migrate
+
## Contributors
- Matt Freels
- Rohith Ravi
- Rick Olson
-
Copyright (c) 2009 Serious Business, released under the MIT license.
@@ -12,6 +12,7 @@ def initialize(table, config = {})
end
def up!
+ engine.set_epoch(Time.parse(ENV['NEXT_EPOCH'])) if !ENV['NEXT_EPOCH'].blank?
engine.up!
end
@@ -70,7 +71,7 @@ def connection
end
def engine
- CopyEngine.new(strategy)
+ @engine ||= CopyEngine.new(strategy)
end
end
end
@@ -151,6 +151,10 @@ def info_with_time(str, &block)
# Manage the Epoch
+ def set_epoch(time)
+ @next_epoch = time
+ end
+
def flop_epoch
epoch = @next_epoch
@next_epoch = self.next_epoch

0 comments on commit 9ee6798

Please sign in to comment.