Sam*_*ron 4 activerecord ruby-on-rails-3
我今天有一种情况,我希望在迁移中向表中添加部分postgres索引.当然,这种东西在轨道使用中是不可能的add_index(它将来一段时间)
所以,我被迫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).
#
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果我有任何自定义DML,这个execute声明schema.rb的效果并没有被跟踪schema.rb.
有什么方法可以强制execute包含DML 的语句找到自己schema.rb?
使用schema.rb无法实现您想要的功能,您要做的是切换到使用数据库的本机模式转储/检索代码.
config.active_record.schema_format = :sql
Run Code Online (Sandbox Code Playgroud)
现在,您将获得一个structure.sql文件,而不是schema.rb文件.这应该透明地适用于所有rails的内置任务,并且因为它使用本机转储器格式,它将支持你想要的任何疯狂的东西.
| 归档时间: |
|
| 查看次数: |
727 次 |
| 最近记录: |