有一个令人沮丧的问题,我的 rails 迁移使用空格和表列的位置更新架构。
所以大多数时候我跑 bundle exec rake db:migrate
它将执行以下场景之一。当我将其合并到我们的主分支并且其他开发人员解决此问题时,他们的 Rails 迁移会恢复选项卡和位置排序。
我们注意到,如果我是架构的最后一个提交者,那么团队中的所有三位开发人员在运行迁移时都会遇到相同的问题。
我刚刚更新 postgres to v9.2.4
这与其他开发人员相同。还有什么我可以尝试的想法吗?
例子
下面是 git diffs 来演示正在发生的事情。
重新排序架构的示例:
create_table "accounts", :force => true do |t|
t.integer "organisation_id"
- t.boolean "active", :default => false
t.text "notes"
+ t.boolean "active", :default => false
end
向架构添加选项卡的示例:
create_table "comments", :force => true do |t|
- t.integer "commentable_id", :default => 0
- t.string "commentable_type", :default => ""
+ t.integer "commentable_id", :default => 0
+ t.string "commentable_type", :default => ""
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
最佳答案
我构建了一个 gem 来解决这个问题。
它对列、索引名称和外键进行排序,删除多余的空格并运行 Rubocop 进行某些格式设置以统一 schema.rb 文件的输出。
https://github.com/jakeonrails/fix-db-schema-conflicts
将它添加到 Gemfile 后,您只需像平常一样运行 rake db:migrate 或 rake db:schema:dump 即可。
关于ruby-on-rails - Rails 迁移总是在模式中插入空格或更改列的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17713512/