Created
January 15, 2012 00:36
-
-
Save chrislloyd/1613600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
task :pivot => :environment do | |
schema = Mongoid::Config.master[:schema_info] | |
pivots = Dir[File.join('db', 'pivots', '*.rb')] | |
previous_pivots = schema.find.map {|p| p['file']} | |
pivots_to_run = (pivots - previous_pivots).sort | |
def log(str) | |
puts " * #{str}" | |
end | |
pivots_to_run.each do |pivot| | |
start = Time.now | |
load(pivot) | |
puts "#{pivot} - #{(Time.now - start).to_i}s" | |
schema.insert(file: pivot, at: Time.now) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PivotGenerator < Rails::Generators::Base | |
def create_migration_file | |
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S") | |
filename = "#{timestamp}.rb" | |
create_file File.join('db', 'pivots', filename), <<-EOF | |
# Describe pivot | |
EOF | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment