2013-03-11 94 views
0

我们目前使用flyway作为独立组件管理我们的数据库迁移当前客户。对于新客户,我们希望开始使用flyway的schema_version表部署我们的应用程序以及当前版本的条目。我们的应用程序目前使用Hibernate来初始化数据库(在安装过程中),并提供一个orm。使用Hibernate初始化flyway的schema_version表

当我试图为schema_version创建xml映射时,我发现休眠requires a primary key,并根据以下show create table schema_version;的输出没有主键。

CREATE TABLE IF NOT EXISTS `schema_version` (
`version_rank` INT(11) NOT NULL, 
`installed_rank` INT(11) NOT NULL, 
`version` VARCHAR(50) NOT NULL, 
`description` VARCHAR(200) NOT NULL, 
`type` VARCHAR(20) NOT NULL, 
`script` VARCHAR(1000) NOT NULL, 
`checksum` INT(11) DEFAULT NULL, 
`installed_by` VARCHAR(30) NOT NULL, 
`installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
`execution_time` INT(11) NOT NULL, 
`success` TINYINT(1) NOT NULL, 
KEY `schema_version_vr_idx` (`version_rank`), 
KEY `schema_version_ir_idx` (`installed_rank`), 
KEY `schema_version_s_idx` (`success`) 
) ENGINE=INNODB DEFAULT CHARSET=utf8; 

我的问题是,将迁飞继续,如果我创建一个额外的字段,主键,才能正常运行,或设置schema_version组合键?

这里是当前Hibernate映射的xml:

<hibernate-mapping package="com.hp.cp.psp.persistence.data" catalog="orion" default-lazy="false"> 
<class name="Schema_VersionDO" table="schema_version" lazy="false"> 
    <cache usage="nonstrict-read-write"/> 

    <id name="id" type="int" /><!-- added to satisfy hibernate (id|composite-id) --> 
    <property name="version_rank" type="int" index="schema_version_vr_idx" not-null="true"/> 
    <property name="installed_rank" type="int" index="schema_version_ir_idx" not-null="true"/> 
    <property name="version" type="string" length="50" not-null="true"/> 
    <property name="description" type="string" length="200" not-null="true" /> 
    <property name="type" type="string" length="20" not-null="true" /> 
    <property name="script" type="string" length="1000" not-null="true"/> 
    <property name="checksum" type="int"/> 
    <property name="installed_by" type="string" length="30" not-null="true"/> 
    <property name="installedOn" not-null="true"> 
     <column name="installed_on" sql-type="timestamp" default="CURRENT_TIMESTAMP" /> 
    </property> 
    <property name="execution_time" type="int" not-null="true"/> 
    <property name="success" type="byte" length="1" index="schema_version_s_idx" not-null="true"/> 
</class> 
</hibernate-mapping> 

帮助或建议是一如既往,不胜感激。谢谢 布拉德

回答

0

没有必要为此使用Hibernate。 Flyway.init()完全符合你的需求。

+0

一如既往,感谢您的快速响应! 目前我们软件的决定是flyway不会在安装过程中使用或者被集成到主应用程序中。我必须说服他们,它应该是,初始化和连接到飞桥属性。他们希望从用户界面看到数据库版本,并将其集成到休眠似乎是不安全和太多的工作。再次感谢。 – 2013-03-12 16:52:05