From 64f97a89d24a589828b0dbf58a417290951fb6e4 Mon Sep 17 00:00:00 2001 From: carlad Date: Thu, 11 Feb 2016 10:13:05 +0100 Subject: [PATCH] add db creation and migration for development, update readme --- README.md | 8 ++++---- Rakefile | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b72bb7c8..9b02729f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is the app running on https://api.travis-ci.org/ 1. PostgreSQL 9.3 or higher 1. Redis 1. RabbitMQ -1. Nginx *NB: If working on Ubuntu please install Nginx manually from source. [This guide](http://www.rackspace.com/knowledge_center/article/ubuntu-and-debian-installing-nginx-from-source) is helpful but make sure you install the [latest stable version](https://www.nginx.com/resources/wiki/start/topics/tutorials/install/#stable), include the user name on your ubuntu machine when compiling (add `--user=[yourusername]` as an option when running `./configure`), and don't follow any subsequent server configuration steps. Travis-api will start and configure its own nginx server when run locally. +1. Nginx *NB: If working on Ubuntu please install Nginx manually from source. [This guide](http://www.rackspace.com/knowledge_center/article/ubuntu-and-debian-installing-nginx-from-source) is helpful but make sure you install the [latest stable version](https://www.nginx.com/resources/wiki/start/topics/tutorials/install/#stable), include the user name on your ubuntu machine when compiling (add `--user=[yourusername]` as an option when running `./configure`), and don't follow any subsequent server configuration steps. Travis-api will start and configure its own nginx server when run locally. ## Installation @@ -17,8 +17,8 @@ This is the app running on https://api.travis-ci.org/ ### Database setup -1. `rake db:create db:migrate` -2. for testing 'RAILS_ENV=test bundle exec rake db:create db:migrate --trace' +1. `bundle exec rake db:create` +2. for testing 'RAILS_ENV=test bundle exec rake db:create --trace' 1. Clone `travis-logs` and copy the `logs` database (assume the PostgreSQL user is `postgres`): ```sh-session cd .. @@ -31,7 +31,7 @@ pg_dump -t logs travis_logs_development | psql -U postgres travis_development Repeat the database steps for `RAILS_ENV=test`. ```sh-session -RAILS_ENV=test rake db:create db:structure:load +RAILS_ENV=test bundle exec rake db:create pushd ../travis-logs RAILS_ENV=test rvm jruby do bundle exec rake db:migrate psql -c "DROP TABLE IF EXISTS logs CASCADE" -U postgres travis_test diff --git a/Rakefile b/Rakefile index 224ae1fb..93c7d171 100644 --- a/Rakefile +++ b/Rakefile @@ -4,12 +4,18 @@ require 'travis/migrations' task default: :spec namespace :db do - desc 'Create the test database' - task :create do - sh 'createdb travis_test' rescue nil - sh 'mkdir spec/support/db' - sh "cp #{Gem.loaded_specs['travis-migrations'].full_gem_path}/db/structure.sql spec/support/db/structure.sql" - sh 'psql -q travis_test < spec/support/db/structure.sql' + if ENV["RAILS_ENV"] == 'test' + desc 'Create and migrate the test database' + task :create do + sh 'createdb travis_test' rescue nil + sh "psql -q travis_test < #{Gem.loaded_specs['travis-migrations'].full_gem_path}/db/structure.sql" + end + else + desc 'Create and migrate the development database' + task :create do + sh 'createdb travis_development' rescue nil + sh "psql -q travis_development < #{Gem.loaded_specs['travis-migrations'].full_gem_path}/db/structure.sql" + end end end