简体   繁体   English

您如何与开发人员团队一起管理Ruby on Rails迁移?

[英]How do you manage Ruby on Rails migrations with a team of developers?

We have a team of developers who are each going to be developing database migrations for our system using the Rails tools. 我们有一个开发人员团队,他们每个人都将使用Rails工具为我们的系统开发数据库迁移。 Migrations seems at first like a great way to manage changes to the database schema, but as we go on it has become harder to manage changes in a distributed way. 迁移似乎最初是管理数据库模式更改的一种很好的方法,但是随着我们的继续,以分布式方式管理更改变得更加困难。 If we each develop migrations on our own, how can we reconcile the problems that occur? 如果我们每个人都自己开发迁移,我们如何协调发生的问题呢?

To be specific about the problems, imagine the following scenario timeline: 要具体说明问题,请考虑以下方案时间表:

  1. Developer A creates a new migration file timestamped with 9:00 am 开发人员A创建一个新的迁移文件,时间戳为上午9:00
  2. Developer B creates another new migration file timestamped with 10:00 am 开发人员B创建另一个新的迁移文件,时间戳为上午10:00
  3. Developer B checks in the migration dated 10:00 am at 11:00 am 开发人员B检查日期上午10:00(上午11:00)的迁移
  4. Developer A checks in the migration dated 9:00 am at 11:30 am 开发人员A检查上午9:00(上午11:30)的迁移

There are a number of problems that can occur here, especially if the two migration files conflict in their changes, but the most basic problem is that some people have run the 10:00 am migration when the 9:00 am migration is checked in. The timestamps associated with the migrations are of course when the file was created, not when it was checked in, which will mess up the Rails migrator. 这里可能会出现许多问题,特别是如果两个迁移文件的更改发生冲突,但最基本的问题是有些人在上午9:00迁移时已经运行了上午10:00的迁移。与迁移相关联的时间戳当然是在创建文件时,而不是在签入时,这会弄乱Rails迁移器。

This is a fixable problem, but the solution could be plenty of different options. 这是一个可修复的问题,但解决方案可能有很多不同的选择。 What is the best way (or at least a good way) to solve this problem? 解决这个问题的最佳方式(或至少是一种好方法)是什么?

This seems more like a team communication problem, or a plain process problem. 这似乎更像是团队沟通问题,或者是一个简单的流程问题。 The migration versions where changed from sequential numbers to timestamps to avoid the problem where developers A and B create a migration with the same version. 迁移版本从序列号更改为时间戳,以避免开发人员A和B使用相同版本创建迁移的问题。

In order to avoid migration conflicts: 为了避免迁移冲突:

  • Always keep the team on the loop when it comes to creation of migrations. 在创建迁移时始终让团队保持循环。 That should avoid the problem alltogether. 这应该完全避免这个问题。
  • Always pull from your repository and test migrations (and run your test suite) before checking your code changes back into the main shared repo. 在检查代码更改回主共享仓库之前,始终从存储库中取出并测试迁移(并运行测试套件)。 This is a safety net that should always be followed. 这是一个应始终遵循的安全网。

Now your scenario looks like this: 现在你的场景看起来像这样:

  1. Developer A creates a new migration file timestamped with 9:00 am 开发人员A创建一个新的迁移文件,时间戳为上午9:00
  2. Developer B creates another new migration file timestamped with 10:00 am 开发人员B创建另一个新的迁移文件,时间戳为上午10:00
  3. Developer B pulls from repository. 开发人员B从存储库中提取。 Realizing there are no new changes, checks in the migration dated 10:00 am at 11:00 am 意识到没有新的变化,在早上10点到凌晨11点进行迁移检查
  4. Developer A pulls from the repository, runs migrations and test suites, resolves any conflicts and pushes to repository at 11:30am (ok, maybe 11:35). 开发人员A从存储库中提取,运行迁移和测试套件,解决任何冲突并在上午11:30推送到存储库(好的,也许是11:35)。

Never push to a shared repo without making sure your changes won't introduce a conflict or break the build. 永远不要推送到共享仓库而不确保您的更改不会引入冲突或破坏构建。

We always create a bootstrap rake task. 我们总是创建一个bootstrap rake任务。 This task drops the development db, runs all migrations in turn and then fills it with bogus testing data. 此任务将删除开发数据库,​​依次运行所有迁移,然后使用虚假测试数据填充它。

Besides having tons of content in your app to use, you also have to run all migrations. 除了要在您的应用中使用大量内容外,您还必须运行所有迁移。 If you do this before you commit your stuff, you're sure all migrations will work for others as well. 如果在提交内容之前执行此操作,则可以确保所有迁移也适用于其他迁移。

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

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