修改flyway脚本初始化运行的问题
This commit is contained in:
parent
d073900598
commit
09d798a3d2
@ -109,6 +109,40 @@
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<warName>${project.artifactId}</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Flyway Maven插件 -->
|
||||
<plugin>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-maven-plugin</artifactId>
|
||||
<version>${flyway.version}</version>
|
||||
<configuration>
|
||||
<url>jdbc:postgresql://localhost:5432/qaup?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai</url>
|
||||
<user>postgres</user>
|
||||
<password>123456</password>
|
||||
<locations>
|
||||
<location>classpath:db/migration</location>
|
||||
</locations>
|
||||
<baselineOnMigrate>true</baselineOnMigrate>
|
||||
<baselineVersion>1.0.0</baselineVersion>
|
||||
<baselineDescription>Initial baseline from existing database</baselineDescription>
|
||||
<validateOnMigrate>true</validateOnMigrate>
|
||||
<cleanDisabled>true</cleanDisabled>
|
||||
<outOfOrder>false</outOfOrder>
|
||||
<encoding>UTF-8</encoding>
|
||||
<placeholderReplacement>false</placeholderReplacement>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.7.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-database-postgresql</artifactId>
|
||||
<version>${flyway.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
||||
@ -4,14 +4,15 @@ import org.flywaydb.core.Flyway;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Flyway数据库迁移配置
|
||||
@ -31,8 +32,36 @@ public class FlywayConfig {
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private FlywayProperties flywayProperties;
|
||||
// 直接从配置文件读取Flyway配置,避免依赖FlywayProperties bean
|
||||
@Value("${spring.flyway.locations:classpath:db/migration}")
|
||||
private List<String> locations;
|
||||
|
||||
@Value("${spring.flyway.baseline-on-migrate:true}")
|
||||
private boolean baselineOnMigrate;
|
||||
|
||||
@Value("${spring.flyway.baseline-version:1.0.0}")
|
||||
private String baselineVersion;
|
||||
|
||||
@Value("${spring.flyway.baseline-description:Initial baseline from existing database}")
|
||||
private String baselineDescription;
|
||||
|
||||
@Value("${spring.flyway.validate-on-migrate:true}")
|
||||
private boolean validateOnMigrate;
|
||||
|
||||
@Value("${spring.flyway.clean-disabled:true}")
|
||||
private boolean cleanDisabled;
|
||||
|
||||
@Value("${spring.flyway.out-of-order:false}")
|
||||
private boolean outOfOrder;
|
||||
|
||||
@Value("${spring.flyway.encoding:UTF-8}")
|
||||
private String encoding;
|
||||
|
||||
@Value("${spring.flyway.placeholder-replacement:false}")
|
||||
private boolean placeholderReplacement;
|
||||
|
||||
@Value("${spring.flyway.table:flyway_schema_history}")
|
||||
private String table;
|
||||
|
||||
/**
|
||||
* 自定义Flyway配置
|
||||
@ -48,35 +77,33 @@ public class FlywayConfig {
|
||||
Flyway flyway = Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
// 迁移脚本位置
|
||||
.locations(flywayProperties.getLocations().toArray(new String[0]))
|
||||
.locations(locations.toArray(new String[0]))
|
||||
// 基线迁移设置
|
||||
.baselineOnMigrate(flywayProperties.isBaselineOnMigrate())
|
||||
.baselineVersion(flywayProperties.getBaselineVersion())
|
||||
.baselineDescription(flywayProperties.getBaselineDescription())
|
||||
.baselineOnMigrate(baselineOnMigrate)
|
||||
.baselineVersion(baselineVersion)
|
||||
.baselineDescription(baselineDescription)
|
||||
// 迁移验证
|
||||
.validateOnMigrate(flywayProperties.isValidateOnMigrate())
|
||||
.validateOnMigrate(validateOnMigrate)
|
||||
// 生产环境安全设置
|
||||
.cleanDisabled(flywayProperties.isCleanDisabled())
|
||||
.cleanDisabled(cleanDisabled)
|
||||
// 不允许乱序迁移
|
||||
.outOfOrder(flywayProperties.isOutOfOrder())
|
||||
.outOfOrder(outOfOrder)
|
||||
// 编码设置
|
||||
.encoding(flywayProperties.getEncoding())
|
||||
.encoding(encoding)
|
||||
// 占位符配置
|
||||
.placeholderReplacement(flywayProperties.isPlaceholderReplacement())
|
||||
.placeholderReplacement(placeholderReplacement)
|
||||
// 表名配置
|
||||
.table(flywayProperties.getTable())
|
||||
// 模式配置
|
||||
.schemas(flywayProperties.getSchemas().toArray(new String[0]))
|
||||
.table(table)
|
||||
.load();
|
||||
|
||||
log.info("Flyway配置完成:");
|
||||
log.info(" - 迁移脚本位置: {}", flywayProperties.getLocations());
|
||||
log.info(" - 基线版本: {}", flywayProperties.getBaselineVersion());
|
||||
log.info(" - 基线描述: {}", flywayProperties.getBaselineDescription());
|
||||
log.info(" - 验证迁移: {}", flywayProperties.isValidateOnMigrate());
|
||||
log.info(" - 禁用清理: {}", flywayProperties.isCleanDisabled());
|
||||
log.info(" - 编码: {}", flywayProperties.getEncoding());
|
||||
log.info(" - 迁移脚本位置: {}", locations);
|
||||
log.info(" - 基线版本: {}", baselineVersion);
|
||||
log.info(" - 基线描述: {}", baselineDescription);
|
||||
log.info(" - 验证迁移: {}", validateOnMigrate);
|
||||
log.info(" - 禁用清理: {}", cleanDisabled);
|
||||
log.info(" - 编码: {}", encoding);
|
||||
|
||||
return flyway;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
CREATE SCHEMA topology IF NOT EXISTS topology;
|
||||
CREATE SCHEMA IF NOT EXISTS topology;
|
||||
|
||||
COMMENT ON SCHEMA topology IS 'PostGIS Topology schema';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user