Liquibase 未针对 Spring Boot/MySQL 应用程序执行
Liquibase not executing for Spring Boot/MySQL app
Spring 在这里引导 1.5.8 和 Java 8。我遵循了所有 Spring Boot & Liquibase 指南,但我似乎无法让 Liquibase 工作。
这里是 link 到 GitHub repo 用于准确重现问题,但这里是独家新闻:
我有以下 MySQL 提前创建的 v8 数据库(在应用程序运行之前):
CREATE DATABASE IF NOT EXISTS troubleshooting_db CHARACTER SET utf8 COLLATE utf8_general_ci;
我有以下 src/main/resources/db/changelog
个文件:
db.changelog-master.yaml:
===
databaseChangeLog:
- include:
file: db/changelog/1-setup.sql
1-setup.sql:
===
--liquibase formatted sql
--changeset troubleshooting:1 dbms:mysql
-- LOOKUPS
CREATE TABLE IF NOT EXISTS metric_range_categories (
metric_range_category_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
metric_range_category_ref_id VARCHAR(36) NOT NULL,
metric_range_category_name VARCHAR(250) NOT NULL,
metric_range_category_label VARCHAR(250) NOT NULL,
metric_range_category_description VARCHAR(500) NOT NULL,
CONSTRAINT pk_metric_range_categories PRIMARY KEY (metric_range_category_id),
INDEX idx_metric_range_categories_metric_range_category_ref_id (metric_range_category_ref_id),
INDEX idx_metric_range_categories_metric_range_category_label (metric_range_category_label),
CONSTRAINT uc_metric_range_categories_metric_range_category_ref_id UNIQUE (metric_range_category_ref_id),
CONSTRAINT uc_metric_range_categories_metric_range_category_name UNIQUE (metric_range_category_name),
CONSTRAINT uc_metric_range_categories_metric_range_category_label UNIQUE (metric_range_category_label)
);
-- Lots of other CREATE TABLE statements down here...
以及以下 JPA 注释实体:
@Entity
@Table(name = "metric_range_categories")
@AttributeOverrides({
@AttributeOverride(name = "id", column = @Column(name = "metric_range_category_id")),
@AttributeOverride(name = "refId", column = @Column(name = "metric_range_category_ref_id")),
@AttributeOverride(name = "name", column = @Column(name = "metric_range_category_name")),
@AttributeOverride(name = "label", column = @Column(name = "metric_range_category_label")),
@AttributeOverride(name = "description", column = @Column(name = "metric_range_category_description"))
})
public class MetricRangeCategory extends BaseLookup {
public MetricRangeCategory() {
}
public MetricRangeCategory(Long id, String refId, String name, String label, String description) {
super(id, refId, name, label, description);
}
}
在运行时我得到以下异常:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [metric_range_categories]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:67)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:475)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 29 common frames omitted
因此当它启动时,Liquibase 不会 excute/engage 因此 Hibernate JPA 验证失败,因为它正在寻找不存在的 table (因为 Liquibase 从未介入并完成它的工作!)。关于我要去哪里出错的任何想法?为什么 Liquibase 没有加入?
有 2 个不同的问题in the repo:
- application.yml 的位置错误。将它从根移动到
src/main/resources
- 嵌套在 属性 中 TroubleshootingConfig.Machine
具有空值,因为未创建此 bean "authInfo" 并且上下文初始化失败。这是 Spring Boot Configuration Binding 工作原理的参考。
Spring 在这里引导 1.5.8 和 Java 8。我遵循了所有 Spring Boot & Liquibase 指南,但我似乎无法让 Liquibase 工作。
这里是 link 到 GitHub repo 用于准确重现问题,但这里是独家新闻:
我有以下 MySQL 提前创建的 v8 数据库(在应用程序运行之前):
CREATE DATABASE IF NOT EXISTS troubleshooting_db CHARACTER SET utf8 COLLATE utf8_general_ci;
我有以下 src/main/resources/db/changelog
个文件:
db.changelog-master.yaml:
===
databaseChangeLog:
- include:
file: db/changelog/1-setup.sql
1-setup.sql:
===
--liquibase formatted sql
--changeset troubleshooting:1 dbms:mysql
-- LOOKUPS
CREATE TABLE IF NOT EXISTS metric_range_categories (
metric_range_category_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
metric_range_category_ref_id VARCHAR(36) NOT NULL,
metric_range_category_name VARCHAR(250) NOT NULL,
metric_range_category_label VARCHAR(250) NOT NULL,
metric_range_category_description VARCHAR(500) NOT NULL,
CONSTRAINT pk_metric_range_categories PRIMARY KEY (metric_range_category_id),
INDEX idx_metric_range_categories_metric_range_category_ref_id (metric_range_category_ref_id),
INDEX idx_metric_range_categories_metric_range_category_label (metric_range_category_label),
CONSTRAINT uc_metric_range_categories_metric_range_category_ref_id UNIQUE (metric_range_category_ref_id),
CONSTRAINT uc_metric_range_categories_metric_range_category_name UNIQUE (metric_range_category_name),
CONSTRAINT uc_metric_range_categories_metric_range_category_label UNIQUE (metric_range_category_label)
);
-- Lots of other CREATE TABLE statements down here...
以及以下 JPA 注释实体:
@Entity
@Table(name = "metric_range_categories")
@AttributeOverrides({
@AttributeOverride(name = "id", column = @Column(name = "metric_range_category_id")),
@AttributeOverride(name = "refId", column = @Column(name = "metric_range_category_ref_id")),
@AttributeOverride(name = "name", column = @Column(name = "metric_range_category_name")),
@AttributeOverride(name = "label", column = @Column(name = "metric_range_category_label")),
@AttributeOverride(name = "description", column = @Column(name = "metric_range_category_description"))
})
public class MetricRangeCategory extends BaseLookup {
public MetricRangeCategory() {
}
public MetricRangeCategory(Long id, String refId, String name, String label, String description) {
super(id, refId, name, label, description);
}
}
在运行时我得到以下异常:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [metric_range_categories]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:67)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:475)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 29 common frames omitted
因此当它启动时,Liquibase 不会 excute/engage 因此 Hibernate JPA 验证失败,因为它正在寻找不存在的 table (因为 Liquibase 从未介入并完成它的工作!)。关于我要去哪里出错的任何想法?为什么 Liquibase 没有加入?
有 2 个不同的问题in the repo:
- application.yml 的位置错误。将它从根移动到 src/main/resources
- 嵌套在 属性 中 TroubleshootingConfig.Machine 具有空值,因为未创建此 bean "authInfo" 并且上下文初始化失败。这是 Spring Boot Configuration Binding 工作原理的参考。