使用 dbdeploy 部署数据库时控制数据

发布于 2024-12-05 06:28:21 字数 753 浏览 0 评论 0原文

我们与 dbdeploy task 版本控制,这完全是一种很好的工作方式。除了一个令人难以置信的疑问之外,我实际上在数据库版本上没有很多问题:我们如何控制数据库包含的数据?

目前,我通常有一个三角洲,其中包含一些示例数据,这些数据用于测试,但是在生产环境中,我想拥有生产数据,例如实际有效数据。当然,我可以写另一个三角洲,该三角洲截断了testdata并插入实际数据,但是某种程度上感觉笨拙而笨拙,因为三角洲中唯一的语言是SQL。在编写这样的三角洲时,处理序列并确保外国密钥关系正确,这是一个真正的痛苦。

因此,我认为编写可以从CSV文件导入数据的PHP脚本可能是有意义的。这实际上会起作用,直到有另一个数据库更改将列重命名为列,这将使PHP文件毫无用处。当然,通过更新脚本以将数据库更改并重新运行脚本来轻松修复,但这是错误的,这是我首先开始使用DBDeploy的原因。

所以,我的问题是;在部署更改时,如何处理数据,或更准确:如何插入生产环境所需的数据?

We work with Phing's dbdeploy task to do version control of our PostgreSQL databases, which altogether is a nice way of working. I don't really have a lot of problems with database versions after we started working with it, apart from one nagging doubt: how do we control the data the database contains?

Right now, I usually have a delta that contains some example data, which is used for testing, but in a production environment, I want to have production data, as in, actual valid data. Of course, I could write another delta which truncates the testdata and insert the actual data, but somehow that feels clunky and cumbersome, as the only language in a delta is SQL. When writing such a delta, handling sequences and making sure foreign key relations are correct, is a real pain.

So I figured it might make sense to write a PHP script that will import data from, say, a CSV file. That would actually work, until there is another database change that renames a column, which would render the PHP file useless. Of course, that is easily fixed by updating the script to incorporate the database changes and re-running the script, but that's error-prone, which sort of is the reason I started using dbdeploy in the first place.

So, my question is; how do you handle data while deploying changes, or more accurately: how do you insert the data the production environment needs?

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

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

发布评论

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

评论(1

ゝ偶尔ゞ 2024-12-12 06:28:21

你是对的,测试数据应该被排除在增量之外,就像测试不应该在生产系统上进行一样。你用什么来测试? Phunit,硒,...?你使用任何php框架吗?

无论如何,最好的方法可能是使用您正在使用的任何工具中可能已经附带的东西。例如,Symfony 1.x 有相当好的夹具管理。对于测试 PHP 代码,PHPUnit 是事实上的标准,并且它附带了一些夹具管理。尝试查看 PHPUnit 文档以获取有关如何处理数据集的更多信息: http://www.phpunit.de/manual/current/en/database.html#understanding-datasets-and-datatables

You're right that testing data should be left out of deltas the same way testing shouldn't probably be done on a production system. What do you use for testing? Phpunit, Selenium, ...? Do you use any php framework?

Anyway the best way may be using something that might already come shipped with whatever tool you happen to be using. For example Symfony 1.x has quite a good fixture management. For testing PHP code, PHPUnit is a de facto standard and it comes with some fixture management. Try looking at the PHPUnit documentation for more info on how it handles datasets: http://www.phpunit.de/manual/current/en/database.html#understanding-datasets-and-datatables

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