Created
July 24, 2012 08:09
-
-
Save freshfey/3168755 to your computer and use it in GitHub Desktop.
script
This file contains hidden or 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 | |
# This is the Skillpunch boostrap file. It will help you getting your dev | |
# environment up and running in no time! | |
# Execute this script from within the root folder of the project using: | |
# => `script/bootstrap` | |
# | |
require 'rubygems' | |
require 'colored' | |
require 'hpricot' | |
# Global Variables | |
DB_USERNAME = "root" | |
DB_PASSWORD = "" | |
TEST_DATABASE = "skillpunch_test" | |
DEV_DATABASE = "skillpunch_development" | |
################## DEPENDENCY CHECKS ######################## | |
# Check if we have PostgreSQL installed: | |
unless system("which pg_ctl 2>&1 > /dev/null") | |
puts "PostgreSQL is not installed! Install it first:".red | |
puts " => brew install postgresql".yellow | |
exit(1) | |
end | |
# Check required environment variables | |
unless ENV['GOOGLE_USERNAME'] | |
puts "GOOGLE_USERNAME environment variable not set!".red | |
exit(1) | |
end | |
unless ENV['GOOGLE_PASSWORD'] | |
puts "GOOGLE_PASSWORD environment variable not set!".red | |
exit(1) | |
end | |
unless ENV['SKILLPUNCH_SPREADSHEET'] | |
puts "SKILLPUNCH_SPREADSHEET environment variable not set!".red | |
exit(1) | |
end | |
unless ENV['SKILLPUNCH_SPREADSHEET_SHEET'] | |
puts "SKILLPUNCH_SPREADSHEET_SHEET environment variable not set!".red | |
exit(1) | |
end | |
################## BUNDLER ######################## | |
puts "Running bundle install:".yellow | |
system("bundle install") | |
################# DATABASE ######################## | |
# This command will create a root user: | |
# `createuser --createdb --superuser --login root --username=postgres` | |
# | |
# This command will delete the root user: | |
# `dropuser trudi --username=postgres` | |
# ################################################# | |
# Recreate Databases | |
# => This block drops all databases for Skillpunch and | |
# creates them again from scratch. | |
# | |
print "\nRebuild the complete Database? ".yellow | |
puts "(WARNING: all data inside the dev & test database will be lost)".red | |
print "(y)es, (n)o => ".blue | |
case gets.strip | |
when 'Y', 'y', 'yes' | |
# Drop all database connections | |
puts "Dropping all connections to the database #{DEV_DATABASE}...".yellow | |
`psql postgres #{DB_USERNAME} --command="SELECT pg_terminate_backend(pg_stat_activity.procpid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '#{DEV_DATABASE}';"` | |
# Delete DEV_DATABASE | |
print "Deleting database #{DEV_DATABASE}...".red | |
`dropdb #{DEV_DATABASE} --username=#{DB_USERNAME}` | |
puts " ...done!".red | |
# Create Database DEV_DATABASE | |
print "Creating Database #{DEV_DATABASE}...".green | |
`createdb --owner=#{DB_USERNAME} --username=#{DB_USERNAME} #{DEV_DATABASE}` | |
puts " ...done!".green | |
# Migrate the database | |
puts "Running rake db:migrate:".yellow | |
system("rake db:migrate") | |
# Seed the database | |
puts "Running rake db:seed:".yellow | |
system("rake db:seed") | |
# Delete TEST_DATABASE | |
print "Deleting database #{TEST_DATABASE}...".red | |
`dropdb #{TEST_DATABASE} --username=#{DB_USERNAME}` | |
puts " ...done!".red | |
# Create Database TEST_DATABASE | |
print "Creating Database #{TEST_DATABASE}...".green | |
`createdb --owner=#{DB_USERNAME} --username=#{DB_USERNAME} #{TEST_DATABASE}` | |
puts " ...done!".green | |
# Prepare the test Database | |
puts "Running rake db:test:prepare:".yellow | |
system("rake db:test:prepare") | |
puts "Running rake db:test:load:".yellow | |
system("rake db:test:load") | |
end | |
# Add live data | |
print "\nFill the Database with production data? ".yellow | |
print "(y)es, (n)o => ".blue | |
case gets.strip | |
when 'Y', 'y', 'yes' | |
print "\nadding production data to the database...".yellow | |
system('rake db:import') | |
end | |
################## RUN TESTS ######################## | |
puts "\nRunning tests now...".green | |
system("bundle exec rspec") | |
################## FINISHED ######################## | |
puts "\n Sweet, my job here is done!".green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment