Liquibase在想法

时间:2018-05-01 12:03:14

标签: mysql spring-boot liquibase

当我在默认运行模式下启动spring boot应用程序时,它会正常执行liquibase语句。

再次停止并再次运行会正常跳过变更集,因为它已经执行了。

从调试模式开始,但是尝试再次执行变更集,即使它已经运行了。

我把它转过来并首先在debug中执行了更改,它在databasechangelog中整齐地创建了条目 当在非调试模式下第二次运行时,同样的情况发生

我的更改是本机sql格式,数据库是带有mysql连接器的mariadb

我比较了两个databasechangelog(先运行vs先调试)条目的md5总和,它们是相同的。

liquibase版本是3.5.4我也测试了3.5.5,结果相同

mysql Ver 15.1使用readline 5.2分发10.0.34-MariaDB,用于debian-linux-gnu(x86_64)

这里也是liquibase失败的记录部分

2018-05-01 13:54:00.610 DEBUG 27486 --- [           main] liquibase                                : Connected to xxx@localhost@jdbc:mysql://localhost:3306/project1_db?nullNamePatternMatchesAll=true
2018-05-01 13:54:00.610 DEBUG 27486 --- [           main] liquibase                                : Setting auto commit to false from true
2018-05-01 13:54:00.642 DEBUG 27486 --- [           main] liquibase                                : Executing QUERY database command: select count(*) from project1_db.DATABASECHANGELOGLOCK
2018-05-01 13:54:00.647 DEBUG 27486 --- [           main] liquibase                                : Executing QUERY database command: select count(*) from project1_db.DATABASECHANGELOGLOCK
2018-05-01 13:54:00.648 DEBUG 27486 --- [           main] liquibase                                : Executing QUERY database command: SELECT LOCKED FROM project1_db.DATABASECHANGELOGLOCK WHERE ID=1
2018-05-01 13:54:00.649 DEBUG 27486 --- [           main] liquibase                                : Lock Database
2018-05-01 13:54:00.655 DEBUG 27486 --- [           main] liquibase                                : Executing UPDATE database command: UPDATE project1_db.DATABASECHANGELOGLOCK SET LOCKED = 1, LOCKEDBY = 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)', LOCKGRANTED = '2018-05-01 13:54:00.650' WHERE ID = 1 AND LOCKED = 0
2018-05-01 13:54:00.657  INFO 27486 --- [           main] liquibase                                : Successfully acquired change log lock
2018-05-01 13:54:00.672 DEBUG 27486 --- [           main] liquibase                                : Opening file:/home/xxx/project1-connector/project1-backend/target/classes/db/changelog/db.changelog-master.yaml as classpath:/db/changelog/db.changelog-master.yaml
2018-05-01 13:54:00.687 DEBUG 27486 --- [           main] liquibase                                : includeAll for db/changelog/changes/
2018-05-01 13:54:00.687 DEBUG 27486 --- [           main] liquibase                                : Using file opener for includeAll: liquibase.integration.spring.SpringLiquibase$SpringResourceOpener(jdk.internal.loader.ClassLoaders$AppClassLoader)
2018-05-01 13:54:00.690 DEBUG 27486 --- [           main] liquibase                                : Opening file:/home/xxx/project1-connector/project1-backend/target/classes/db/changelog/changes/db.change.sql as db/changelog/changes/db.change.sql
2018-05-01 13:54:00.690 DEBUG 27486 --- [           main] liquibase                                : Opening file:/home/xxx/project1-connector/project1-backend/target/classes/db/changelog/changes/db.change.sql as db/changelog/changes/db.change.sql
2018-05-01 13:54:00.694 DEBUG 27486 --- [           main] liquibase                                : Computed checksum for 1525175640693 as 422ae5f56810de3fc5eeb17bb4af5afe
2018-05-01 13:54:00.710 DEBUG 27486 --- [           main] liquibase                                : Executing QUERY database command: SELECT MD5SUM FROM project1_db.DATABASECHANGELOG WHERE MD5SUM IS NOT NULL LIMIT 1
2018-05-01 13:54:00.711 DEBUG 27486 --- [           main] liquibase                                : Executing QUERY database command: select count(*) from project1_db.DATABASECHANGELOG
2018-05-01 13:54:00.712  INFO 27486 --- [           main] liquibase                                : Reading from project1_db.DATABASECHANGELOG
2018-05-01 13:54:00.712 DEBUG 27486 --- [           main] liquibase                                : Executing QUERY database command: SELECT * FROM project1_db.DATABASECHANGELOG ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC
2018-05-01 13:54:00.716 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Computed checksum for inputStream as 0c73ccd0174246a5a7fab00d26cc30d2
2018-05-01 13:54:00.720 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Computed checksum for 7:0c73ccd0174246a5a7fab00d26cc30d2: as 22c8e24ae058e8e523819972d470a98a
2018-05-01 13:54:00.721 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Running Changeset:db/changelog/changes/db.change.sql::basicdata::xxx
2018-05-01 13:54:00.721 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Changeset db/changelog/changes/db.change.sql::basicdata::xxx
2018-05-01 13:54:00.721 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Reading ChangeSet: db/changelog/changes/db.change.sql::basicdata::xxx
2018-05-01 13:54:00.727 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Executing Statement: insert into company (id, name, created_at, created_by)
values (1, 'mycompany', now(), 'xxx')
2018-05-01 13:54:00.728 DEBUG 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Executing EXECUTE database command: insert into company (id, name, created_at, created_by)
values (1, 'mycompany', now(), 'xxx')
2018-05-01 13:54:00.733 ERROR 27486 --- [           main] liquibase                                : classpath:/db/changelog/db.changelog-master.yaml: db/changelog/changes/db.change.sql::basicdata::xxx: Change Set db/changelog/changes/db.change.sql::basicdata::xxx failed.  Error: Duplicate entry '1' for key 'PRIMARY' [Failed SQL: insert into company (id, name, created_at, created_by)
values (1, 'mycompany', now(), 'xxx')]

1 个答案:

答案 0 :(得分:1)

我想这可能是logicalFilePath的问题。也许你的类路径在调试和正常运行中略有不同。尝试在sql文件中指定它。 look here获取信息。