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" +"    &

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/714881.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/714881.shtml
英文地址,請注明出處:http://en.pswp.cn/news/714881.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

第十一屆藍橋杯省賽第一場C++ A組 / B組《網絡分析》(c++)

1.題目說明 小明正在做一個網絡實驗。 他設置了 n 臺電腦&#xff0c;稱為節點&#xff0c;用于收發和存儲數據。 初始時&#xff0c;所有節點都是獨立的&#xff0c;不存在任何連接。 小明可以通過網線將兩個節點連接起來&#xff0c;連接后兩個節點就可以互相通信了。 兩…

代碼隨想錄算法訓練營第二十五天 | 216.組合總和III 17.電話號碼的字母組合

216.組合總和III https://programmercarl.com/0216.%E7%BB%84%E5%90%88%E6%80%BB%E5%92%8CIII.html#%E5%85%B6%E4%BB%96%E8%AF%AD%E8%A8%80%E7%89%88%E6%9C%AC class Solution:def combinationSum3(self, k: int, n: int) -> List[List[int]]:result [] # 存放結果集sel…

實現一個移動端焦點輪播圖

HTML結構&#xff1a; 創建一個輪播圖的容器&#xff0c;并在其中放置輪播圖片。 <div id"carousel"> <div class"carousel-item active"> <img src"image1.jpg" alt"Image 1"> </div> <div class&q…

Docker部署ZooKeeper

在分布式系統中,ZooKeeper是一個關鍵的組件,用于協調和管理多個節點之間的狀態。本文將詳細介紹如何使用Docker安裝和部署ZooKeeper,包括非集群部署和集群部署兩種情況。 非集群部署 前期準備 在開始之前,請確保你已經安裝了Docker,并且擁有sudo權限。 關閉防火墻和SEL…

5、DVWA代碼審計(2)

一、csrf 1、csrf(low) 限制 復現 GET /vulnerabilities/csrf/?password_new123456&password_conf123456&ChangeChange HTTP/1.1 Host: ddd.com Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,…

電子電器架構 —— DoIP協議相關的介紹

電子電器架構 —— DoIP協議相關的介紹 我是穿拖鞋的漢子,魔都中堅持長期主義的汽車電子工程師。 老規矩,分享一段喜歡的文字,避免自己成為高知識低文化的工程師: 沒有人關注你。也無需有人關注你。你必須承認自己的價值,你不能站在他人的角度來反對自己。人生在世,最怕…

監聽者的力量:探索觀察者模式和spring使用

觀察者模式是一種對象行為型設計模式&#xff0c;它定義了對象之間的一對多依賴關系。 觀察者模式通常用于實現分布式事件處理系統、新聞代理或MVC框架的一部分。在這種模式中&#xff0c;一個對象&#xff08;稱為“主題”或“可觀察對象”&#xff09;維護一系列依賴于它的對…

vue3編寫H5適配橫豎屏

具體思路如下&#xff1a; 1、監聽瀏覽器屏幕變化&#xff0c;通過監聽屏幕寬高&#xff0c;辨別出是橫屏&#xff0c;還是豎屏狀態 在項目的起始根頁面進行監聽&#xff0c;我就是在App.vue文件下進行監聽 代碼如下&#xff1a; <template><RouterView /> <…

【Spring IoC】實驗四:特殊值處理

個人名片&#xff1a; &#x1f43c;作者簡介&#xff1a;一名大三在校生&#xff0c;喜歡AI編程&#x1f38b; &#x1f43b;???個人主頁&#x1f947;&#xff1a;落798. &#x1f43c;個人WeChat&#xff1a;hmmwx53 &#x1f54a;?系列專欄&#xff1a;&#x1f5bc;?…

Java4種創建線程方式

目錄 一&#xff1a;繼承Thread 二&#xff1a;重新Runnable接口 三&#xff1a;Callable 四&#xff1a;lambda 一&#xff1a;繼承Thread public static void main(String[] args) {Thread1 t1new Thread1();t1.start(); } class Thread1 extends Thread {Overridepublic…

C++ //練習 10.16 使用lambda編寫你自己版本的biggies。

C Primer&#xff08;第5版&#xff09; 練習 10.16 練習 10.16 使用lambda編寫你自己版本的biggies。 環境&#xff1a;Linux Ubuntu&#xff08;云服務器&#xff09; 工具&#xff1a;vim 代碼塊 /*******************************************************************…

BERTopic安裝最全教程及報錯處理

BERTopic安裝 BERTopic的安裝比較復雜,直接安裝會報錯 安裝方法1,.whl文件安裝 ERROR: Could not build wheels for hdbscan, which is required to install pyproject.toml-based projects正確安裝流程 查看python能安裝whl的版本pip debug --verbose Compatible tags: 2…

圖表背后的智慧:辦公場景中的數據可視化革新

在現代辦公場景中&#xff0c;數據可視化的應用已經成為提高效率、推動創新的得力工具。無論是管理層還是普通員工&#xff0c;都能從數據可視化中受益匪淺。下面我就以可視化從業者的角度&#xff0c;簡單聊聊這個話題。 首先&#xff0c;數據可視化提升了數據的易讀性與理解性…

docker安裝最新版lastest

docker pull mysql 報missing signature key錯誤問題原因&#xff1a;如果安裝docker用的是yum install docker命令的話&#xff0c;下載下來的docker版本為舊版本&#xff0c;所以會有數字簽名有問題 最新版docker安裝方法&#xff1a; 卸載舊版本 Docker&#xff08;如果已安…

【研發日記】Matlab/Simulink技能解鎖(三)——在Stateflow編輯窗口Debug

文章目錄 前言 State斷點 Transition斷點 條件斷點 按State步進 Watch Data Value Sequence Viewer 分析和應用 總結 前言 見《【研發日記】Matlab/Simulink技能解鎖(一)——在Simulink編輯窗口Debug》 見《【研發日記】Matlab/Simulink技能解鎖(二)——在Function編輯…

AQS(抽象隊列同步器)

什么是AQS? AQS&#xff08;AbstractQueuedSynchronizer&#xff09;是Java中用于實現鎖和同步器的基礎框架。它是一個抽象類&#xff0c;提供了一種靈活且強大的方式來實現各種同步器&#xff0c;如ReentrantLock、Semaphore、CountDownLatch等 AQS實現原理&#xff1f; 1、…

Flink狀態存儲-StateBackend

文章目錄 前言一、MemoryStateBackend二、FSStateBackend三、RocksDBStateBackend四、StateBackend配置方式五、狀態持久化六、狀態重分布OperatorState 重分布KeyedState 重分布 七、狀態過期 前言 Flink是一個流處理框架&#xff0c;它需要對數據流進行狀態管理以支持復雜的…

10個技巧,3分鐘教會你高效尋找開源項目

作為程序員&#xff0c;不論是開發還是學習&#xff0c;肯定會用到開源項目&#xff0c;那么怎么快速在開源網站找到這些項目呢&#xff1f; 常用的開源網站有&#xff1a;github 和 gitee github是全球最大的開源社區&#xff0c;今天就以github為例&#xff0c;演示一下 gi…

【vue】vue中數據雙向綁定原理/響應式原理,mvvm,mvc、mvp分別是什么

關于 vue 的原理主要有兩個重要內容&#xff0c;分別是 mvvm 數據雙向綁定原理&#xff0c;和 響應式原理 MVC&#xff08;Model-View-Controller&#xff09;&#xff1a; Model&#xff08;模型&#xff09;&#xff1a;表示應用程序的數據和業務邏輯。View&#xff08;視圖&…

edge 安裝筆記

依賴項&#xff1a; jukebox 下載代碼GitHub - rodrigo-castellon/jukebox 拷貝到根目錄即可&#xff0c;文件夾留一個根目錄jukebox vqvae_cache_path cache_dir "/vqvae.pth.tar" prior_cache_path cache_dir "/prior_level_2.pth.tar"