Created
August 28, 2014 15:14
-
-
Save lihanli/d66dfdb9730722b54716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pry' | |
file = ARGV[0] | |
raise('dump not found') unless File.exists?(file) | |
UNPAKT_DIR = '/Users/Unpakt/workspace/unpakt' | |
def run(cmd, raise_on_error: true, output: false, bundle_exec: false, working_dir: false) | |
cmd = "bundle exec #{cmd}" if bundle_exec | |
cmd = "cd #{working_dir}; #{cmd}" if working_dir | |
return_val = output ? system(cmd) : `#{cmd}` | |
raise if raise_on_error && !$?.success? | |
return_val | |
end | |
raise('database in use') if run('rake db:drop db:create 2>&1', bundle_exec: true, working_dir: UNPAKT_DIR).include?("Couldn't drop") | |
run("pg_restore --clean -x -O -U postgres -d movingbox_dev #{file}", raise_on_error: false) | |
run('rake db:migrate utils:obfuscate db:test:prepare', output: true, bundle_exec: true, working_dir: UNPAKT_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment