【发布时间】:2017-10-17 19:30:10
【问题描述】:
为了防止在我们迁移到生产站点期间发生数据库事务错误,我们遵循了https://github.com/LendingHome/zero_downtime_migrations 中概述的建议(具体由https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in 概述),但是在特别大的表上创建索引期间,即使索引创建的“并发”方法锁定了表,并导致在该表上创建或更新任何 ActiveRecord 导致它们各自的事务失败并出现PG::InFailedSqlTransaction 异常。
这是我们正在运行 Rails 4.2(使用 ActiveRecord 4.2.7.1)的迁移:
class AddTypeIndexToModel < ActiveRecord::Migration
disable_ddl_transaction!
def change
add_index :model, :model_type_id, algorithm: :concurrently
end
end
【问题讨论】:
-
你使用了monkeypatch吗?此处如何指示github.com/barsoom/devbook/tree/master/deploy_without_downtime
标签: ruby-on-rails ruby postgresql activerecord