Java 迁移 [英] Migrations for Java

查看:23
本文介绍了Java 迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时使用 ruby​​ on rails 和 Java.当我在 Rails 项目上工作时,我真的很喜欢使用迁移.所以我想知道是否有类似 Java 的迁移工具?如果没有这样的工具,使用迁移作为控制 Java 项目使用的数据库的工具是一个好主意吗?

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?

推荐答案

我使用 Hibernate 的 SchemaUpdate 来执行与迁移相同的功能.它实际上比迁移更容易,因为每次启动应用程序时,它都会检查数据库结构并将其与映射同步,因此没有额外的 rake:db:migrate 步骤,并且您的应用程序永远不会与它运行的数据库不同步反对.Hibernate 映射文件并不比 Rails 迁移复杂,因此即使您没有在应用程序中使用 Hibernate,您也可以利用它.缺点是它不像回滚、向下迁移、运行 DML 语句那样灵活.正如评论中所指出的,它也不会删除表或列.作为 Hibernate 初始化过程的一部分,我运行了一个单独的方法来手动执行这些操作.

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.

我不明白为什么你不能使用 Rails 迁移——只要你不介意安装堆栈(Ruby、Rake、Rails),你就不必接触你的应用程序.

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.

这篇关于Java 迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆