2017-05-24 84 views
1

我試圖使用Heroku的CI運行我的Rails應用程序的測試,但它試圖加載我的structure.sql文件時遇到問題。Heroku CI w/Postgresql擴展

-----> Preparing test database 
     Running: rake db:schema:load_if_ruby 
     db:schema:load_if_ruby completed (3.24s) 
     Running: rake db:structure:load_if_sql 
     psql:/app/db/structure.sql:28: ERROR: must be owner of extension plpgsql 
     rake aborted! 
     failed to execute: 
     psql -v ON_ERROR_STOP=1 -q -f /app/db/structure.sql d767koa0m1kne1 
     Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions. 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/postgresql_database_tasks.rb:108:in `run_cmd' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/postgresql_database_tasks.rb:80:in `structure_load' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:223:in `structure_load' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:236:in `load_schema' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:255:in `block in load_schema_current' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in `each' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:254:in `load_schema_current' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:290:in `block (3 levels) in <top (required)>' 
     /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:294:in `block (3 levels) in <top (required)>' 
     /app/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>' 
     Tasks: TOP => db:structure:load 
     (See full trace by running task with --trace) 
! 
!  Could not prepare database for test 
! 

有關此行是:

psql:/app/db/structure.sql:28: ERROR: must be owner of extension plpgsql rake aborted!

Structure.sql包含此行:

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; 

如何獲得Heroku的CI這個工作任何想法?

回答

1

端可達覆蓋db:structure:dump刪除COMMENT ON ...聲明:

namespace :db do 
    namespace :structure do 
    task dump: [:environment, :load_config] do 
     filename = ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure.sql") 
     sql = File.read(filename).each_line.grep_v(/\ACOMMENT ON EXTENSION.+/).join 

     File.write(filename, sql) 
    end 
    end 
end 
+0

你把這個任務放在什麼文件中? 'project.rake'? – user2954587

1

如果凱爾的解決方案是不夠的,這些錯誤不僅通過對擴展言論引起的,但實際的擴展安裝,你仍然可以去硬盤的方式,這添加到初始化:

# This is a temporary workaround for the Rails issue #29049. 
# It could be safely removed when the PR #29110 got merged and released 
# to use instead IGNORE_PG_LOAD_ERRORS=1. 

module ActiveRecord 
    module Tasks 
    class PostgreSQLDatabaseTasks 
     ON_ERROR_STOP_1 = 'ON_ERROR_STOP=0'.freeze 
    end 
    end 
end 

注:這是不特定的Heroku,但更廣泛的Rails 5.1的問題