flyway实战

2024-03-02 22:52
文章标签 实战 flyway

本文主要是介绍flyway实战,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

flyway是一款用来管理数据库版本的工具框架

一, 添加依赖

<dependency><groupId>org.flywaydb</groupId><artifactId>flyway-core</artifactId>
</dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId>
</dependency>

二, 编写配置类

MySQLDatabase

/** Copyright (C) Red Gate Software Ltd 2010-2021** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**         http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package org.flywaydb.core.internal.database.mysql;import lombok.CustomLog;
import lombok.extern.slf4j.Slf4j;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.MigrationType;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.database.base.BaseDatabaseType;
import org.flywaydb.core.internal.database.base.Table;
import org.flywaydb.core.internal.database.mysql.mariadb.MariaDBDatabaseType;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.JdbcTemplate;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;import java.sql.Connection;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;@Slf4j
public class MySQLDatabase extends Database<MySQLConnection> {// See https://mariadb.com/kb/en/version/private static final Pattern MARIADB_VERSION_PATTERN = Pattern.compile("(\\d+\\.\\d+)\\.\\d+(-\\d+)*-MariaDB(-\\w+)*");private static final Pattern MARIADB_WITH_MAXSCALE_VERSION_PATTERN = Pattern.compile("(\\d+\\.\\d+)\\.\\d+(-\\d+)* (\\d+\\.\\d+)\\.\\d+(-\\d+)*-maxscale(-\\w+)*");private static final Pattern MYSQL_VERSION_PATTERN = Pattern.compile("(\\d+\\.\\d+)\\.\\d+\\w*");/*** Whether this is a Percona XtraDB Cluster in strict mode.*/private final boolean pxcStrict;/*** Whether this database is enforcing GTID consistency.*/private final boolean gtidConsistencyEnforced;/*** Whether the event scheduler table is queryable.*/final boolean eventSchedulerQueryable;public MySQLDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {super(configuration, jdbcConnectionFactory, statementInterceptor);JdbcTemplate jdbcTemplate = new JdbcTemplate(rawMainJdbcConnection, databaseType);pxcStrict = isMySQL() && isRunningInPerconaXtraDBClusterWithStrictMode(jdbcTemplate);gtidConsistencyEnforced = isMySQL() && isRunningInGTIDConsistencyMode(jdbcTemplate);eventSchedulerQueryable = false;}private static boolean isEventSchedulerQueryable(JdbcTemplate jdbcTemplate) {try {// Attempt queryjdbcTemplate.queryForString("SELECT event_name FROM information_schema.events LIMIT 1");return true;} catch (SQLException e) {log.debug("Detected unqueryable MariaDB event scheduler, most likely due to it being OFF or DISABLED.");return false;}}static boolean isRunningInPerconaXtraDBClusterWithStrictMode(JdbcTemplate jdbcTemplate) {try {String pcx_strict_mode = jdbcTemplate.queryForString("select VARIABLE_VALUE from performance_schema.global_variables"+ " where variable_name = 'pxc_strict_mode'");if ("ENFORCING".equals(pcx_strict_mode) || "MASTER".equals(pcx_strict_mode)) {log.debug("Detected Percona XtraDB Cluster in strict mode");return true;}} catch (SQLException e) {log.debug("Unable to detect whether we are running in a Percona XtraDB Cluster. Assuming not to be.");}return false;}static boolean isRunningInGTIDConsistencyMode(JdbcTemplate jdbcTemplate) {try {String gtidConsistency = jdbcTemplate.queryForString("SELECT @@GLOBAL.ENFORCE_GTID_CONSISTENCY");if ("ON".equals(gtidConsistency)) {log.debug("Detected GTID consistency being enforced");return true;}} catch (SQLException e) {log.debug("Unable to detect whether database enforces GTID consistency. Assuming not.");}return false;}boolean isMySQL() {return databaseType instanceof MySQLDatabaseType;}boolean isMariaDB() {return databaseType instanceof MariaDBDatabaseType;}boolean isPxcStrict() {return pxcStrict;}/** CREATE TABLE ... AS SELECT ... cannot be used in three scenarios:* - Percona XtraDB Cluster in strict mode doesn't support it* - TiDB doesn't support it (overridden elsewhere)* - When GTID consistency is being enforced. Note that if GTID_MODE is ON, then ENFORCE_GTID_CONSISTENCY is* necessarily ON as well.*/protected boolean isCreateTableAsSelectAllowed() {return !pxcStrict && !gtidConsistencyEnforced;}@Overridepublic String getRawCreateScript(Table table, boolean baseline) {String tablespace =configuration.getTablespace() == null? "": " TABLESPACE \"" + configuration.getTablespace() + "\"";String baselineMarker = "";if (baseline) {if (isCreateTableAsSelectAllowed()) {baselineMarker = " AS SELECT" +"     1 as \"installed_rank\"," +"     '" + configuration.getBaselineVersion() + "' as \"version\"," +"     '" + configuration.getBaselineDescription() + "' as \"description\"," +"     '" + MigrationType.BASELINE + "' as \"type\"," +"     '" + configuration.getBaselineDescription() + "' as \"script\"," +"     NULL as \"checksum\"," +"     '" + getInstalledBy() + "' as \"installed_by\"," +"     CURRENT_TIMESTAMP as \"installed_on\"," +"     0 as \"execution_time\"," +"     TRUE as \"success\"\n";} else {// Revert to regular insert, which unfortunately is not safe in concurrent scenarios// due to MySQL implicit commits after DDL statements.baselineMarker = ";\n" + getBaselineStatement(table);}}return "CREATE TABLE " + table + " (\n" +"    `installed_rank` INT NOT NULL,\n" +"    &

这篇关于flyway实战的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/767675

相关文章

网页解析 lxml 库--实战

lxml库使用流程 lxml 是 Python 的第三方解析库,完全使用 Python 语言编写,它对 XPath表达式提供了良好的支 持,因此能够了高效地解析 HTML/XML 文档。本节讲解如何通过 lxml 库解析 HTML 文档。 pip install lxml lxm| 库提供了一个 etree 模块,该模块专门用来解析 HTML/XML 文档,下面来介绍一下 lxml 库

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

滚雪球学Java(87):Java事务处理:JDBC的ACID属性与实战技巧!真有两下子!

咦咦咦,各位小可爱,我是你们的好伙伴——bug菌,今天又来给大家普及Java SE啦,别躲起来啊,听我讲干货还不快点赞,赞多了我就有动力讲得更嗨啦!所以呀,养成先点赞后阅读的好习惯,别被干货淹没了哦~ 🏆本文收录于「滚雪球学Java」专栏,专业攻坚指数级提升,助你一臂之力,带你早日登顶🚀,欢迎大家关注&&收藏!持续更新中,up!up!up!! 环境说明:Windows 10

springboot实战学习(1)(开发模式与环境)

目录 一、实战学习的引言 (1)前后端的大致学习模块 (2)后端 (3)前端 二、开发模式 一、实战学习的引言 (1)前后端的大致学习模块 (2)后端 Validation:做参数校验Mybatis:做数据库的操作Redis:做缓存Junit:单元测试项目部署:springboot项目部署相关的知识 (3)前端 Vite:Vue项目的脚手架Router:路由Pina:状态管理Eleme

深度学习实战:如何利用CNN实现人脸识别考勤系统

1. 何为CNN及其在人脸识别中的应用 卷积神经网络(CNN)是深度学习中的核心技术之一,擅长处理图像数据。CNN通过卷积层提取图像的局部特征,在人脸识别领域尤其适用。CNN的多个层次可以逐步提取面部的特征,最终实现精确的身份识别。对于考勤系统而言,CNN可以自动从摄像头捕捉的视频流中检测并识别出员工的面部。 我们在该项目中采用了 RetinaFace 模型,它基于CNN的结构实现高效、精准的

项目实战系列三: 家居购项目 第四部分

购物车 🌳购物车🍆显示购物车🍆更改商品数量🍆清空购物车&&删除商品 🌳生成订单 🌳购物车 需求分析 1.会员登陆后, 可以添加家居到购物车 2.完成购物车的设计和实现 3.每添加一个家居,购物车的数量+1, 并显示 程序框架图 1.新建src/com/zzw/furns/entity/CartItem.java, CartItem-家居项模型 /***

Birt报表开发实战

我就截图描述得了,没什么含金量,看图基本明白的。 1.开始 a.创建报表文件 b.数据源配置 c.配置数据集 2.网格报表 拖拉式操作,很方便 3.预览效果 其他报表的操作也基本不难,就不扯了! 2.级联参数 官方视频教程:http://demo.actuate.com/demos/cascade/cascade.html

[yolov5] --- yolov5入门实战「土堆视频」

1 项目介绍及环境配置 下载yolov5 tags 5.0源码,https://github.com/ultralytics/yolov5/tree/v5.0,解压 Pycharm 中创建conda虚拟环境 激活conda虚拟环境 根据作者提供的requirements.txt文件,pip install -r requirements.txt 如果作者没有提供requirement.txt文件

用Python实现时间序列模型实战——Day 14: 向量自回归模型 (VAR) 与向量误差修正模型 (VECM)

一、学习内容 1. 向量自回归模型 (VAR) 的基本概念与应用 向量自回归模型 (VAR) 是多元时间序列分析中的一种模型,用于捕捉多个变量之间的相互依赖关系。与单变量自回归模型不同,VAR 模型将多个时间序列作为向量输入,同时对这些变量进行回归分析。 VAR 模型的一般形式为: 其中: ​ 是时间  的变量向量。 是常数向量。​ 是每个时间滞后的回归系数矩阵。​ 是误差项向量,假