Added Rakefile
This commit is contained in:
parent
a3edc5c24c
commit
7335524716
2 changed files with 32 additions and 2 deletions
32
Rakefile
Normal file
32
Rakefile
Normal 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
|
|
@ -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…
Reference in a new issue