inchworm

inchworms

Summer of Coding, one inch at a time...

Rakefile

inchworms -

Today we needed a lot of chocolade

to survive the day. The weather makes us depressed.

Anyway, we are starting to put more structure into our project

strucure

and in the rakefile ;) A rakefile is needed to get more organized, run different ruby scripts in an specific order and that’s what we like.

The old rakefile:

namespace :db do 
  task :migrate do
    require "sequel"
    Sequel.extension :migration
    DB = Sequel.postgres("farmsubsidy_development")
    Sequel::Migrator.run(DB, './db/migrations', :use_transactions=>true)
  end

  task :set_up_performance_test_db do
    require "sequel"
    Sequel.extension :migration

    #check to see if performance DB already exists
    the_database_is_there = system("psql -l | grep farmsubsidy_performance")
    if the_database_is_there
      #if it does then drop the db 
      system("dropdb farmsubsidy_performance")
    end
    #and recreate it
    system("createdb farmsubsidy_performance")

    DB = Sequel.postgres("farmsubsidy_performance")
    Sequel::Migrator.run(DB, './db/migrations', :use_transactions=>true)
  end

  task :run_any_new_migration do
    require "sequel"
    Sequel.extension :migration

    DB = Sequel.postgres("farmsubsidy_performance_add_top_payments")
    Sequel::Migrator.run(DB, './db/migrations', :use_transactions=>true)
  end

end

The new rakefile:

require 'csv'
require 'logger'
require "sequel"

Sequel.extension :migration

#include all .rake files in lib/tasks directory
Dir.glob('lib/tasks/*.rake').each { |r| import r }

#take the database_name variable from command line input or fall back to default: test_db
#i.e. rake db:createandmigrate database_name=xxxx  
@database_name = ENV['database_name'] || 'farmsubsidy_test_db'

Done!

rake