How do I sanitize a time stamp for use in a conditional index in a rails migration? -
i have rails migration need create conditional index. condition includes timestamp so:
class indexcreatedatonnotes < activerecord::migration def change add_index :notes, :created_at, where: "state = 'active' , created_at >= #{200.days.ago}" end end however not put timestamp straight string query in rails, instead do: note.where("created_at >= ?", 200.days.ago) things escaped right way timezones , everything. how do in migration?
when use #{value} value called to_s on converted string thing miss here surround date single quotes , to_s called on date don't want to_s want calling .to_formatted_s(:db):
add_index :notes, :created_at, where: "state = 'active' , created_at >= '#{200.days.ago.to_formatted_s(:db)}'"
Comments
Post a Comment