完整的数据库模式转换 - 如何测试重写的查询?
我们的数据库设计得很糟糕(我们继承了它)。我已将架构重新设计为可用且可维护的东西。相当多的表和列已被删除,许多列已被移动,并且大多数表和列已被重命名。一些数据类型也已更改。
我已经从我们的网络应用程序中提取了所有查询,并开始重写它们。我们认为,我们的 DBA 能够将旧数据迁移到新模式。为了确保我们需要通过将旧结果与新结果进行比较来测试每个查询。
我们如何测试这样的大规模迁移?我需要能够指定参数,并将旧表/列映射到新表/列。由于有数百个查询,这是一项艰巨的任务。我可以自己写一些东西,但我已经对我的时间有很多要求,所以使用现有的工具是更好的选择。
谢谢!
Our database is poorly designed all the way around (we inherited it). I've reworked the schema to something useable and maintainable. Quite a few tables and columns have been dropped, many columns have moved and most tables and columns have been renamed. Some datatypes have been changed also.
I've extracted all the queries from our webapps and we've started rewriting them. Our DBA is able to migrate the old data to the new schema, we think. To be sure we need to test each query by comparing the old results with the new.
How can we test such a wholesale migration? I need to be able to specify parameters, and map old tables/columns to new tables/columns. With hundreds of queries this is a daunting task. I could write something myself but I already have a lot of demands on my time so using an existing tool is preferable.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我必须这样做......而且这很容易,因为我重写了整个应用程序;)
许多查询听起来像是基本操作,例如选择,插入,更新尚未在函数中抽象 - 也许这可以帮助清理适应之前一团糟。
现在进行测试:
您需要一个测试脚本
a) 运行所有查询
b) 存储所有选择的输出进行比较
备份您的测试数据库@状态0,清除常规查询日志
在您的应用程序中使用所有删除、选择和更新,
复制粘贴该日志,获取每个选择并在其前面加上“创建表 temptable_xyz”(或课程选择到 temptable_xyz .. 取决于可用的语法)
在两个数据库上运行,迁移脚本后 test db @ state 0 和 test db @ state 0
比较
如果您可以确保您使用了每个应用程序中的每个功能,那么这应该可以做到。
GL - 没有什么比让现有的东西变得更好更好的了;)
I've had to do this ... and well it was easy because i rewrote the entire application ;)
Many queries sounds like basic operations such as select,insert,updates have not been abstracted in functions - maybe that can help clean up the mess before adapting.
Now for the testing:
You need a test script that will
a) run all your queries
b) store output of all selects for comparison
backup your test db @ state 0, clear the general query log
play around your application using all the deletes, selects and updates,
copy paste that log, take every single select and precede it with a "Create table temptable_xyz" (or of course SELECT into temptable_xyz .. depends on the available syntax)
run on both databases, test db @ state 0 and test db @ state 0 after migration script
compare
This should do it if you can make sure you used every feature in every app.
GL - nothing like making existing stuff better ;)
有时简单的解决方案就可以解决问题。
如果只是 SELECT,您可以将新旧查询放入文本文件中,使用脚本运行它们并比较输出。
或者您可以编写基于结果比较的单元测试
Sometimes simple solutions do the job.
If it is just SELECTs, you could just put the new and old queries in text files, run them with a script and diff the output.
Or you could write a unit test based result comparison
这将是我的方法:
创建一个 SQL 脚本来连接每个数据库的表并比较结果。这可以通过 information_schema 或其他系统表来完成(取决于供应商)。
插入临时表
选择(从 db1..name 中选择 count(1))
,(从 db2..name 中选择 count(1))
,(在 t1.col1 = t2.col1 和 t1.colx = t2.colx 上从 db1.name t1 join db2.name t2 选择 count(1))
, tablename
然后您可以运行查询中包含该表名的查询。它将为您提供查看位置的起点。
This would be my approach:
Create a sql script that joins each database's table and compare the results. This could be done off information_schema or other system tables (depending on the vendor.)
insert into temp table
select (select count(1) from db1..name)
, (select count(1) from db2..name)
, (Select count(1) from db1.name t1 join db2.name t2 on t1.col1 = t2.col1 and t1.colx = t2.colx)
, tablename
You could then run through the queries that have the tablename in the query. It would give you starting point of where to look.