Spring boot 在spring boot应用程序中液化迁移文件
我有一个spring boot应用程序,它使用liquibase进行数据库/数据迁移,当前状态是,有一个迁移文件Spring boot 在spring boot应用程序中液化迁移文件,spring-boot,migration,refactoring,liquibase,Spring Boot,Migration,Refactoring,Liquibase,我有一个spring boot应用程序,它使用liquibase进行数据库/数据迁移,当前状态是,有一个迁移文件db.changelog master.xml,其中包含所有变更集。现在我想把这个文件分成多个文件,或者至少在新文件中创建新脚本。因此,我尝试添加db.changelog master.yaml,以包括主文件和任何其他文件。但问题是,它会生成一个新的校验和值,以便旧文件中已经存在的脚本再次执行。是否有任何方法可以在不运行旧脚本的情况下分离旧的大文件,甚至将其包含在db.changelo
db.changelog master.xml
,其中包含所有变更集。现在我想把这个文件分成多个文件,或者至少在新文件中创建新脚本。因此,我尝试添加db.changelog master.yaml
,以包括主文件和任何其他文件。但问题是,它会生成一个新的校验和值,以便旧文件中已经存在的脚本再次执行。是否有任何方法可以在不运行旧脚本的情况下分离旧的大文件,甚至将其包含在db.changelog master.yaml中?有两种可能的选择:
1.更改逻辑文件路径:
Liquibase允许您定义变更日志的所谓逻辑文件路径。这允许您假装变更集实际上来自同一个文件。Liquibase将把变更集视为之前在changelog.xml中定义的变更集
<?xml version="1.0" encoding="UTF-8"?>
<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 dbchangelog-3.5.xsd"
logicalFilePath="classpath:changelog.xml">
<changeSet author="me" id="changeset2">
<createTable tableName="TABLE2">
<column name="COLUMN1" type="VARCHAR2(10)"/>
</createTable>
</changeSet>
</databaseChangeLog>
细节
<?xml version="1.0" encoding="UTF-8"?>
<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 dbchangelog-3.5.xsd">
<changeSet id="moving changesets from changelog to changelog2" author="Maros Kovacme">
<sql>
UPDATE DATABASECHANGELOG
SET
FILENAME = REPLACE(FILENAME, 'changelog.xml', 'changelog2.xml'))
WHERE
ID IN (
'changeset2'
);
</sql>
</changeSet>
</databaseChangeLog>
@Configuration
public class MultipleLiquiaseConfiguration {
@Bean
public SpringLiquibase liquibaseChangelog(DataSource dataSource) {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:changelog.xml");
return liquibase;
}
@Bean
@DependsOn("liquibaseChangelog")
public SpringLiquibase liquibaseMigration(DataSource dataSource) {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:tmp-migration.xml");
return liquibase;
}
@Bean("liquibase")
@DependsOn("liquibaseMigration")
public SpringLiquibase liquibaseChangelog2(DataSource dataSource) {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:changelog2.xml");
return liquibase;
}
}