因此,在创建并发索引时,CONCURRENTLY 不会添加到我的 structure.sql 的 CREATE INDEX 中,因为我在配置中将其设置为 config.active_record.schema_format = :sql
。应用.rb
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);
这是一个已知问题吗?我如何确定运行迁移时它实际上是同时运行的
最佳答案
db/struture.sql
或 db/schema.rb
是数据库当前模式结构的反射(reflect),所以它不会有关于算法的信息添加索引(算法用于迁移过程,与模式的最终状态无关)。
关于“我如何确定在运行迁移时它实际上是同时运行的”这个问题?我认为您唯一能知道的是运行迁移时的输出:
$ rake db:migrate
== 20160616073441 AddIndextoUsers: migrating ==================================
-- add_index(:users, :age, {:algorithm=>:concurrently})
-> 0.0243s
== 20160616073441 AddIndextoUsers: migrated (0.0244s) =========================
当不支持算法选项时,ActiveRecord 将引发错误,例如。当您的算法有错别字时。
关于ruby-on-rails - 索引同时未显示在 structure.sql 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37845542/