Added Rakefile

This commit is contained in:
Yann Esposito (Yogsototh) 2010-08-20 09:42:50 +02:00
parent a3edc5c24c
commit 7335524716
2 changed files with 32 additions and 2 deletions

32
Rakefile Normal file
View file

@ -0,0 +1,32 @@
namespace "db" do
task :std_db_action, [:action] do |t,args|
require 'rubygems'
require 'global_config'
require 'dm-core'
require 'dm-migrations'
# Connect to DB
DataMapper.setup(:default, $db_url)
# Include all models
Dir["app/models/*.rb"].each { |file| require file }
# Reset tables
DataMapper.finalize
if args.action == 'migrate'
DataMapper.auto_migrate!
puts 'migration finished'
elsif args.action == 'upgrade'
DataMapper.auto_upgrade!
puts 'upgrade finished'
else
puts 'std_db_action [migrate|upgrade]'
end
end
task :migrate do
Rake.application.invoke_task("db:std_db_action[migrate]")
end
task :upgrade do
Rake.application.invoke_task("db:std_db_action[upgrade]")
end
end

View file

@ -20,5 +20,3 @@ constructed_db_url<<="#{$db_password}" if not $db_password.nil?
constructed_db_url<<="@#{$db_host}/" if not $db_host.nil?
constructed_db_url<<="@#{$db_database}" if not $db_database.nil?
$db_url=ENV['DATABASE_URL'] || constructed_db_url
puts $db_url