我在尝试在我的项目上设置 Gitlab CI 时遇到了一个奇怪的问题,该Rails 5.1
项目使用apartment
gem 来支持多租户。我已经设置了 docker-compose 来构建我的容器并运行测试。他们正在我的本地机器上传递,但 Gitlab 管道一直因此错误而失败。
$ bundle exec rspec
/builds/demiurge/new_world/spec/models/char/skill_spec.rb:5: warning: toplevel constant Skill referenced by Char::Skill
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
An error occurred in a `before(:suite)` hook.
Failure/Error: Apartment::Tenant.create slug
ActiveRecord::StatementInvalid:
PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
: SET search_path TO "public", "shared_extensions"
# ./app/models/world.rb:36:in `create_tenant'
# ./spec/rails_helper.rb:52:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# PG::UndefinedObject:
# ERROR: type "hstore" does not exist
# LINE 1: ...har_id" integer, "type" character varying, "data" hstore, "p...
# ^
# ./db/schema.rb:292:in `block in <top (required)>'
Finished in 0.58676 seconds (files took 5 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
我的 docker-compose 设置很简单:
cache:
image: redis:alpine
ports:
- 6379:6379
db:
image: postgres:9.6-alpine
volumes:
- ./data/db/data:/var/lib/postgresql/data
ports:
- 5432:5432
我的 gilab-ci.yml 看起来像这样。而且我还lib/tasks/apartment.rake
设置了一个这样的任务,该任务应该在创建数据库时启用 hstore。任务通过 CI,但仍返回相同的错误。