当前位置:网站首页>Flyway的SaaS多租户实现方案
Flyway的SaaS多租户实现方案
2022-07-17 00:15:00 【dragonpeng2008】
一、前言
前面的章节已经实现了mysql、MongoDB、redis和Activiti的多租户切实现方案,本章将继续学习Flyway数据库版本管理工具的多数据源实现方案。Flyway是独立于数据库的应用管理并跟踪数据库变更的数据库版本管理工具.使用Flyway可以像Git管理代码那样管理sql脚本,可以实现不同环境的sql脚本自动更新,开发人员像提交代码一样提交sql更新脚本,程序发布时自动更新数据库脚本,省去了运维人员收集和部署脚本的烦恼,开发环境验证的脚本,部署在测试环境可以自动升级。而且更新过程可追溯,目前Flyway支持很多数据库,常见的MySQL、MariaDB、Oracle都支持。
如果只是对一个数据库进行脚本升级,这个使用Flyway很简单,但是如果要对多租户的多个数据库进行升级,就需要借助Springboot的AbstractRoutingDataSource,在程序启动的时候连接不同租户的数据库进行数据库脚本的升级。
二、实现方案
实现方案很简单,我们只需要在Flyway配置的时候使用我们自定义的数据源即可。
1、首先由于我们已经有了MySQL的多数据源支持,Flyway可以复用该数据源
2、由于Flyway在初始化的时候需要传入一个数据源,我们可以把MySQL的数据源传进去。
3、 最后遍历所有的数据源,执行Flyway的migrate操作就完成了数据库脚本的升级功能。
三、准备
为了演示简单,我们需要准备一些数据库升级的sql脚本,首先是每个租户都需要升级的脚本文件,然后是租户tenant_one和tenant_two各自特有的升级脚本文件。
每个租户都要执行的脚本文件V1.1__create_test_table.sql,创建一个test表:
边栏推荐
- 【瑞吉外卖⑩】Linux 粗略学习 & Redis 粗略学习
- General knowledge of network (detailed)
- uniapp微信小程序登录(先授权微信后授权手机号)-- (1)
- After unity imports the FBX model, the rotation and position of the object will change automatically at runtime
- For solopi app performance test
- [unity Editor Extension] unity makes its own exclusive editor panel
- How to do a good job of test case review
- Reprint: SQL injection common bypass
- 登录功能的测试点大全
- The jstat command checks the GC status of the JVM
猜你喜欢

30分钟搞懂 HTTP 缓存

How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)

Logical vulnerability - authentication vulnerability

bugku---game1

Summary of tree and heap knowledge points

服务器知识(详情)

Software testing technology interim testing summary | software testing foundation & Executive testing & test design and development

STL -- deque container

Network layer transmission protocol (detailed)

InnoDB, MySQL structure, and the difference between the three kinds of deletion
随机推荐
bugku题解
Performance bottleneck positioning XMIND
[unity Editor Extension] unity makes its own exclusive editor panel
Sigaga
接口(Collection/Map)- 各接口的实现与对比
Known preorder traversal, preorder traversal, find the sequence traversal of the tree
性能测试实施规范指南
Jmeter接口测试之响应断言
[solved] after referring to the local MySQL and forgetting the password, [server] --initialize specified but the data directory has files in it Aborti
Sword finger offer 48 The longest substring without repeated characters
status 500 reading AftersaleService#getAftersaleList(Long)+com.sun.proxy.$Proxy214.getAftersaleList
Signal and system experiment
Experience in using flow playback tool Gor
CTFHub----RCE
D - parity game discretization + weighted union search set
30分钟搞懂 HTTP 缓存
JS note 1
Jmeter响应时间测试组件&多接口并发
STL -- stack container
2022 latest software testing tools