【发布时间】:2021-01-21 07:32:50
【问题描述】:
我的 Rails 应用程序的数据库被划分为多个分片,每个分片的partition_key 为toyota_seller_account_id。
现在我想使用此迁移创建一个名为 agg_product_summary_breakdowns 的表:
class CreateAggProductSummaryBreakdowns < ActiveRecord::Migration[5.2]
def change
create_table :agg_product_summary_breakdowns, partition_key: :toyota_seller_account_id do |t|
t.references :toyota_seller_account, null: false
t.date :summary_date, null: false
t.timestamps
end
end
def down
drop_table :agg_product_summary_breakdowns
end
end
现在 Rails 将自动在 toyota_seller_account_id 上创建一个名为 index_agg_product_summary_breakdowns_on_toyota_seller_account_id 的索引,因为它是分区键。
但是,我会遇到这个错误:
ArgumentError: Index name 'index_agg_product_summary_breakdowns_on_toyota_seller_account_id' on table 'agg_product_summary_breakdowns' is too long; the limit is 63 characters。不幸的是,它只有 64 个字符长(比允许的长 1 个字符)。
我想保持表名不变,即agg_product_summary_breakdowns,并且分区键也不能更改。有没有办法覆盖我不知道的索引名称?
谢谢!
【问题讨论】:
标签: ruby-on-rails indexing activerecord migration sharding