分支 git、运行迁移并保持模式功能
我对 git 相当陌生,我已经开始使用多个分支来同时构建不同的功能,例如使用 gitbranch、git checkout 等命令。
以下是步骤列表我采取了:
git checkout feature1
make some changes that include migrations
rake db:migrate
rake db:commit to feature1 with schema.rb
git checkout feature2
# at this point my schema appears to revert to pre-feature1
make some changes that involve a new migration
rake db:migrate
# schema now shows changes from BOTH feature1 and feature2.
在feature2中运行rake db:migrate
的行为刷新了架构,我想这反映了支撑feature1和feature2的本地数据库。您知道我可以做什么来保持这些迁移分开,以便每个功能都可以有自己的架构,或者是否有其他方法来处理分支迁移?
I'm fairly new to git and I've begun using multiple branches to build different features simultaneously using commands like git branch
, git checkout
, etc.
Here's a list of steps I've taken:
git checkout feature1
make some changes that include migrations
rake db:migrate
rake db:commit to feature1 with schema.rb
git checkout feature2
# at this point my schema appears to revert to pre-feature1
make some changes that involve a new migration
rake db:migrate
# schema now shows changes from BOTH feature1 and feature2.
The act of running rake db:migrate
in feature2 refreshes the schema, which I imagine reflects my local database that underpins both feature1 and feature2. Do you know what I can do to keep these migrations separate so each feature can have its own schema, or is there another way to handle branched migrations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑一下您的工作流程。在feature1分支中有来自feature1的schema.rb,但如果您使用sqlite,您的数据库已在feature2分支中更新。如果您对 feature2 进行了更改,从而破坏了 feature1 中的应用程序,则必须为 feature1 重建数据库。
如果您不想重建数据库,则必须在 feature2 分支中运行迁移之前将 Rails 应用程序配置为使用不同的数据库。
编辑:另一种可能性是将数据库添加到 git (通过更改 .gitignore 文件并将其添加到存储库)。然后你可以使用 git 恢复你的数据库。
think about your workflow. In feature1 branch there is the schema.rb from feature1 but in case you used sqlite your database has been updated in feature2 branch. If you made changes in feature2 which breaks your application in feature1 you have to rebuild your database for feature1.
If you don't want to rebuild your database you have to configure your rails app to use a different database before running the migration in feature2 branch.
edit: Another possibility is to add your database to git (by changing the .gitignore file and adding it to the repo). Then you can revert your database with git.