我尝试在我的Rails 5.1
项目中设置Gitlab CI时遇到一个奇怪的问题,该项目使用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看起来像this。我还有一个lib/tasks/apartment.rake
任务设置,如this,可以在数据库创建时启用hstore。任务传递给CI,但它仍然会返回相同的错误。
答案 0 :(得分:-2)
ERROR: type "hstore" does not exist
此错误告诉您postgres数据库中没有hstore
扩展名。
在任何地方使用此数据类型之前,必须在迁移中启用它。
def change
enable_extension "hstore"
end
您必须确保数据库用户是superuser