在创建索引时添加where子句

时间:2019-04-14 18:04:03

标签: ruby-on-rails postgresql

我在ruby中有一个数据库迁移脚本。

如何在迁移脚本中添加where子句

unless index_exists?(:hotel_room_types, [:hotel_id, :dynamic_price_from])
      add_index :hotel_room_types, [:hotel_id, :dynamic_price_from], 
      unique: true, where: (status =1), name: 'by_hotel_id_from'
 end

PG::DatatypeMismatch: ERROR:  argument of WHERE must be type boolean, not type integer

第1行:... otel_room_types”(“ hotel_id”,“ dynamic_price_from”)在1处

1 个答案:

答案 0 :(得分:1)

where作为字符串

add_index :hotel_room_types, [:hotel_id, :dynamic_price_from], 
  unique: true, where: 'status = 1', name: 'by_hotel_id_from'