diff options
author | mguetlein <martin.guetlein@gmail.com> | 2010-06-02 12:10:11 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2010-06-02 12:10:11 +0200 |
commit | 32c6fae5eba64293efd25bb7db177f1964ee2625 (patch) | |
tree | 0089a16f46ef8f9cdfb6fdcf64d936c56d71345d /Rakefile | |
parent | 01dbc229e6a3483bd18d028f5cab3483c10ca43c (diff) |
replacing datamapper with activerecord for validation objects
Diffstat (limited to 'Rakefile')
-rw-r--r-- | Rakefile | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -18,3 +18,47 @@ task :test do load 'test.rb' end +desc "load config" +task :load_config do + require 'yaml' + ENV['RACK_ENV'] = 'test' unless ENV['RACK_ENV'] + basedir = File.join(ENV['HOME'], ".opentox") + config_dir = File.join(basedir, "config") + config_file = File.join(config_dir, "#{ENV['RACK_ENV']}.yaml") + if File.exist?(config_file) + @@config = YAML.load_file(config_file) + raise "could not load config, config file: "+config_file.to_s unless @@config + end + puts "config loaded" +end + +# USER VERSION 0 instead +#desc "Clear database" +#task :clear_db => :load_config do +# if @@config[:database][:adapter]=="mysql" +# clear = nil +# IO.popen("locate clear_mysql.sh"){ |f| clear=f.gets.chomp("\n") } +# raise "clear_mysql.sh not found" unless clear +# cmd = clear+" "+@@config[:database][:username]+" "+@@config[:database][:password]+" "+@@config[:database][:database] +# IO.popen(cmd){ |f| puts f.gets } +# else +# raise "clear not implemented for database-type: "+@@config[:database][:adapter] +# end +#end + +desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" +task :migrate => :load_config do + require 'active_record' + ActiveRecord::Base.establish_connection( + :adapter => @@config[:database][:adapter], + :host => @@config[:database][:host], + :database => @@config[:database][:database], + :username => @@config[:database][:username], + :password => @@config[:database][:password] + ) + ActiveRecord::Base.logger = Logger.new($stdout) + ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil ) +end + + + |