Skip to content

Instantly share code, notes, and snippets.

@deanrad
Created December 4, 2009 17:20
Show Gist options
  • Save deanrad/249177 to your computer and use it in GitHub Desktop.
Save deanrad/249177 to your computer and use it in GitHub Desktop.
# MY FIRST (NON-WORKING) ATTEMPT - borrowing from rails/lib/console_sanbox..
# I think it works only for console where a single connection can be counted on
# Allow for server to run in a mode where xactions are rolled back on exit,
# like script/console's --sandbox option. eg: > SANDBOX=1 script/server -p 3001
if ENV['SANDBOX']=="1"
$stderr.puts "NOTE: YOU ARE RUNNING IN SANDBOX MODE, ALL XACTIONS WILL ABORT ON EXIT"
conf = YAML::load( File.open(RAILS_ROOT + '/config/database.yml'))[RAILS_ENV]
$stderr.puts conf.inspect
ActiveRecord::Base.establish_connection(conf)
ActiveRecord::Base.connection.begin_db_transaction
at_exit do
ActiveRecord::Base.connection.rollback_db_transaction
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment