如何使用不同的数据库模式管理git分支?

时间:2022-12-14 07:26:35

I have a project where I need to work on a new feature that requires part of the database to be re-designed whilst also keeping the main development branch working on the old schema.

我有一个项目,我需要处理一个新功能,需要重新设计部分数据库,同时保持主开发分支在旧模式上工作。

What is your best-practice for managing a project like this?

管理这样的项目的最佳实践是什么?

I thought about having a separate database whilst working on the new feature but realised this would require having the database config checked into the repository which is a no-go. Are there other ways I could approach the issue?

我想在处理新功能时有一个单独的数据库,但意识到这需要将数据库配置检入存储库,这是不行的。还有其他方法可以解决这个问题吗?


Seed data to the rescue

播种种子数据

Right after posting this the answer hit me - I should have some scripts to populate my db with seed data. That way I can just drop/recreate/seed the database when switching between branches.

在发布这个答案之后,答案就出现了 - 我应该有一些脚本用种子数据填充我的数据库。这样我就可以在分支之间切换时删除/重新创建/播种数据库。

1 个解决方案

#1


1  

The usual way to deal with this is to check your database creation scripts into source control. Then you can branch and manage them in the same way as the rest of your source code.

处理此问题的常用方法是将数据库创建脚本检查为源代码管理。然后,您可以使用与其他源代码相同的方式分支和管理它们。

You will need a way of pointing your code at a particular instance of a database (which has been created using the scripts in the current branch).

您需要一种将代码指向数据库的特定实例(使用当前分支中的脚本创建)的方法。

#1


1  

The usual way to deal with this is to check your database creation scripts into source control. Then you can branch and manage them in the same way as the rest of your source code.

处理此问题的常用方法是将数据库创建脚本检查为源代码管理。然后,您可以使用与其他源代码相同的方式分支和管理它们。

You will need a way of pointing your code at a particular instance of a database (which has been created using the scripts in the current branch).

您需要一种将代码指向数据库的特定实例(使用当前分支中的脚本创建)的方法。