Java 迁移
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/131020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Migrations for Java
提问by Josh Moore
I use both ruby on rails and Java. I really enjoy using migrations when I am working on a rails project. so I am wondering is there a migrations like tool for Java? If there is no such tool is it a good idea to use migrations as a tool to control a database used by a Java project?
我同时使用 ruby on rails 和 Java。当我在 Rails 项目上工作时,我真的很喜欢使用迁移。所以我想知道是否有类似 Java 的迁移工具?如果没有这样的工具,使用迁移作为控制 Java 项目使用的数据库的工具是一个好主意吗?
采纳答案by Brian Deterling
I've used Hibernate's SchemaUpdate to perform the same function as migrations. It's actually easier than migrations because every time you start up your app, it examines the database structure and syncs it up with your mappings so there's no extra rake:db:migrate step and your app can never be out of sync with the database it's running against. Hibernate mapping files are no more complex than Rails migrations so even if you didn't use Hibernate in the app, you could take advantage of it. The downside is that it's not as flexible as far as rolling back, migrating down, running DML statements. As pointed out in the comments, it also doesn't drop tables or columns. I run a separate method to do those manually as part of the Hibernate initialization process.
我使用 Hibernate 的 SchemaUpdate 来执行与迁移相同的功能。它实际上比迁移更容易,因为每次启动应用程序时,它都会检查数据库结构并将其与映射同步,因此没有额外的 rake:db:migrate 步骤,并且您的应用程序永远不会与它运行的数据库不同步反对。Hibernate 映射文件并不比 Rails 迁移复杂,因此即使您没有在应用程序中使用 Hibernate,您也可以利用它。缺点是它不像回滚、向下迁移、运行 DML 语句那样灵活。正如评论中所指出的,它也不会删除表或列。作为 Hibernate 初始化过程的一部分,我运行了一个单独的方法来手动执行这些操作。
I don't see why you couldn't use Rails migrations though - as long as you don't mind installing the stack (Ruby, Rake, Rails), you wouldn't have to touch your app.
我不明白为什么你不能使用 Rails 迁移——只要你不介意安装堆栈(Ruby、Rake、Rails),你就不必接触你的应用程序。
回答by Axel Fontaine
For a feature comparisonbetween
对于之间的功能比较
- Flyway
- Liquibase
- c5-db-migration
- dbdeploy
- mybatis
- MIGRATEdb
- migrate4j
- dbmaintain
- AutoPatch
- 飞道
- Liquibase
- c5-db-迁移
- 数据库部署
- 米巴蒂斯
- 迁移数据库
- 迁移4j
- 数据库维护
- 自动补丁
have a look at http://flywaydb.org
This should be a good start for you and anyone else to select the right tool for the job
这应该是您和其他任何人为工作选择正确工具的良好开端
回答by Adam Monsen
回答by Kyle Burton
回答by Winky
There are also two independent implementations of rails-like migrations for Java:
对于 Java,还有两个类似 Rails 的迁移的独立实现:
1) Maven-based migrations from Carbon Five
从1)基于Maven的迁移碳五
2) Ant-based tasks from Hashrocket(my personal favorite)
2) 来自Hashrocket的基于 Ant 的任务(我个人最喜欢的)
Although these packages were written for Maven and Ant specifically, with some work you can adapt them to just about anything.
尽管这些包是专门为 Maven 和 Ant 编写的,但通过一些工作,您可以使它们适应任何事物。
回答by Kief
I ran across this post while researching the same question. I haven't come to any conclusions about the best tool or approach yet, but one tool that I've come across which hasn't been mentioned in other answers so far is dbdeploy. I'd be interested to read any comparisons of these tools.
我在研究同一个问题时偶然发现了这篇文章。我还没有得出关于最佳工具或方法的任何结论,但我遇到的一个工具是dbdeploy,但迄今为止在其他答案中还没有提到。我有兴趣阅读这些工具的任何比较。
Some other relevant resources: Martin Fowler and Pramod Sadalage's somewhat aged post on Evolutionary Database Design, and the book Refactoring Databases: Evolutionary Database Designby Sadalage and Scot Ambler.
其他一些相关资源:Martin Fowler 和 Pramod Sadalage 关于进化数据库设计的有些陈旧的帖子,以及Sadalage 和 Scot Ambler的书重构数据库:进化数据库设计。
回答by reacuna
回答by Pascal Thivent
There is also DbMaintainwhich has been initially developed inside Unitilsbut is now a dedicated project. We are currently using it and are very satisfied (which doesn't mean there aren't any good alternatives). I list more of them in my database+migrationbookmarks (with a focus on tools supporting Maven).
还有DbMaintain,它最初是在Unitils内部开发的,但现在是一个专用项目。我们目前正在使用它并且非常满意(这并不意味着没有任何好的替代品)。我在我的数据库+迁移书签中列出了更多它们(重点是支持 Maven 的工具)。

