今天我遇到了一种情况,我希望在迁移中向表中添加部分postgres索引。当然,使用add_index
(coming some time}
因此,我在迁移中被迫使用execute
语句。
现在,schema.rb
的评论位于顶部:
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
不幸的是,在execute
中没有跟踪schema.rb
语句,如果我有任何自定义DML,这会使schema.rb
的效果变得毫无用处。
有什么方法可以强制包含DML的execute
语句找到自己schema.rb
?
答案 0 :(得分:6)
没有办法用schema.rb实现你想要的,你想要做的就是切换到使用数据库的本机模式转储/检索代码。
config.active_record.schema_format = :sql
现在,您将获得一个structure.sql文件,而不是schema.rb文件。这应该透明地适用于所有导轨'内置任务,并且使用原生转储器格式,它可以支持您想要的任何疯狂的东西。