我建议你看看Liquibase这将允许应用程序保持自己的数据库最新。
如果您使用的春天,它很容易,你只需要一个Spring bean,如:
@Bean
public SpringLiquibase liquibase() {
log.debug("Configuring Liquibase");
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource());
liquibase.setChangeLog("classpath:config/liquibase/master.xml");
liquibase.setContexts("development, production");
return liquibase;
}
然后,你必须修改日志:
databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="1" author="bob">
<createTable tableName="department">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="active" type="boolean" defaultValueBoolean="true"/>
</createTable>
</changeSet>
</databaseChangeLog>
每个应用程序启动时,它会检查,如果时间有任何需要应用的更改。
感谢您的建议。我从来没有尝试过Liquibase。将做一些PoC,看看它是如何帮助。 – ak2205