Skip to content

Instantly share code, notes, and snippets.

@masaru-tech
Last active September 26, 2017 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masaru-tech/c670a11fdebb35c6bac3bc2307576854 to your computer and use it in GitHub Desktop.
Save masaru-tech/c670a11fdebb35c6bac3bc2307576854 to your computer and use it in GitHub Desktop.
Rake::TaskManager.class_eval do
def alias_task(fq_name)
new_name = "#{fq_name}:original"
@tasks[new_name] = @tasks.delete(fq_name)
end
end
def alias_task(fq_name)
Rake.application.alias_task(fq_name)
end
def override_task(*args, &block)
name, params, deps = Rake.application.resolve_args(args.dup)
fq_name = Rake.application.instance_variable_get(:@scope).path + ":#{name}"
alias_task(fq_name)
Rake::Task.define_task(*args, &block)
end
namespace :db do
override_task :migrate => :environment do
ENV['RAILS_ENV'] ||= "development"
sh "bundle exec ridgepole -E #{ENV['RAILS_ENV']} -c config/database.yml -f db/Schemafile --apply"
end
task 'ridgepole:export' => :environment do
ENV['RAILS_ENV'] ||= "development"
sh "bundle exec ridgepole -E #{ENV['RAILS_ENV']} -c config/database.yml --export -o db/Schemafile"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment