mysql - rails : preventing bad/conflicting database migrations

标签 mysql ruby-on-rails ruby continuous-integration ruby-on-rails-5

只是想知道这些是否可以通过 rubocop 或直接通过 ci 以某种方式预防。

我们最初在主分支上进行了一些迁移:

# migration 1
create_table :some_table do |t|
  t.string :some_col
end

# migration 2
def change
  rename_column :some_table, :some_col, :some_other_col
end

但是,我们还有一个单独/较旧的分支,其中 some_table 中的列被直接重命名:

create_table :some_table do |t|
  t.string :some_col
end

它被合并到/通过了 ci 并在生产中运行,没有任何问题,但是在几周后部署到新的测试环境时抛出 No such columns: some_table 错误时被捕获。

最佳答案

引用自:rake db:schema:load vs rake db:migrate这解释了这个确切的问题:

when you are adding a new migration to an existing app then you need to run rake db:migrate, but when you join to existing application (especially some old application), or when you drop your applications database and you need to create it again, always run rake db:schema:load to load schema.

本质上,当您启动新实例时,请始终使用 db:schema:load 加载初始数据库,从那时起您就可以照常迁移。

关于mysql - rails : preventing bad/conflicting database migrations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46944606/

相关文章:

ruby - JRuby 是否支持 { 事物 : "hello" } syntax?

ruby - 为什么我不能在方法外定义变量并在方法内更新?

ios - RubyMotion Build : ERROR! 找不到名为 `(?-mix:iOS Team Provisioning Profile)' 的配置文件

php - 如何在 Codeigniter 中对始终位于顶部的特定/某些行的表进行排序?

mysql - PHP/MySQL 中的 Unicode 比较

sql - 在android中查询数据库

mysql - SQL连接即使没有这样的ID

ruby-on-rails - 如何让延迟的工作自己排队

ruby-on-rails - Rails 命名空间模型与非命名空间模型冲突

ruby-on-rails - 脚本/服务器 custom_require.rb :36:in `require' : cannot load such file -- test/unit/error (LoadError)