数据库改动版本控制工具flyway
官网地址:https://documentation.red-gate.com/fd/quickstart-how-flyway-works-184127223.html
为什么选择flyway
- 官网给的信息:
They allow you to:
Recreate a database from scratch
Make it clear at all times what state a database is in
Migrate in a deterministic way from your current version of the database to a newer one
springboot整合flyway
官网给的地址:http://www.masterspringboot.com/programming/various/flyway-tutorial-for-spring-boot-users/
核心源码阅读路径
执行的核心代码位置入口
spring-boot-autoconfigure包中:
org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer->afterPropertiesSet->migrate方法
一般会见到一些探测的问题,是在org.flywaydb.core.Flyway#doValidate类中里面做的
- 常见的问题
Caused by: org.flywaydb.core.api.FlywayException: Validate failed:
Detected resolved migration not applied to database: 001.002.001.001
具体的而校验逻辑是在:org.flywaydb.core.internal.command.DbValidate#validate 这个类进行的
校验过程中创建MigrationInfoServiceImpl,其中加载已有脚本是在org.flywaydb.core.internal.info.MigrationInfoServiceImpl#refresh这个方法执行的时候进行的
- 这块的逻辑是根据context的配置信息获取指定classpath的SQL脚本文件
Collection<ResolvedMigration> resolvedMigrations = migrationResolver.resolveMigrations(context);
- SQL脚本是否已经执行标识,后面新增的保存近pendingResolverVersioned。如果已经执行过的序号中间新增会报错
ResolvedMigration resolvedMigration = resolvedVersioned.get(Pair.of(av.getLeft().getVersion(), av.getLeft().getType().isUndo()));
if (resolvedMigration != null) {
pendingResolvedVersioned.remove(resolvedMigration);
}
分类:
数据库
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏