Skip to content

Instantly share code, notes, and snippets.

@gonzedge
Created November 23, 2011 03:09
Show Gist options
  • Save gonzedge/1387792 to your computer and use it in GitHub Desktop.
Save gonzedge/1387792 to your computer and use it in GitHub Desktop.
Stripping down Rails 3.1: Using only the database migrations
tasks = [:create, :drop, :migrate, :rollback, :version, :seed, :setup]
tasks.each do |name|
task name do
sh "rake db:#{name.to_s} RAILS_ENV={environment}"
end
end
source 'http://rubygems.org'
gem 'git-deploy'
gemfile = File.open(File.join(File.dirname(__FILE__), 'deploy', 'Gemfile'))
eval gemfile.read
rails new deploy
rakefile = File.open(File.join(File.dirname(__FILE__), 'deploy', 'Rakefile'))
eval rakefile.read.gsub(/config/, 'deploy/config')
task :generate do
arguments = ARGV.find { |a| a.start_with?('GENERATE=') }
arguments = arguments.split('=')[1] unless arguments.nil?
sh "cd deploy; rails generate #{arguments}" unless arguments.nil? or arguments.empty?
end
db_tasks_file = File.open(File.join(File.dirname(__FILE__), 'deploy', 'lib', 'tasks', 'db.rb'))
db_tasks = db_tasks_file.read
namespace :db do
namespaces = [:test, :production]
namespaces.each do |name|
namespace name do
eval db_tasks.gsub(/{environment}/, name.to_s)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment