The easiest scenario is when you point Flyway to an empty database.

It will try to locate its schema history table. As the database is empty, Flyway won't find it and will create it instead.

You now have a database with a single empty table called flyway_schema_history by default:

This table will be used to track the state of the database.

Immediately afterwards Flyway will begin scanning the filesystem or the classpath of the application for migrations. They can be written in either Sql or Java.

The migrations are then sorted based on their version number and applied in order:

As each migration gets applied, the schema history table is updated accordingly:

flyway_schema_history
installed_rank version description type script checksum installed_by installed_on execution_time success
1 1 Initial Setup SQL V1__Initial_Setup.sql 1996767037 axel 2016-02-04 22:23:00.0 546 true
2 2 First Changes SQL V2__First_Changes.sql 1279644856 axel 2016-02-06 09:18:00.0 127 true

With the metadata and the initial state in place, we can now talk about migrating to newer versions.

Flyway will once again scan the filesystem or the classpath of the application for migrations. The migrations are checked against the schema history table. If their version number is lower or equal to the one of the version marked as current, they are ignored.

The remaining migrations are the pending migrations: available, but not applied.

They are then sorted by version number and executed in order:

The schema history table is updated accordingly:

flyway_schema_history
installed_rank version description type script checksum installed_by installed_on execution_time success
1 1 Initial Setup SQL V1__Initial_Setup.sql 1996767037 axel 2016-02-04 22:23:00.0 546 true
2 2 First Changes SQL V2__First_Changes.sql 1279644856 axel 2016-02-06 09:18:00.0 127 true
3 2.1 Refactoring JDBC V2_1__Refactoring   axel 2016-02-10 17:45:05.4 251 true

And that's it! Every time the need to evolve the database arises, whether structure (DDL) or reference data (DML), simply create a new migration with a version number higher than the current one. The next time Flyway starts, it will find it and upgrade the database accordingly.

How Flyway works的更多相关文章

  1. 快速掌握Flyway

    什么是Flyway? Flyway is an open-source database migration tool. It strongly favors simplicity and conve ...

  2. 数据库版本管理工具Flyway(4.0.3)---工作机制(译文)

    How Flyway works The easiest scenario is when you point Flyway to an empty database. 最容易的方案是Flyway指向 ...

  3. 快速掌握和使用Flyway

    什么是Flyway? 转载:https://blog.waterstrong.me/flyway-in-practice/ Flyway is an open-source database migr ...

  4. Concepts-->Migrations

    https://flywaydb.org/documentation/migrations Overview With Flyway all changes to the database are c ...

  5. flywaydb and sql server

    https://flywaydb.org/documentation/database/sqlserver How Flyway works https://flywaydb.org/getstart ...

  6. Flyway Overview and Installation

    https://flywaydb.org/documentation/ Flyway is an open-source database migration tool. It strongly fa ...

  7. springboot web项目创建及自动配置分析(thymeleaf+flyway)

    @ 目录 源码分析 webjars thymeleaf thymeleaf语法 springmvc 启动配置原理 集成flyway插件 springboot 创建web项目只需要引入对应的web-st ...

  8. spring注解源码分析--how does autowired works?

    1. 背景 注解可以减少代码的开发量,spring提供了丰富的注解功能.我们可能会被问到,spring的注解到底是什么触发的呢?今天以spring最常使用的一个注解autowired来跟踪代码,进行d ...

  9. 生产环境中,数据库升级维护的最佳解决方案flyway

    官网:https://flywaydb.org/ 转载:http://casheen.iteye.com/blog/1749916 1.  引言 想到要管理数据库的版本,是在实际产品中遇到问题后想到的 ...

随机推荐

  1. C-Cow Sorting (置换群, 数学)

    Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the evening. Each cow has a uniqu ...

  2. 【转】 如何导入excel数据到数据库,并解决导入时间格式问题

    在办公环境下,经常会用到处理excel数据,如果用写程序导入excel数据到数据库那就太麻烦了,涉及解析excel,还要各种格式问题,下面简单利用数据库本身支持的功能解决这类导入问题. 准备 创建表 ...

  3. ReactiveObjC

    简介: RAC 指的就是 RactiveCocoa ,是 Github 的一个开源框架,能够帮我们提供大量方便的事件处理方案,让我们更简单粗暴地去处理事件,现在分为 ReactiveObjC 和 Re ...

  4. spring部分注解

    @Controller @SpringBootApplication @Configuration @ComponentScan(basePackages={"first",&qu ...

  5. 转:C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解

    转载自:http://www.cnblogs.com/easyfrog/p/3141269.html using System; using System.Collections.Generic; u ...

  6. seo网页加速技术,预加载 DNS Prefetching 详解

    seo网页加速技术,预加载 DNS Prefetching 详解 DNS Prefetching 是什么 : DNS 是什么-- Domain Name System,域名系统,作为域名和IP地址相互 ...

  7. js my_first

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. FAQ About WOYO PDR007 Dent Removal Heat Induction System

    WOYO PDR 007 is a dent repair tool for auto maintence. WOYO PDR007 Auto Body Paintless Dent Repair K ...

  9. 前端框架VUE----箭头函数

    箭头函数 基本语法: ES6允许使用“箭头”(=>)定义函数 var f = a = > a //等同于 var f = function(a){ return a; } 如果箭头函数不需 ...

  10. GoldenGate实时投递数据到大数据平台(2)- Cassandra

    简介 GoldenGate是一款可以实时投递数据到大数据平台的软件,针对apache cassandra,经过简单配置,即可实现从关系型数据将增量数据实时投递到Cassandra,以下介绍配置过程. ...