add db creation and migration for development, update readme

This commit is contained in:
carlad 2016-02-11 10:13:05 +01:00
parent 6ab0ec3c3a
commit 64f97a89d2
2 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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