4
我今天遇到了一種情況,我想在遷移中向表中添加部分postgres索引。當然這種東西是不可能的在軌道上使用add_index
(它是coming some time)如何在遷移中正確添加自定義SQL DML
因此,我強制在我的遷移中使用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
不追蹤這樣做的效果是使schema.rb
幾乎無用的,如果我有任何自定義的DML。
有什麼辦法可以強制execute
包含DML的語句找到schema.rb
?
要添加到這個問題,有沒有辦法做到這一點使用rake的方式,每當rake創建一個數據庫,它運行一個腳本包含所有的自定義SQL DML? – 2013-01-22 10:36:51