Skip to content

Instantly share code, notes, and snippets.

@chrislloyd
Created January 15, 2012 00:36
Show Gist options
  • Save chrislloyd/1613600 to your computer and use it in GitHub Desktop.
Save chrislloyd/1613600 to your computer and use it in GitHub Desktop.
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
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