Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add simplified db_setup script that just sets up a test db

  • Loading branch information...
commit fbd0e7317e7c456559804c4888cea24753357a82 1 parent 1f0593b
@janxious janxious authored
Showing with 41 additions and 3 deletions.
  1. +1 −3 README.md
  2. +40 −0 test/script/db_setup
View
4 README.md
@@ -82,10 +82,8 @@ MySQL instead of the more convenient sqlite. Running the tests should
be as easy as:
``` bash
-cd ./test/aaa_test_app/
bundle
-script/db_setup -c # makes the databases with the correct permissions
-cd ../.. # back in the AAA root
+test/script/db_setup # makes the databases with the correct permissions (for mySQL)
rake
```
View
40 test/script/db_setup
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+require "bundler/setup"
+require "active_record"
+require "yaml"
+require 'highline/import'
+
+database_file = File.join(File.dirname(__FILE__), "/../", "database.yml")
+
+$DB_CONFIG = YAML.load(File.read(database_file))
+
+$ROOT_PW = ask("Provide root mySQL password to setup '#{$DB_CONFIG["database"]}': ") { |q| q.echo = false}
+if !$ROOT_PW || $ROOT_PW.empty?
+ puts "error reading password"
+ exit 4
+end
+
+password_check = "echo 'show databases;' | mysql -u root -p'#{$ROOT_PW}' > /dev/null"
+unless system password_check
+ puts "incorrect password"
+ exit 7
+end
+
+def execute_mysql(message, statement, user = nil, password = nil)
+ puts message
+ `echo '#{statement}' | mysql -u #{user} -p'#{password}'`
+end
+
+db = $DB_CONFIG["database"]
+user = "root"
+pass = $ROOT_PW
+
+drop_statement = "drop database if exists #{db};"
+create_statement = "create database #{db};"
+grant_statement = "grant all on `#{db}`.* to `#{$DB_CONFIG["username"]}`@`localhost` identified by \"#{$DB_CONFIG["password"]}\";"
+
+execute_mysql("dropping #{db}", drop_statement, user, pass)
+
+execute_mysql("creating #{db}", create_statement, user, pass)
+
+execute_mysql("granting on #{db}", grant_statement, user, pass)
Please sign in to comment.
Something went wrong with that request. Please try again.