我们在表influencers
上有一个名为ind_unique_id
的索引。这是迁移文件中的语句:
CREATE UNIQUE INDEX ind_unique_id ON influencers(((ind->>'id')::TEXT));
我可以看到索引在PgAdmin中查找。但是,如果我通过Rails方法index_exists?
检查它,它将返回false
:
Influencer.connection.index_exists?(:influencers, name: "ind_unique_id")
我也尝试将其作为符号传递:
Influencer.connection.index_exists?(:influencers, :ind_unique_id)
他们都没有回归真实。我做错了什么?
答案 0 :(得分:1)
您检查所需的列,而不是索引本身的名称。 喜欢这个
Influencer.connection.index_exists?(:influencers, :some_column_name)
您还可以检查多列
Influencer.connection.index_exists?(:influencers, [:some_column_name, :some_other_column_name])
但是还有另一种方法可以做你想要做的事情index_name_exists?
Influencer.connection.index_name_exists?(:influencers, :ind_unique_id)