问题描述
我遇到了一个问题,当时我在Rails项目的两个分支上工作,每个项目都有一个迁移以添加列。当时, rake db:migrate:reset
引起问题,我仅依靠 schema.rb
正确地工作代表我的数据库状态。有一次,我遇到了一个问题,其中分支A添加的列进入了分支B的架构。由于 migrate:reset
不是一个选择,因此我手动进行编辑架构文件。我所做的更改基本上删除了分支B的schema.rb中不需要的分支A中的列。
I came across a problem where I was working on two branches on a rails project and each project has a migration to add a column. At the time, rake db:migrate:reset
cause a problem and I solely relied on my schema.rb
to correctly represent the state of my database. At one point, I came across a problem where a column added by branch A got into the schema of branch B. Since migrate:reset
was not an option, I resorted to manually editing the schema file to. I committed this change that basically deleted the column from branch A that I did not need in branch B's schema.rb.
问题是在将分支A合并到master之后出现的。当我尝试将分支B重新设置为master时,我仍然在B中拥有该提交以删除架构文件中的列(由于它位于master中,因此现在变得很重要)。 Git对此没有看到任何冲突,并自动将其合并。在重新定型结束时,我发现我的架构与我的母版中的架构不一致。
Problem came after I have merged branch A into master. When I tried to rebase branch B to master, I still had that commit in B to delete the column (which now has become relevant because it is in master) in the schema file. Git did not see a conflict for this and auto-merged it. At the end of my rebase, I found that my schema is inconsistent with what I have in master.
我的解决方法是再次编辑架构文件并手动添加先前的删除列回到架构文件。我的问题是:这被认为是非常规的吗?有危险吗hacky?
My fix is to edit the schema file again and manually add the previously deleted column back to the schema file. My question is: Is this considered unconventional? dangerous? hacky?
现在它涉及一列,但是如果涉及多个列的删除/添加,那么(危险的)解决方案可能会导致更多问题,并且db / schema.rb不一致。
Right now it involves one column but if this involved multiple column deletions/additions the (dangerous?) solution could lead to more problems and db/schema.rb inconsistency.
推荐答案
编辑 schema.rb $ c $通常被认为是不好的做法。 c>文件。
根据:
schema.rb
在每次运行新迁移时都会更新
schema.rb
gets updated every time you run a new migration:
我建议您花一些时间来整理问题,并使 schema.rb
文件恢复正常,并更正最新的迁移集。
I'd recommend just spending some time to sort things out and get the schema.rb
file back on track and correct up to the latest set of migrations.
这篇关于在Rails中手动编辑schema.rb是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!