如何处理使用同一数据库的两个单独的laravel项目上的迁移? [英] How to handle migrations on two separate laravel projects that use the same database?

查看:54
本文介绍了如何处理使用同一数据库的两个单独的laravel项目上的迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的设置是这样:

  1. 我们拥有和提供iOS和Android应用程序的API
  2. 我们有一个Admin API,可提供Admin网络应用程序

我正在开发Admin,我的同事正在开发app API.

I'm developing the Admin, my colleague is developing the app API.

它们都使用相同的数据库和大多数相同的表.将它们合并到一个项目中不是一个选择,因为我们将部署到Elastic Beanstalk,并且Admin不需要扩展,因为它会被少数人使用.

They both use the same database, and most of the same tables. Merging them into a single project is not an option as we will deploy to Elastic Beanstalk and the Admin doesn't need to scale, since it will be used by a small number of people.

我们遇到的问题是处理迁移,我们已经得出以下结论:

The issue we ran into is handling migrations, and we've arrived to the following conclusions:

  • 我们不能在项目中都有自己的迁移,因为版本不会累加
  • 如果我们仅在其中一个项目上进行迁移(我们都可以访问两个项目),则没有迁移的项目就不能在不重新部署另一个项目的情况下进行重新部署
  • 如果我们制作的第三个项目仅包含迁移,那么我们将托管一个本质上不执行任何操作的应用程序

尽管我能想到解决此问题的 hacky 方法,但我们正在寻找最佳实践方法.

While I can think of hacky ways of fixing this issue, we're looking for a best practices approach.

推荐答案

我建议选择创建仅具有迁移功能的第三个项目.这样,您可以将所有迁移都放在一个位置,避免出现不一致的问题,并且可以将迁移与任一应用程序的部署分离.该应用程序不做"任何事情这一事实应该无关紧要;您不需要部署额外的应用程序,只需从部署服务器运行迁移即可.实际上,您不必仅为迁移而创建整个Laravel项目.在Laravel之外使用Eloquent很简单.本文提供了一个使用雄辩查询的示例构建器以在Laravel之外运行迁移.您还可以使用诸如 Phinx 之类的轻量级迁移工具,该工具提供与Laravel内置迁移类似的功能集,但只需很少的操作依赖性.

I would recommend the option of creating the third project that only has migrations. That way, you keep all the migrations in one place and avoid problems of inconsistency, and you decouple the migrations from the deployment of either app. The fact that the app doesn't "do" anything shouldn't matter; you don't need to deploy an extra app, just run the migrations from your deployment server. You don't actually have to create a whole Laravel project just for your migrations; it's fairly simple to use Eloquent outside of Laravel. This article gives an example of using the Eloquent query builder to run migrations outside of Laravel. You could also use a lightweight migrations tool like Phinx, which offers a similar feature set to Laravel's built-in migrations but with minimal dependencies.

这篇关于如何处理使用同一数据库的两个单独的laravel项目上的迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆