索引同时没有出现在structure.sql中

时间:2016-06-15 20:51:58

标签: ruby-on-rails postgresql activerecord

所以在创建并发索引时,CONCURRENTLY不会被添加到我的structure.sql的CREATE INDEX中,因为我在config.application.rb中将它设置为config.active_record.schema_format = :sql

class IndexUsersOnDateOfBirth < ActiveRecord::Migration
  disable_ddl_transaction!

  def change
    add_index :users, :date_of_birth, algorithm: :concurrently
  end
end

在我的structure.sql中列为

CREATE INDEX index_users_on_date_of_birth ON users USING btree (date_of_birth);

我希望它看起来像

CREATE INDEX CONCURRENTLY index_users_on_date_of_birth ON users USING btree (date_of_birth);

这是一个已知问题吗?如何在运行迁移时确定它实际并发运行

1 个答案:

答案 0 :(得分:1)

db/struture.sqldb/schema.rb反映了数据库的当前架构结构,因此在添加索引时不会有关于算法的信息(该算法用于迁移过程,不相关最终的架构状态。)

关于“如何在运行迁移时确定它实际并发运行”的问题?我认为你唯一能知道的就是运行迁移时的输出:

$ rake db:migrate
== 20160616073441 AddIndextoUsers: migrating ==================================
-- add_index(:users, :age, {:algorithm=>:concurrently})
   -> 0.0243s
== 20160616073441 AddIndextoUsers: migrated (0.0244s) =========================

当不支持算法选项时,ActiveRecord将引发错误,例如。当你的算法有拼写错误。