Skip to content

Instantly share code, notes, and snippets.

@dillonhafer
Created March 12, 2015 14:52
Show Gist options
  • Save dillonhafer/b993f1e0d3009b55936d to your computer and use it in GitHub Desktop.
Save dillonhafer/b993f1e0d3009b55936d to your computer and use it in GitHub Desktop.
Cloning the dev env for tests using MySql
namespace :spec do
task :clone_structure do
environments = YAML.load(File.read('config/database.yml'))
test = environments["test"]
dev = environments["development"]
puts "Deleting #{test["database"]}..."
`echo 'DROP DATABASE #{test["database"]};' | mysql -u #{test["username"]} -p'#{test["password"]}'`
puts "Creating #{test["database"]}..."
`echo 'CREATE DATABASE #{test["database"]};' | mysql -u #{test["username"]} -p'#{test["password"]}'`
puts "Importing schema into #{test["database"]} from #{dev["database"]}..."
`mysqldump -u #{dev["username"]} -p'#{dev["password"]}' --no-data #{dev["database"]} | mysql -u #{test["username"]} -p'#{test["password"]}' #{test["database"]}`
end
desc "Clone structure from development to test and load seed data into test"
task :prepare => ["spec:clone_structure", :environment] do
puts "Creating initial seeds..."
# Seed data:
# => an initial account and user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment