在源代码管理中管理我的数据库

时间:2022-09-11 14:59:07

As I am working with a new database project (within VS2008), and as I have never developed a database from scratch, I immediately began looking into how to manage a database within source control (in this case, Subversion).

当我正在使用一个新的数据库项目(在VS2008中)时,由于我从未开始从头开发数据库,​​我立即开始研究如何在源代码控制中管理数据库(在本例中为Subversion)。

I found some information on SO, including this post: Keeping development databases in multiple environments in sync. One of the answers in particular pointed to a number of a links, all of which had good, useful information.

我在SO上找到了一些信息,包括这篇文章:保持多个环境中的开发数据库同步。其中一个答案特别指出了一些链接,所有这些链接都有很好的有用信息。

I was reading a series of posts by K. Scott Allen which describe how he manages database change. From my reading (and please pardon the noobishness of my question), it seems as though the database itself is never checked into a repository. Rather, scripts that can build the database, along with test data (which is also populated from scripts) is checked into the repository. Ultimately, this means that, when a developer is testing his or her app, these scripts, which are part of the build process, are run. This ensures that the database is up-to-date, but is also run locally from every developer's machine.

我正在阅读K. Scott Allen撰写的一系列文章,描述他如何管理数据库变更。从我的阅读(并请原谅我的问题的无意义),似乎数据库本身从未被检查到存储库。相反,可以在存储库中检查可以构建数据库的脚本以及测试数据(也从脚本填充)。最终,这意味着,当开发人员测试他或她的应用程序时,将运行这些脚本,这些脚本是构建过程的一部分。这可确保数据库是最新的,但也可以从每个开发人员的计算机本地运行。

This makes sense to me (if I am indeed reading that correctly). However, if I am missing something, I would appreciate correction or additional guidance. In addition, another question I wanted to ask - does this also mean that I should NOT check in the mdf or ldf files that are created from Visual Studio?

这对我来说很有意义(如果我确实正确地阅读了这一点)。但是,如果我遗失了某些内容,我将不胜感激,或者需要更多指导。另外,我想问的另一个问题 - 这是否也意味着我不应该检查从Visual Studio创建的mdf或ldf文件?

Thanks for any help and additional insight. Always appreciated.

感谢您的帮助和其他见解。永远感激。

5 个解决方案

#1


6  

That is correct you should check in scripts not the database file itself.

这是正确的,你应该检查脚本而不是数据库文件本身。

I'm not a fan of building from test data unless the data itself will mimic the size of data that production has (or in,the case of new databases, is intended to have) . Why? because writing code against a table with 100 records doesn't tell you if it will run in a timely fashion when you have 10,000,000 records. I've way too many bad design choices made from people who think a small data set is OK for development.

我不是建立测试数据的粉丝,除非数据本身将模仿生产所具有的数据的大小(或者,在新数据库的情况下,它是有的)。为什么?因为针对具有100条记录的表编写代码并不会告诉您当有10,000,000条记录时它是否会及时运行。我认为有太多糟糕的设计选择来自那些认为小数据集可以用于开发的人。

Here, we do not allow devs to have a separate database on their box (which typically limits the size the database can be by virture of not being a server attached to SAN), instead they must work against the dev database which is periodically refreshed from prod (and then all the new dev scripts run) to keep the data the right size. I think it is important that your dev datbase environment match prod as closely as possible including equipment configuration, size of the database etc. Nothing more frustrating than spending a long time developng something that either won't work at all on prod or has to be taken down immediately because it is slowing the system too much.

在这里,我们不允许开发人员在他们的盒子上有一个单独的数据库(这通常会限制数据库的大小,因为它不是连接到SAN的服务器),而是他们必须对定期刷新的开发数据库起作用。 prod(然后运行所有新的dev脚本)以保持数据的正确大小。我认为重要的是你的dev数据库环境尽可能地匹配prod,包括设备配置,数据库的大小等等。没有什么比花费很长时间开发一些在生产上根本无法工作或必须是立即取下,因为它太慢了系统。

Jumping down off my soapbox now.

现在跳下我的肥皂盒。

#2


2  

It is great idea to check in scripts, since source code control is best suited to working with text files, rather than binary files. Differences in the script files can be easily reviewed as part of the rest of your code changes related to the database change. In addition to checking in the database scripts, we also check in a database schema snapshot. This database schema snapshot allows us to verify that the schema in production matches the expected schema for given version of the product. Besides that, the database schema snapshot is a handy way for searching for columns and tables using a plain text editor.

检查脚本是个好主意,因为源代码控制最适合处理文本文件,而不是二进制文件。作为与数据库更改相关的其余代码更改的一部分,可以轻松查看脚本文件中的差异。除了检入数据库脚本之外,我们还检入了数据库模式快照。此数据库模式快照允许我们验证生产中的模式是否与给定版本的产品的预期模式匹配。除此之外,数据库模式快照是使用纯文本编辑器搜索列和表的便捷方式。

#3


1  

I use DataConstructor but am biased because I wrote it.

我使用DataConstructor但是因为我写了它而有偏见。

#4


0  

Try SQL Examiner: How to keep your database under version control

尝试SQL Examiner:如何使数据库保持版本控制

#5


0  

You could use a tool like Liquibase to manage the database scripts. It is really a database upgrade framework, so it will keep track of the steps that have executed already, so when you want to upgrade production, for example, it only executes the new steps.

您可以使用Liquibase之类的工具来管理数据库脚本。它实际上是一个数据库升级框架,因此它将跟踪已经执行的步骤,因此当您想要升级生产时,它只会执行新的步骤。

#1


6  

That is correct you should check in scripts not the database file itself.

这是正确的,你应该检查脚本而不是数据库文件本身。

I'm not a fan of building from test data unless the data itself will mimic the size of data that production has (or in,the case of new databases, is intended to have) . Why? because writing code against a table with 100 records doesn't tell you if it will run in a timely fashion when you have 10,000,000 records. I've way too many bad design choices made from people who think a small data set is OK for development.

我不是建立测试数据的粉丝,除非数据本身将模仿生产所具有的数据的大小(或者,在新数据库的情况下,它是有的)。为什么?因为针对具有100条记录的表编写代码并不会告诉您当有10,000,000条记录时它是否会及时运行。我认为有太多糟糕的设计选择来自那些认为小数据集可以用于开发的人。

Here, we do not allow devs to have a separate database on their box (which typically limits the size the database can be by virture of not being a server attached to SAN), instead they must work against the dev database which is periodically refreshed from prod (and then all the new dev scripts run) to keep the data the right size. I think it is important that your dev datbase environment match prod as closely as possible including equipment configuration, size of the database etc. Nothing more frustrating than spending a long time developng something that either won't work at all on prod or has to be taken down immediately because it is slowing the system too much.

在这里,我们不允许开发人员在他们的盒子上有一个单独的数据库(这通常会限制数据库的大小,因为它不是连接到SAN的服务器),而是他们必须对定期刷新的开发数据库起作用。 prod(然后运行所有新的dev脚本)以保持数据的正确大小。我认为重要的是你的dev数据库环境尽可能地匹配prod,包括设备配置,数据库的大小等等。没有什么比花费很长时间开发一些在生产上根本无法工作或必须是立即取下,因为它太慢了系统。

Jumping down off my soapbox now.

现在跳下我的肥皂盒。

#2


2  

It is great idea to check in scripts, since source code control is best suited to working with text files, rather than binary files. Differences in the script files can be easily reviewed as part of the rest of your code changes related to the database change. In addition to checking in the database scripts, we also check in a database schema snapshot. This database schema snapshot allows us to verify that the schema in production matches the expected schema for given version of the product. Besides that, the database schema snapshot is a handy way for searching for columns and tables using a plain text editor.

检查脚本是个好主意,因为源代码控制最适合处理文本文件,而不是二进制文件。作为与数据库更改相关的其余代码更改的一部分,可以轻松查看脚本文件中的差异。除了检入数据库脚本之外,我们还检入了数据库模式快照。此数据库模式快照允许我们验证生产中的模式是否与给定版本的产品的预期模式匹配。除此之外,数据库模式快照是使用纯文本编辑器搜索列和表的便捷方式。

#3


1  

I use DataConstructor but am biased because I wrote it.

我使用DataConstructor但是因为我写了它而有偏见。

#4


0  

Try SQL Examiner: How to keep your database under version control

尝试SQL Examiner:如何使数据库保持版本控制

#5


0  

You could use a tool like Liquibase to manage the database scripts. It is really a database upgrade framework, so it will keep track of the steps that have executed already, so when you want to upgrade production, for example, it only executes the new steps.

您可以使用Liquibase之类的工具来管理数据库脚本。它实际上是一个数据库升级框架,因此它将跟踪已经执行的步骤,因此当您想要升级生产时,它只会执行新的步骤。