Rails database setup on Travis-CI

后端 未结 3 981
执笔经年
执笔经年 2021-01-30 23:02

I\'m trying to use Travis Continuous Integration on a Rails project. The documentation says that the test db must be configured as following for SQLite3:

test:
          


        
3条回答
  •  深忆病人
    2021-01-30 23:30

    My solution for this problem is fully based on a blog post with a few differences:

    1. Travis CI specific settings in config/database.travis.yml;
    2. cp config/database.travis.yml config/database.yml in before script section of .travis.yml;
    3. I don't have config/database.yml in source tree.

    Here is full listing for both files:

    # .travis.yml
    language: ruby
    rvm:
      - 1.9.3
    env:
      - DB=sqlite
      - DB=mysql
      - DB=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.travis.yml config/database.yml
      - mysql -e 'create database strano_test'
      - psql -c 'create database strano_test' -U postgres
    
    
    # config/database.travis.yml
    sqlite: &sqlite
      adapter: sqlite3
      database: db/<%= Rails.env %>.sqlite3
    
    mysql: &mysql
      adapter: mysql2
      username: root
      password:
      database: strano_<%= Rails.env %>
    
    postgresql: &postgresql
      adapter: postgresql
      username: postgres
      password:
      database: strano_<%= Rails.env %>
      min_messages: ERROR
    
    defaults: &defaults
      pool: 5
      timeout: 5000
      host: localhost
      <<: *<%= ENV['DB'] || "postgresql" %>
    
    development:
      <<: *defaults
    
    test:
      <<: *defaults
    
    production:
      <<: *defaults
    

提交回复
热议问题