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

发布于 2024-08-03 08:28:57 字数 514 浏览 2 评论 0原文

我们有一个开发团队,每个人都将使用 Rails 工具为我们的系统开发数据库迁移。起初,迁移似乎是管理数据库模式更改的好方法,但随着我们的继续,以分布式方式管理更改变得越来越困难。如果我们各自开发迁移,如何解决出现的问题?

为了具体说明问题,请想象以下场景时间线:

  1. 开发人员 A 创建一个时间戳为上午 9:00 的新迁移文件
  2. 开发人员 B 创建另一个时间戳为上午 10:00 的新迁移文件
  3. 开发人员 B 检查日期为上午 10:00 的迁移上午 11:00
  4. 开发人员 A 在上午 11:30 检查日期为上午 9:00 的迁移

这里可能会出现许多问题,特别是如果两个迁移文件在其更改中发生冲突,但最基本的问题是有些人在上午 9:00 迁移签入时运行了上午 10:00 迁移。与迁移关联的时间戳当然是创建文件时的时间戳,而不是签入时的时间戳,这会弄乱 Rails 迁移器。

这是一个可以解决的问题,但解决方案可能有很多不同的选择。解决这个问题的最佳方法(或至少是好方法)是什么?

We have a team of developers who are each going to be developing database migrations for our system using the Rails tools. 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 a.m.
  2. Developer B creates another new migration file timestamped with 10:00 a.m.
  3. Developer B checks in the migration dated 10:00 a.m. at 11:00 a.m.
  4. Developer A checks in the migration dated 9:00 a.m. at 11:30 a.m.

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 a.m. migration when the 9:00 a.m. 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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮颜 2024-08-10 08:28:57

这看起来更像是一个团队沟通问题,或者是一个简单的流程问题。迁移版本从顺序编号更改为时间戳,以避免开发人员 A 和 B 创建具有相同版本的迁移的问题。

为了避免迁移冲突:

  • 在创建迁移时始终让团队了解情况。这应该可以完全避免这个问题。
  • 在将代码更改签回主共享存储库之前,始终从存储库中提取并测试迁移(并运行测试套件)。这是应始终遵循的安全网。

现在您的场景如下所示:

  1. 开发人员 A 创建一个时间戳为上午 9:00 的新迁移文件
  2. 开发人员 B 创建另一个时间戳为上午 10:00 的新迁移文件
  3. 开发人员 B 从存储库中提取。意识到没有新的更改,
  4. 开发人员 A 在上午 10:00 上午 11:00 检查迁移,从存储库中提取,运行迁移和测试套件,解决所有冲突并在上午 11:30 推送到存储库(好吧,也许是 11:00) :35)。

在确保您的更改不会引入冲突或破坏构建的情况下,切勿推送到共享存储库。

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.

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 a.m.
  2. Developer B creates another new migration file timestamped with 10:00 a.m.
  3. Developer B pulls from repository. Realizing there are no new changes, checks in the migration dated 10:00 a.m. at 11:00 a.m.
  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).

Never push to a shared repo without making sure your changes won't introduce a conflict or break the build.

梦与时光遇 2024-08-10 08:28:57

我们总是创建一个 bootstrap rake 任务。此任务删除开发数据库,​​依次运行所有迁移,然后用虚假的测试数据填充它。

除了应用程序中有大量内容可供使用之外,您还必须运行所有迁移。如果您在提交内容之前执行此操作,那么您确信所有迁移也适用于其他人。

We always create a bootstrap rake task. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文