ruby-on-rails - 索引同时未显示在 structure.sql 中

标签 ruby-on-rails postgresql activerecord

因此,在创建并发索引时,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.sqldb/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/

相关文章:

ruby-on-rails - 一个最初建立在 Ubuntu 上的 Rails 项目可以在 Mac 环境上运行吗?

javascript - 如何在ajax响应 rails 上添加javascript

ruby-on-rails - Heroku 或 Rails 如何配置数据库?

ruby-on-rails - Rails - 验证关联的存在?

ruby-on-rails - Rails heroku app/assets/images 或上传到 AWS/Cloudinary

java - 如何向 Postgresql CopyManager 指示 session 实例

postgresql - 在 OpenJPA 中使用 VARCHAR 或 TEXT 作为默认字符串映射

ruby-on-rails - Rails 3 ActiveRecord 条件包括?

ruby-on-rails - 如何跨多个请求在 Rails 中缓存查询

javascript - 当我使用belongsToMany 关联时,Sequelize 中的自动预加载