Slide 1

Slide 1 text

Automate Database Migration using Flyway framework Karthickeyan Narasimhan | @hellokarthic Product Developer, Freshworks

Slide 2

Slide 2 text

DISCLAIMER The views expressed during and with respect to this presentation are those of the presenter and do not necessarily reflect the views of the company, Freshworks. The logos or service names (collectively, "Trademarks") used in the presentation are for the purposes of identifying the relevant service providers. Freshworks does not claim any right or ownership over such Trademarks. The images used in the presentation are for illustrative purposes only. For any questions pertaining to the presentation's use, distribution or publication, please write to the presenter. All rights reserved by Freshworks Inc.

Slide 3

Slide 3 text

About Me ● Product Developer at Freshworks Technologies Private Limited. ● Over 2+ years of Experience in Web Development ● FOSS Enthusiast ● Mozilla Rep(India) & Tech Speaker ● Mozilla Campus Advisory Committee Board Member

Slide 4

Slide 4 text

● A Tale of Manual DB Migration ● What are the ways to solve the DB Migration problem ● How flyway came to our rescue ● Live Demo on applying flyway to your project ● Challenges we faced while using Flyway ● Q&A, Resource sharing Overview

Slide 5

Slide 5 text

A Tale of Manual DB Migration

Slide 6

Slide 6 text

Ways to solve?

Slide 7

Slide 7 text

Come let’s fly with Flyway! Supports Plain SQL / Java based migrations 6 major commands- Info, Migrate, Repair, Clean, Baseline & Validate Multiple & Simple Setup - Supports Gradle, Maven, ANT, etc Flyway is an Open source tool for managing Database migration -KISS Approach Conventions over Configuration

Slide 8

Slide 8 text

● Usually contains DDL statements ● Or reference data, data fixes. ○ Did we change the country code(or currency) table on this machine? ● Use JDBC code for complex migration ○ Not checksummed by default unlike SQL migrations. What’s in a Migration?

Slide 9

Slide 9 text

build.gradle

Slide 10

Slide 10 text

Naming Conventions

Slide 11

Slide 11 text

Let’s see in Action Image Source: www.giphy.com

Slide 12

Slide 12 text

How you did that? ● Working with maintenance branches ● Working with feature branches ● Working with lots of migrations

Slide 13

Slide 13 text

Use Case 3 Use Case 1 Use Case 2 Use Case 3 Problem: Working with maintenance branches

Slide 14

Slide 14 text

● DB prod schema evolves linearly ● Ensure maintenance migrations happen before migrations belonging to later release ● use major.minor version scheme for maintenance ○ V1.1 comes after V1 but before V2 ○ In practice V001_01__increase_comment_size.sql Use Case 3 Solution: Working with maintenance branches Use Case 1 Use Case 2 Use Case 3

Slide 15

Slide 15 text

Use Case 3 Use Case 3 Use Case 1 Use Case 2 Use Case 3 Problem: Working with feature branches

Slide 16

Slide 16 text

Use Case 3 Use Case 1 Use Case 2 Use Case 3 Solution: Working with feature branches V2018_01_01_2330__Add_newTable.sql

Slide 17

Slide 17 text

Use Case 3 Use Case 1 Use Case 2 Use Case 3 Solution: Working with feature branches

Slide 18

Slide 18 text

Use Case 3 Use Case 1 Use Case 2 Use Case 3 Problem: Working with lot of migrations Image Source: www.images.google.com

Slide 19

Slide 19 text

● Squashing migrations ● Squash all applied migration files into one or two files ○ DDL+Reference data ● Use baseline gradle flywaybaseline -Dflyway.baselineVersion= Use Case 3 Use Case 1 Use Case 2 Use Case 3 Solution: Working with lot of migrations

Slide 20

Slide 20 text

What are you waiting for?

Slide 21

Slide 21 text

How to Contribute? https://stackoverflow.com/questions/tagged/flyway https://flywaydb.org/documentation/contribute/website/ https://flywaydb.org/documentation/contribute/code/

Slide 22

Slide 22 text

https://tinyurl.com/DevDayDaNang Resources

Slide 23

Slide 23 text

Image Source: From the movie “A Serious Man”

Slide 24

Slide 24 text

Karthickeyan Narasimhan Product Developer, Freshworks www.facebook.com/hellokarthic @hellokarthic https://www.linkedin.com/in/hellokarthic/ [email protected]