Existing database setup
These are the steps to follow to successfully integrate Flyway in a project with an existing database.
Take a DDL and reference data extract from production
First start by taking a snapshot of your most important database: production. This will be the starting point for migrations.
Generate a sql script that includes the entire DDL (including indexes, triggers, procedures, ...) of the production database. To do this you will need to add insert statements for all the reference data present in the database.
需要一次性导出现有数据库中的所有表以及存储过程
This script will form your base migration. Save it on the classpath in the directory you configured with baseDir. Give it a relevant version number and description such as V1__Base_version.sql.
Clean all databases containing data you don't mind losing
Now comes the point where we have to make sure that the migrations meant for production will work everywhere.
For all databases with unimportant data you don't mind losing, perform
> flyway clean
to completely remove their contents.
Align the remaining databases with production
Check all remaining databases. You must make sure that their structure (DDL) and reference data matches production exactly. This step is important, as all scripts destined for production will be applied here first. For the scripts to succeed, the objects they migrate must be identical to what is present in production.
Give these databases a baseline version
Now comes the time to baseline the databases that contain data (including production) with a baseline version. Use the same version and description you used for the production extract script created above.
You can accomplish it like this:
> flyway baseline
You must perform this step for each database that hasn't been cleaned.
Done !
Congratulations ! You are now ready.
When you execute
> flyway migrate
the empty databases will be migrated to the state of production and the others will be left as is.
As soon
as you add a new migration, it will be applied identically to all databases.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了