我们应该schema.rb在提交给GIT的时候加入吗?还是应该忽略它?什么是正确的方法?
目前我正在使用庞大的rails应用程序和多个分支,每个分支都有一个新功能.它发生了很多功能需要迁移,在将它与master合并之前应该不会出现问题:schema.rb已经使用dev数据库的信息进行了更新!
澄清:
1. Branch A has migration create_table_x
2. Branch B has migration create_table_y
3. Branch A adds another create_table_z and runs db:migrate
4. You want to merge Branch A with Master and you see table_x, table_y and table_z in the schema.rb of Branch A.
Run Code Online (Sandbox Code Playgroud)
在分支中的每次迁移之前重置+种子数据库或为每个分支创建数据库都不是一个选项.由于2 GB SQL数据的巨大规模,它将无法使用.
我的问题:
是否真的需要将schema.rb保留在存储库中,因为每次迁移都会重建它?
如果是这样,是否可以从迁移而不是数据库转储构建架构?
我几个月来就注意到了这一点,但直到现在我才没有时间处理它。每当我的 CI 服务器自动执行git pull并重新启动 Rails 服务器时,它们schema.rb都会被随机修改。如下例所示,api_name某个表的列被删除。大约三个月前我放弃了这个专栏。与 相同transportation_charges。通常,该文件中的间距会发生变化:请参阅created_at和updated_at。
这尤其令人烦恼,因为在下次运行时,当我的 CI 执行初始操作时git pull,它会抱怨更改schema.rb并停止执行,直到它们被推送或恢复。而且不仅仅是 CI 服务器。我也在其他开发者机器上看到过这种情况。以前有人遇到过这个吗?
diff --git a/db/schema.rb b/db/schema.rb
index 470d3bf..166e3ee 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -883,7 +883,6 @@ ActiveRecord::Schema.define(version: 20170720211740) do
create_table "ups_package_service_options", force: :cascade do |t|
t.string "name"
- t.string "api_name"
t.string "type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@@ -910,9 +909,8 @@ ActiveRecord::Schema.define(version: 20170720211740) do
t.string "code"
t.string "name"
t.string …Run Code Online (Sandbox Code Playgroud)