无法 运行 来自 Spring 的 flyway 脚本 在 docker 容器中使用数据库作为 Mysql 启动应用程序
Unable to run the flyway scripts from Spring Boot application with database as Mysql in docker container
我有 spring 启动应用程序,其中有很多 flyway 脚本。一旦启动应用程序启动,此脚本将自动 运行。他们 运行 在没有 docker 的情况下正常工作。当我将此应用程序放入 docker 容器中时
application.yml
server:
port:8080
context-path:/tms-server
http:
mappers:
jsonPrettyPrint:true
security:
basic:
enabled:false
cors:
enabled:true
flyway:
enabled:true
clean-on-validation-error:false
validate-on-migrate:false
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false
user:app_user
password:test123
schemas:synfioo_poc
locations:db/migration/mysql
spring:
profiles:
active:mysql
flyway Sql 文件位于 classpath:db/migration/mysql
db/migration/mysql/V0001__R001_Create_schema.sql:
CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
)
我的申请-mysql.yml看起来像
spring:
jpa:
database:mysql
database-platform:org.hibernate.dialect.MySQL5Dialect
datasource:
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false
username:app_user
password:test123
driver-class-name:com.mysql.jdbc.Driver
在 docker 构建之后,我正在将我的 Spring 引导程序与 Mysql Db 链接起来,就像这样
假设我已经正确地创建了 mysql 图像并且它 运行ning 能够从 mysql 客户端创建 table 但 flyway 脚本不是 运行ning 来自 java 程序
还正确创建了 docker 文件
docker run -t --name synfioo-poc-container --link mysql-docker-container:mysql -p 8080:8080 docker-synfioo-core:latest
异常:
2018-05-31 13:28:45.746 INFO 1 --- [ main] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
2018-05-31 13:28:46.783 INFO 1 --- [ main] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
2018-05-31 13:28:47.457 INFO 1 --- [ main] o.f.core.internal.command.DbValidate : Validated 18 migrations (execution time 00:00.506s)
2018-05-31 13:28:47.502 INFO 1 --- [ main] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: "PUBLIC"."schema_version"
2018-05-31 13:28:47.609 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "PUBLIC": << Empty Schema >>
2018-05-31 13:28:47.615 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 0001 - R001 Create schema
2018-05-31 13:28:47.638 ERROR 1 --- [ main] o.f.core.internal.command.DbMigrate : Migration of schema "PUBLIC" to version 0001 failed! Please restore back
ups and roll back database and code!
2018-05-31 13:28:47.670 WARN 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beansBatchConfig': Unsatisfied dependency expressed through me
thod 'setTransactionManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager'
defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoc
onfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Migration V0001__R001_Create_schema.sql failed
----------------------------------------------
SQL State : 90079
Error Code : 90079
Message : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
) [90079-193]
Location : db/migration/mysql/V0001__R001_Create_schema.sql (/file:/synfioo-core-0.0.1-SNAPSHOT.jar!/db/migration/mysql/V0001__R001_Create_schema.sq
Line : 8
Statement : CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
)
任何人都可以帮助解决这个问题。
Message : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
...
看起来 V0001__R001_Create_schema.sql
中引用的 synfioo_poc
模式/数据库在 mysql-docker-container
实例中不存在。
尝试将 createDatabaseIfNotExist=true
添加到 jdbc url 以便 mysql 自动创建它,如有必要:
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false&createDatabaseIfNotExist=true
我有 spring 启动应用程序,其中有很多 flyway 脚本。一旦启动应用程序启动,此脚本将自动 运行。他们 运行 在没有 docker 的情况下正常工作。当我将此应用程序放入 docker 容器中时 application.yml
server:
port:8080
context-path:/tms-server
http:
mappers:
jsonPrettyPrint:true
security:
basic:
enabled:false
cors:
enabled:true
flyway:
enabled:true
clean-on-validation-error:false
validate-on-migrate:false
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false
user:app_user
password:test123
schemas:synfioo_poc
locations:db/migration/mysql
spring:
profiles:
active:mysql
flyway Sql 文件位于 classpath:db/migration/mysql
db/migration/mysql/V0001__R001_Create_schema.sql:
CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
)
我的申请-mysql.yml看起来像
spring:
jpa:
database:mysql
database-platform:org.hibernate.dialect.MySQL5Dialect
datasource:
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false
username:app_user
password:test123
driver-class-name:com.mysql.jdbc.Driver
在 docker 构建之后,我正在将我的 Spring 引导程序与 Mysql Db 链接起来,就像这样
假设我已经正确地创建了 mysql 图像并且它 运行ning 能够从 mysql 客户端创建 table 但 flyway 脚本不是 运行ning 来自 java 程序
还正确创建了 docker 文件
docker run -t --name synfioo-poc-container --link mysql-docker-container:mysql -p 8080:8080 docker-synfioo-core:latest
异常:
2018-05-31 13:28:45.746 INFO 1 --- [ main] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
2018-05-31 13:28:46.783 INFO 1 --- [ main] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
2018-05-31 13:28:47.457 INFO 1 --- [ main] o.f.core.internal.command.DbValidate : Validated 18 migrations (execution time 00:00.506s)
2018-05-31 13:28:47.502 INFO 1 --- [ main] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: "PUBLIC"."schema_version"
2018-05-31 13:28:47.609 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "PUBLIC": << Empty Schema >>
2018-05-31 13:28:47.615 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 0001 - R001 Create schema
2018-05-31 13:28:47.638 ERROR 1 --- [ main] o.f.core.internal.command.DbMigrate : Migration of schema "PUBLIC" to version 0001 failed! Please restore back
ups and roll back database and code!
2018-05-31 13:28:47.670 WARN 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beansBatchConfig': Unsatisfied dependency expressed through me
thod 'setTransactionManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager'
defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoc
onfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Migration V0001__R001_Create_schema.sql failed
----------------------------------------------
SQL State : 90079
Error Code : 90079
Message : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
) [90079-193]
Location : db/migration/mysql/V0001__R001_Create_schema.sql (/file:/synfioo-core-0.0.1-SNAPSHOT.jar!/db/migration/mysql/V0001__R001_Create_schema.sq
Line : 8
Statement : CREATE TABLE synfioo_poc.Binary_Object (
id BIGINT NOT NULL AUTO_INCREMENT,
modification_counter INTEGER NOT NULL,
data BLOB(2147483647),
size BIGINT NOT NULL,
mime_Type VARCHAR(255),
PRIMARY KEY (ID)
)
任何人都可以帮助解决这个问题。
Message : Schema "SYNFIOO_POC" not found; SQL statement:
CREATE TABLE synfioo_poc.Binary_Object (
...
看起来 V0001__R001_Create_schema.sql
中引用的 synfioo_poc
模式/数据库在 mysql-docker-container
实例中不存在。
尝试将 createDatabaseIfNotExist=true
添加到 jdbc url 以便 mysql 自动创建它,如有必要:
url:jdbc:mysql://mysql-docker-container:3306/synfioo_poc?useSSL=false&createDatabaseIfNotExist=true