2016-03-08 33 views
1

因此,我一直在研究一個Rails項目整晚,並決定特拉維斯會很好,因爲我可以從我的更改GitHub Windows機器(哪些測試不起作用)到Travis,並且在成功構建/測試時,我可以將最新版本提供給服務器。Travis CI「ActiveRecord :: NoDatabaseError:致命:數據庫」jobTrak_test「不存在」

但是,爲了保護我的個人信息,database.yml和and secrets.yml已放入.gitingore中,並替換爲示例文件。

因此,我需要與Travis做一些額外的工作才能生成數據庫。

.travis.yml:

# Travis CI Configuration 
language: ruby 
rvm: 
    - 2.2.3 
services: 
    - postgresql 
before_script: 
    - psql -c 'create database jobTrak_test;' -U postgres 
    - cp config/database.yml.travis config/database.yml 

database.yml.travis:

# Database config 
test: 
    adapter: postgresql 
    database: jobTrak_test 
    username: postgres 

Travis Build Log

,我沒有看到任何其他的在線,所以我清楚地做一些事情這裏錯了。

如果您需要任何其他信息,請告訴我。

回答

0

嘗試創建數據庫軌方式

before_script: 
    - cp config/database.yml.travis config/database.yml 
    - RAILS_ENV=test bundle exec rake db:create 
1

添加服務和before_script條目到.travis.yml固定一個類似的錯誤,我

language: ruby 

bundler_args: --without production 

services: 
    - postgresql 

before_script: 
    - psql -c 'create database marina_test;' -U postgres 

在特拉維斯文檔看看: https://docs.travis-ci.com/user/database-setup/#PostgreSQL

0

您應該嘗試指定DB類型:

env: 
    - DB=pgsql 

注意:postgresql和postgres不起作用。請使用pgsql!

下面是完整的代碼爲我工作:

.travis.yml

language: ruby 

rvm: 
    - 2.2 

env: 
    - DB=pgsql 

services: 
    - postgresql 

script: 
    - RAILS_ENV=test bundle exec rake db:migrate --trace 
    - bundle exec rake db:test:prepare 
    - bundle exec rake 

before_script: 
    - cp config/database.yml.travis config/database.yml 
    - psql -c 'create database courseselect_test;' -U postgres 

配置/ database.yml.travis

default: &default 
    adapter: postgresql 
    encoding: unicode 
    pool: 5 

development: 
    <<: *default 
    database: courseselect_development 

test: 
    <<: *default 
    database: courseselect_test 

production: 
    <<: *default 
    database: courseselect_developement 

順便說一句,我也文件config/database.ymlconfig/database.yml.travis