1

我在嘗試在我的Rails 5.1項目上嘗試設置Gitlab CI時遇到了一個奇怪的問題,該項目使用apartment gem來支持多租戶。 我有docker-compose設置來構建我的容器並運行測試。他們通過我的本地機器,但Gitlab管道保持失敗,出現此錯誤。Gitlab-CI和Apartment Gem

$ 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 

我的搬運工,撰寫的設置很簡單:

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

您可以發佈您'database.yml'嗎? – Aschen

回答

-2

ERROR: type "hstore" does not exist這個錯誤告訴你hstore擴展名不存在於你的postgres數據庫中。
在任何地方使用此數據類型之前,您必須在遷移中啓用它。

def change 
    enable_extension "hstore" 
end 

你必須確保數據庫用戶是superuser

+0

我在問題中鏈接到的apartment.rake任務中。 – Almaron

+0

爲什麼使用rake任務而不是在遷移中啓用'hstore'? – Aschen

+0

1.因爲寶石文檔提出了這個問題。 2.因爲使它成爲'db:create'過程的一部分似乎是合理的,那麼就是遷移。 – Almaron