Travis-CI 上的 Rails 数据库设置 [英] Rails database setup on Travis-CI

查看:38
本文介绍了Travis-CI 上的 Rails 数据库设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Rails 项目上使用 Travis 持续集成.文档说测试数据库必须为 SQLite3 配置如下:

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:
  adapter: sqlite3
  database: ":memory:"
  timeout: 500

但我想保留本地测试的默认配置.是否可以同时保留我的本地设置和 Travis 要求?

But I'd like to keep my default configuration for local tests. Is it possible to keep both my local settings and the Travis requirements?

推荐答案

我对这个问题的解决方案完全基于 一篇博文,但有一些不同:

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

  1. config/database.travis.yml 中的 Travis CI 特定设置;
  2. cp config/database.travis.yml config/database.yml.travis.yml 的脚本部分之前;
  3. 我在源树中没有 config/database.yml.
  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

这篇关于Travis-CI 上的 Rails 数据库设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆