【问题标题】:Rails LHM migration - specify name of indexRails LHM 迁移 - 指定索引的名称
【发布时间】:2016-12-02 18:31:29
【问题描述】:

使用 LHM (Large Hadron Migrator) 有语法文档来添加索引:

require 'lhm'
class SomeMigration < ActiveRecord::Migration
  def self.up
    Lhm.change_table :foos do |m|
      m.add_unique_index  [:bar_id, :baz] # add_index if you don't want uniqueness
    end
  end
  def self.down
    Lhm.change_table :foos do |m|
      m.remove_index  [:bar_id, :baz]
    end
  end
end

如何在 LHM 中指定索引的特定名称?用于添加和删除

我担心我会点击index name length limit,因为我使用了很多列

【问题讨论】:

    标签: mysql ruby-on-rails soundcloud database-migration


    【解决方案1】:
    m.add_unique_index([:long_column, :super_long_column], 'shortened_index_name')
    

    Link to LHM docs for #add_unique_index

    【讨论】:

    • 啊哈!我试过name: 'blah',但期待index_name: 'blah'
    • 所以需要RTFM'd 的徽章
    猜你喜欢
    • 2015-04-27
    • 2012-01-18
    • 1970-01-01
    • 2020-04-10
    • 2015-03-01
    • 1970-01-01
    • 2021-01-03
    • 2013-09-13
    • 2018-07-24
    相关资源
    最近更新 更多