cruisecontrol.rb, seed data, and FKs

Custom cruisecontrol.rb task to handle migrations with seed data. (for when standard cruise build task yields FK constraint violations when the fixtures start loading).

#This builds from migrations each time (slower, but more reliable).  
#Must then empty seed data before tests start to delete stuff, or FK constraints get violated.  

task :cruise do
  ENV['RAILS_ENV'] = 'test'
  puts "custom cruise task invoked.  env is hardcoded to test"

  Rake::Task["environment"].invoke
  #start from scratch with just the test db
  Rake::Task["db:test:purge"].invoke
  #necessary to reconnect, as purge drops database (and w mysql the conn)
  CruiseControl::reconnect

  #run all migrations from scratch.  slow but clean
  Rake::Task["db:migrate"].invoke

  #empty the db of data - migration has loaded seed data into the tables, 
  #which'll be deleted badly by test fixtures loader.

  #NOTE: db:test:purgetwo is just a quick hack to force this identical action to be called again
  #TODO: replace with the correct way to force execution of a task in rake
  Rake::Task["db:test:purgetwo"].invoke
  #necessary to reconnect, as purge drops database (and w mysql the conn)
  CruiseControl::reconnect

  #the migration has already done a schema dump
  Rake::Task["db:schema:load"].invoke

  success = Rake::Task["test"].invoke
  success
end

Embarrassingly, this currently needs ‘db:test:purgetwo’ to exist. I just copied pasted db:test:purge task. The correct way would be to look at how to ensure task execution in rake, but debugging cruisecontrol.rb exhausted all my patience and sanity.

See also What ‘rake test’ does.

5 Responses to “cruisecontrol.rb, seed data, and FKs”

  1. Cheap shoes online mbt shoes sale Says:

    good job,guy,it’s kind of u share this post with us which give useful information to us.God Job!I do hope u can publish more posts later.buy the way ,if you wanna buy cheap brand shoes online,you may visit our shoes store,i am sure you will find what u like.

  2. km Says:

    Sorry, but your comment has been flagged by the spam filter running on this blog: this might be an error, in which case all apologies. Your comment will be presented to the blog admin who will be able to restore it immediately.
    You may want to contact the blog admin via e-mail to notify him.

  3. batterie Says:

    I do hope u can publish more posts later.b

  4. labatterie Says:

    You may want to contact the blog admin via e-mail to notify him.

  5. Tony p90x Says:

    Very useful information, tks for sharing!

Leave a Reply