简体   繁体   English

带有迁移运行的git分支

[英]git branch with migrations run

I checked out a branch in git to experiment with developing a feature that involved making three migrations, which I have run. 我在git中签出了一个分支,以尝试开发一项功能,该功能涉及我已经运行的三个迁移。 Preserving the very small amount of data in the db is not important. 在数据库中保留非常少量的数据并不重要。 How do I handle this when merging the branch back into master? 将分支合并回master时如何处理? Should I rollback the migrations before merging, and then run them again after merged (as seemed to be suggested by one SO answer), or do I leave it as is and just commit everything to the branch and then merge it without rolling anything back. 我应该在合并之前回滚迁移,然后在合并之后再次运行它们(就像一个SO答案所建议的那样),还是我将其保留原样并将所有内容提交到分支,然后将其合并而不回滚任何内容。 Another SO answer suggested removing the db from the gitignore file, but it wasn't clear if that was only necessary in situations where preserving data might be important. 另一个SO答案建议从gitignore文件中删除db,但是尚不清楚是否仅在保留数据可能很重要的情况下才需要这样做。

# Ignore the default SQLite database.
/db/*.sqlite3

You should not track your *.sqlite3 development files in git. 您不应该在git中跟踪*.sqlite3开发文件。

You should 你应该

  1. Merge master into your branch master合并到您的分支
  2. Make sure all is well 确保一切顺利
  3. Checkout master 结帐master
  4. Merge the branch back into master 将分支合并回master
  5. Continue development 继续发展

The merge will pull in your migrations from the branch. 合并将从分支中引入您的迁移。 You could rollback before the merge, do the merge, and then migrate, but there's no need; 您可以在合并之前回滚,进行合并,然后迁移,但是没有必要。 the resulting schema at the end will be identical. 最后的结果架构将是相同的。


In situations where a rollback/migration would be necessary, it's likely your migrations between master and the branch conflict with one another somehow. 在需要回滚/迁移的情况下, master和分支之间的迁移可能会以某种方式相互冲突。 This is something you'd fix in step #2 above when you're "Making sure all is well". 当您“确保一切正常”时,可以在上面的步骤2中修复此问题。

As a general rule, you should be able to take a completely blank database, run rake db:migrate and end up with an up-to-date database structure without anything failing. 通常,您应该能够获取一个完全空白的数据库,运行rake db:migrate并最终得到一个最新的数据库结构,而不会发生任何故障。 This is why step #2 above is important, to ensure you're not merging a breaking/conflicting migration back into master . 这就是为什么上面的步骤2很重要的原因,以确保您不会将中断/冲突的迁移合并回master

As for situations where you are risking losing data in development, this is what fixtures are for. 对于在开发中可能会丢失数据的情况,这就是固定装置的用途。 You can use Rails seeding functionality, or a gem like factory_girl . 您可以使用Rails播种功能,也可以使用factory_girl之类的gem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM