Browse Source

Added Rakefile

master
parent
commit
7335524716
  1. 32
      Rakefile
  2. 2
      global_config.rb

32
Rakefile

@ -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

2
global_config.rb

@ -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

Loading…
Cancel
Save