飞路设置问题
Flyway setup issues
我正在尝试在 Intellij 中创建一个简单的数据库迁移,其中包含一些使用 flyway 的虚拟 tables。
我的虚拟 table 放在 "resources/db/migration" 中,格式为 "V1_0__initial_display.sql"。
它们可能包含这样的内容:
CREATE TABLE Fake (
ID int,
name varchar(255)
);
CREATE TABLE Persons(
ID int,
name varchar (30)
);
INSERT INTO Persons(ID, name)
VALUES(1,'AXC');
INSERT INTO Persons(ID, name)
VALUES(2,'BB');
我的application.properties:
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.logging.level.org.hibernate.SQL=debug
spring.flyway.enabled=true
spring.flyway.user=${db_username}
spring.flyway.password=${db_password}
spring.flyway.url=${database}
spring.flyway.locations=classpath:/db/migration/V1_0__initial_display.sql
我gradle.build的相关部分:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly System.getenv("database")
runtimeOnly 'mysql:mysql-connector-java'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile "org.flywaydb:flyway-core:5.2.4" +
""
flywayMigration "com.xy.z"
}
flyway {
schemas = ['fake', 'persons']
placeholders = [
'keyABC' : 'valueXYZ',
'otherplaceholder': 'value123'
]
url = (System.getenv("database"))
user = (System.getenv("db_username"))
password = (System.getenv("db_password"))
}
我的环境格式。名为数据库的变量:
jdbc:mysql://localhost/xy
SpringBoot应用本身:
@SpringBootApplication
public class XyApplication {
public static void main(String[] args) {
SpringApplication.run(XyApplication.class, args);
System.out.println("Hello World!");
Flyway flyway = Flyway.configure().dataSource(System.getenv("database"),
System.getenv("db_username"), System.getenv("db_password")).load();
flyway.clean();
flyway.baseline();
flyway.migrate();
}
}
错误信息:
Caused by: org.flywaydb.core.api.FlywayException: Found non-empty schema(s)
`xy` without schema history table! Use baseline() or set
baselineOnMigrate to true to initialize the schema history table.
我最近从我的数据库中删除了 flyway_schema_history。我认为主要问题在于此,我正在尝试对其进行初始化。不幸的是,这不是唯一的问题:在我删除此 table 之前,我的实施还没有奏效,因此可能存在更多概念性问题。
你能帮帮我吗?我该如何解决这个问题?
错误消息包含有关如何解决此问题的所有必要信息。
将 spring.flyway.baselineOnMigrate=true
添加到您的 application.properties。
Flyway 期望成为架构上的第一件事 运行。处理此问题的正确方法是在本地删除 xy
模式中的所有内容,并使用迁移文件 (.sql) 构建所有内容。如果您在数据库中有任何不想删除的内容,您可以在调用中使用基线标志来表明您知道 table.
中的数据
通常,FlyWay 和其他类似的迁移工具用于允许开发人员在不同的数据库(如开发和生产,或不同的开发人员机器)中创建相同的模式。如果你已经在 xy
中有一个不是来自 FlyWay 的 table,你可以在你的代码中使用它并且它会工作,但是生产和其他开发人员不会有这个 table.
我正在尝试在 Intellij 中创建一个简单的数据库迁移,其中包含一些使用 flyway 的虚拟 tables。
我的虚拟 table 放在 "resources/db/migration" 中,格式为 "V1_0__initial_display.sql"。
它们可能包含这样的内容:
CREATE TABLE Fake (
ID int,
name varchar(255)
);
CREATE TABLE Persons(
ID int,
name varchar (30)
);
INSERT INTO Persons(ID, name)
VALUES(1,'AXC');
INSERT INTO Persons(ID, name)
VALUES(2,'BB');
我的application.properties:
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.logging.level.org.hibernate.SQL=debug
spring.flyway.enabled=true
spring.flyway.user=${db_username}
spring.flyway.password=${db_password}
spring.flyway.url=${database}
spring.flyway.locations=classpath:/db/migration/V1_0__initial_display.sql
我gradle.build的相关部分:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly System.getenv("database")
runtimeOnly 'mysql:mysql-connector-java'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile "org.flywaydb:flyway-core:5.2.4" +
""
flywayMigration "com.xy.z"
}
flyway {
schemas = ['fake', 'persons']
placeholders = [
'keyABC' : 'valueXYZ',
'otherplaceholder': 'value123'
]
url = (System.getenv("database"))
user = (System.getenv("db_username"))
password = (System.getenv("db_password"))
}
我的环境格式。名为数据库的变量:
jdbc:mysql://localhost/xy
SpringBoot应用本身:
@SpringBootApplication
public class XyApplication {
public static void main(String[] args) {
SpringApplication.run(XyApplication.class, args);
System.out.println("Hello World!");
Flyway flyway = Flyway.configure().dataSource(System.getenv("database"),
System.getenv("db_username"), System.getenv("db_password")).load();
flyway.clean();
flyway.baseline();
flyway.migrate();
}
}
错误信息:
Caused by: org.flywaydb.core.api.FlywayException: Found non-empty schema(s)
`xy` without schema history table! Use baseline() or set
baselineOnMigrate to true to initialize the schema history table.
我最近从我的数据库中删除了 flyway_schema_history。我认为主要问题在于此,我正在尝试对其进行初始化。不幸的是,这不是唯一的问题:在我删除此 table 之前,我的实施还没有奏效,因此可能存在更多概念性问题。
你能帮帮我吗?我该如何解决这个问题?
错误消息包含有关如何解决此问题的所有必要信息。
将 spring.flyway.baselineOnMigrate=true
添加到您的 application.properties。
Flyway 期望成为架构上的第一件事 运行。处理此问题的正确方法是在本地删除 xy
模式中的所有内容,并使用迁移文件 (.sql) 构建所有内容。如果您在数据库中有任何不想删除的内容,您可以在调用中使用基线标志来表明您知道 table.
通常,FlyWay 和其他类似的迁移工具用于允许开发人员在不同的数据库(如开发和生产,或不同的开发人员机器)中创建相同的模式。如果你已经在 xy
中有一个不是来自 FlyWay 的 table,你可以在你的代码中使用它并且它会工作,但是生产和其他开发人员不会有这个 table.