SlideShare a Scribd company logo
By Girish Bapat
Need of database
migration
How Flyway works
Different ways to use
flyway
Demo
• Java API
•Command line
• Maven
• Ant
Need of Database migration
Initial setup
Database
Application
Need of Database migration
Database
Application
Development
setup
Database
Application
QA setup
Database
Application
Integration setup
Database
Application
Production setup
Different environments
Real world scenario
Comparison between source code
and database
Source code
•Version control tools are
available
•Maven, Jenkins, Hudson
reproducible builds and
continuous integration
•Maven release plug-ins for
tagging and for newer versions
Database
•Manually applying
database scripts
•What is current state of
database?
•Which scripts are applied?
•If quick fix is applied on
production after dev
machine?
•How to setup new DB
instance?
Solution is Database migrations
 Allows to recreate a database
from scratch / update from
any previously migrated state
 Make it clear at all times
what state a database is in
 Migrate in a deterministic
way from your current
version of the database to a
newer one
Flyway
Application
EMPTY Database
Flyway will try to find out metadata table. As the Database is empty it does not
find the same.
How Flyway works
How Flyway works
SCHEMA_VERSION
Flyway first creates single empty table
SCHEMA_VERSION by default:
This table will be used for tracking state of
database.
Once SCHEMA_VERSION is created,
Flyway will start scanning classpath for
migrations.
Migrations are sorted based on version
number and applied in order
How Flyway works
SCHEMA_VERSIONSCHEMA_VERSION
Empty
Database
Version 1
SCHEMA_VERSION
Version 2
 API- Flyway can be configured directly into application.
Flyway checks database version and before actual
application starts, applies newer migrations
 Command-line tool- CLI is for users:
 Who wish to migration their database from the command-
line without having to install Maven or Ant
 Flyway comes with plugin for
 Maven
 Gradle Plugin
 SBT
 ANT- Ant Tasks are provided as an AntLib
Different ways to use flyway
Demo- Prerequisites & Setup-API
Prerequisites: Java 5+, Maven 2 or 3
Create project
mvn archetype:generate -B -DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.1
-DgroupId=foo -DartifactId=bar -Dversion=1.0-SNAPSHOT -Dpackage=foobar
Adding the dependencies
<project ...> ...
<dependencies>
<dependency>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.170</version>
</dependency> ...
</dependencies>
... </project>
Demo- Integrating flyway- API
Create App.java in src/main/java/foobar
Demo- first migration- API
First migration:
Migration directory: src/main/resources/db/migration
First migration: src/main/resources/db/migration/V1__Create_person_table.sql
Create table PERSON (
ID int not null,
NAME varchar (100) not null
);
Executing our program
bar> mvn package exec:java -Dexec.mainClass=foobar.App
Check the output
INFO: Creating Metadata table: "PUBLIC"."schema_version"
INFO: Current version of schema "PUBLIC": << Empty Schema >>
INFO: Migrating schema "PUBLIC" to version 1
INFO: Successfully applied 1 migration to schema "PUBLIC"
(execution time 00:00.062s).
Demo- Second migration- API
Second migration:
src/main/resources/db/migration/V2__Add_people.sql
insert into PERSON (ID, NAME) values (1, 'Axel');
insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
insert into PERSON (ID, NAME) values (3, 'Ms. Bar');
Executing our program
bar> mvn package exec:java -Dexec.mainClass=foobar.App
Check the output:
INFO: Current version of schema "PUBLIC": 1
INFO: Migrating schema "PUBLIC" to version 2
INFO: Successfully applied 1 migration to schema "PUBLIC"
(execution time 00:00.090s).
Demo- Integrating flyway- API
Create ExistingDB.java in src/main/java/foobar
Demo- migrations Existing database
Existing database:
Migration directory: src/main/resources/db/migration
migrations: src/main/resources/db/migration/V1__Base_version.sql
Check the output:
INFO: Schema "PUBLIC" is up to date. No migration necessary.
production status:
State: SUCCESS version:1
INFO: Creating Metadata table: "PUBLIC"."schema_version“
INFO: Current version of schema "PUBLIC": << Empty Schema >>
INFO: Migrating schema "PUBLIC" to version 1.0
INFO: Successfully applied 1 migration to schema "PUBLIC“
Sells status:
State: SUCCESS version:1.0
Executing our program
bar> mvn package exec:java -Dexec.mainClass=foobar.ExistingDB
We have production db, we need to replicate database on other databases
Generate a sql script that includes the entire DDL (including indexes, triggers, procedures, ...) of the
production database.
Add all insert scripts of data available on production.
This script will form your base migration.
Demo- Prerequisites & Setup- CLI
Prerequisites: Java 5+
Download flyway command line distribution
http://repo1.maven.org/maven2/com/googlecode/flyway/flyway-
commandline/2.3/flyway-commandline-2.3.zip
Download H2 jars
http://repo1.maven.org/maven2/com/h2database/h2/1.3.170/
h2-1.3.170.jar
Setup
Create flyway-commandline-2.3 and required directories
Extract flyway-commandline-2.3.zip. It will create necessary structure
Configuring Flyway
Edit conf/flyway.properties
flyway.url= jdbc:h2:file:///E:/PROJECTS/flywaydb/flyway-2.3/commandLineDB
flyway.user=SA
Demo- first migration- CLI
First migration: sql/V1__Create_person_table.sql
Create table PERSON (
ID int not null,
NAME varchar (100) not null
);
Executing our program
flyway-2.3> flyway migrate
Check the output
Flyway (Command-line Tool) v.2.3
Creating Metadata table: "PUBLIC"."schema_version"
Current version of schema "PUBLIC": << Empty Schema >>
Migrating schema "PUBLIC" to version 1
Successfully applied 1 migration to schema "PUBLIC" (execution
time 00:00.194s).
Demo- Second migration- CLI
Second migration:
sql/V2__Add_people.sql
insert into PERSON (ID, NAME) values (1, 'Axel');
insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
insert into PERSON (ID, NAME) values (3, 'Ms. Bar');
Executing our program
flyway-2.3> flyway migrate
Check the output:
Flyway (Command-line Tool) v.2.3
Current version of schema "PUBLIC": 1
Migrating schema "PUBLIC" to version 2
Successfully applied 1 migration to schema "PUBLIC"
(execution time 00:00.126s).
Demo- Prerequisites & Setup- Maven
We will use the project as earlier created just change the pom.xml
Adding the dependencies
<project ...> ...
<build>
<plugins><plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-
plugin</artifactId> <version>2.3</version>
<configuration>
<url>jdbc:h2:file:///E:/PROJECTS/flywaydb/f
lyway-maven/database/mavenDB</url>
<user>sa</user>
</configuration>
<dependencies> <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.170</version>
</dependency> </dependencies>
</plugin> </plugins>
</build>
Demo- first migration- Maven
First migration:
Migration directory: src/main/resources/db/migration
First migration: src/main/resources/db/migration/V1__Create_person_table.sql
Create table PERSON (
ID int not null,
NAME varchar (100) not null
);
Executing our program
bar> mvn compile flyway:migrate
Check the output
[INFO] Creating Metadata table: "PUBLIC"."schema_version"
[INFO] Current version of schema "PUBLIC": << Empty Schema >>
[INFO] Migrating schema "PUBLIC" to version 1
[INFO] Successfully applied 1 migration to schema "PUBLIC"
(execution time 00:00
.171s).
Demo- Second migration- Maven
Second migration:
src/main/resources/db/migration/V2__Add_people.sql
insert into PERSON (ID, NAME) values (1, 'Axel');
insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
insert into PERSON (ID, NAME) values (3, 'Ms. Bar');
Executing our program
bar> mvn compile flyway:migrate
Check the output:
[INFO] --- flyway-maven-plugin:2.3:migrate (default-cli) @ bar
---
[INFO] Current version of schema "PUBLIC": 1
[INFO] Migrating schema "PUBLIC" to version 2
[INFO] Successfully applied 1 migration to schema "PUBLIC"
(execution time 00:00
.075s).
Demo- Prerequisites & Setup- ANT
Prerequisites: Java 5+, A working Ant install
Create directories
# mkdir flyway-antlibs flyway-antmigrations
Download ant distribution and H2 jars
http://repo1.maven.org/maven2/com/googlecode/flyway/flyway-
ant/2.3/flyway-ant-2.3.zip
Create build.xml as below
<project name="foobar" default="migrate-db”
xmlns:flyway="antlib:com.googlecode.flyway.ant">
<target name="migrate-db“> <taskdef
uri="antlib:com.googlecode.flyway.ant"
resource="com/googlecode/flyway/ant/antlib.xml">
<classpath>
<pathelement location="libs/flyway-core-2.3.jar" />
<pathelement location="libs/flyway-ant-2.3.jar" />
</classpath>
</taskdef>
<path id="flyway.classpath">
<fileset dir="./libs" includes="h2-1.3.170.jar" />
</path>
<property name="flyway.locations" value="filesystem:./migrations" />
<flyway:migrate url="jdbc:h2:file:///E:/PROJECTS/flywaydb/flyway-
ant/database/antDB" user="SA" />
</target>
</project>
Demo- first migration- ANT
First migration:
Migration directory: migration
First migration: migration/V1__Create_person_table.sql
Create table PERSON (
ID int not null,
NAME varchar (100) not null
);
Executing our program
flyway-ant > ant
Check the output
[flyway:migrate] Creating Metadata table:
"PUBLIC"."schema_version"
[flyway:migrate] Current version of schema "PUBLIC": << Empty
Schema >>
[flyway:migrate] Migrating schema "PUBLIC" to version 1
[flyway:migrate] Successfully applied 1 migration to schema
"PUBLIC" (execution
time 00:00.161s).
Demo- Second migration- ANT
Second migration:
migration/V2__Add_people.sql
insert into PERSON (ID, NAME) values (1, 'Axel');
insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
insert into PERSON (ID, NAME) values (3, 'Ms. Bar');
Executing our program
flyway-ant > ant
Check the output:
[flyway:migrate] Current version of schema "PUBLIC": 1
[flyway:migrate] Migrating schema "PUBLIC" to version 2
[flyway:migrate] Successfully applied 1 migration to schema
"PUBLIC" (execution
time 00:00.085s).
Questions & Answers
Contact me
Twitter:
@girishbapat
Email:
girish.bapat@gmail.com
Slideshare:
http://www.slideshare.net/girishbapat/getting-started-with-
agile-database-migrations-for-java-flywaydb

More Related Content

What's hot

Come Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayCome Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with Flyway
Joris Kuipers
 
Breaking the Monolith
Breaking the MonolithBreaking the Monolith
Breaking the Monolith
VMware Tanzu
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
Kashif Ali Siddiqui
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
rajdeep
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and Beyond
VMware Tanzu
 
MSA ( Microservices Architecture ) 발표 자료 다운로드
MSA ( Microservices Architecture ) 발표 자료 다운로드MSA ( Microservices Architecture ) 발표 자료 다운로드
MSA ( Microservices Architecture ) 발표 자료 다운로드
Opennaru, inc.
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
NAVER CLOUD PLATFORMㅣ네이버 클라우드 플랫폼
 
Service discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudService discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring Cloud
Marcelo Serpa
 
Locking down your Kubernetes cluster with Linkerd
Locking down your Kubernetes cluster with LinkerdLocking down your Kubernetes cluster with Linkerd
Locking down your Kubernetes cluster with Linkerd
Buoyant
 
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
Open Source Consulting
 
VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모
VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모
VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모
Opennaru, inc.
 
Introduction to Version Control
Introduction to Version ControlIntroduction to Version Control
Introduction to Version Control
Jeremy Coates
 
쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.
쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.
쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.
Open Source Consulting
 
Gitlab, GitOps & ArgoCD
Gitlab, GitOps & ArgoCDGitlab, GitOps & ArgoCD
Gitlab, GitOps & ArgoCD
Haggai Philip Zagury
 
Kubernetes in Docker
Kubernetes in DockerKubernetes in Docker
Kubernetes in Docker
Docker, Inc.
 
Introduction To Liquibase
Introduction To Liquibase Introduction To Liquibase
Introduction To Liquibase
Knoldus Inc.
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
Ajeet Singh Raina
 

What's hot (20)

Come Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayCome Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with Flyway
 
Breaking the Monolith
Breaking the MonolithBreaking the Monolith
Breaking the Monolith
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and Beyond
 
MSA ( Microservices Architecture ) 발표 자료 다운로드
MSA ( Microservices Architecture ) 발표 자료 다운로드MSA ( Microservices Architecture ) 발표 자료 다운로드
MSA ( Microservices Architecture ) 발표 자료 다운로드
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
 
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
멀티·하이브리드 클라우드 구축 전략 - 네이버비즈니스플랫폼 박기은 CTO
 
Service discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudService discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring Cloud
 
Locking down your Kubernetes cluster with Linkerd
Locking down your Kubernetes cluster with LinkerdLocking down your Kubernetes cluster with Linkerd
Locking down your Kubernetes cluster with Linkerd
 
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)[오픈소스컨설팅] 서비스 메쉬(Service mesh)
[오픈소스컨설팅] 서비스 메쉬(Service mesh)
 
VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모
VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모
VM과 컨테이너 상에서 Apache & Tomcat 설치, 실행 그리고 배포 데모
 
Introduction to Version Control
Introduction to Version ControlIntroduction to Version Control
Introduction to Version Control
 
쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.
쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.
쿠버네티스 기반 PaaS 솔루션 - Playce Kube를 소개합니다.
 
Gitlab, GitOps & ArgoCD
Gitlab, GitOps & ArgoCDGitlab, GitOps & ArgoCD
Gitlab, GitOps & ArgoCD
 
Kubernetes in Docker
Kubernetes in DockerKubernetes in Docker
Kubernetes in Docker
 
Introduction To Liquibase
Introduction To Liquibase Introduction To Liquibase
Introduction To Liquibase
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
 

Viewers also liked

Liquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOpsLiquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der DatenbankmigrationstoolsJavaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Stephan Kaps
 
Continuous DB Changes Delivery With Liquibase
Continuous DB Changes Delivery With LiquibaseContinuous DB Changes Delivery With Liquibase
Continuous DB Changes Delivery With Liquibase
Aidas Dragūnas
 
Evoluindo bancos de dados com Flyway
Evoluindo bancos de dados com FlywayEvoluindo bancos de dados com Flyway
Evoluindo bancos de dados com Flyway
Vitor Albuquerque
 
Introdução ao Flyway
Introdução ao FlywayIntrodução ao Flyway
Introdução ao Flyway
Jadson Santos
 
Liquibase
LiquibaseLiquibase
Liquibase
Sergii Fesenko
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and Liquibase
Dan Stine
 
Liquibase få kontroll på dina databasförändringar
Liquibase   få kontroll på dina databasförändringarLiquibase   få kontroll på dina databasförändringar
Liquibase få kontroll på dina databasförändringar
Squeed
 
Flyway - database migrations made easy
Flyway - database migrations made easyFlyway - database migrations made easy
Flyway - database migrations made easy
jstack
 
Mini Training Flyway
Mini Training FlywayMini Training Flyway
Mini Training Flyway
Betclic Everest Group Tech Team
 
Architecting for continuous delivery (33rd Degree)
Architecting for continuous delivery (33rd Degree)Architecting for continuous delivery (33rd Degree)
Architecting for continuous delivery (33rd Degree)
Axel Fontaine
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
Ankita Mahajan
 
Flyway (33rd Degree)
Flyway (33rd Degree)Flyway (33rd Degree)
Flyway (33rd Degree)
Axel Fontaine
 
2016 10-26 docker meetup - kubernetes on open stack
2016 10-26 docker meetup - kubernetes on open stack2016 10-26 docker meetup - kubernetes on open stack
2016 10-26 docker meetup - kubernetes on open stack
Amrita Prasad
 
Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With Liquibase
IASA
 
Docker with OpenStack
Docker with OpenStack Docker with OpenStack
Docker with OpenStack
chmouel
 
Liquibase migration for data bases
Liquibase migration for data basesLiquibase migration for data bases
Liquibase migration for data bases
Roman Uholnikov
 
Self Heal Your OpenStack Control Plane!
Self Heal Your OpenStack Control Plane!Self Heal Your OpenStack Control Plane!
Self Heal Your OpenStack Control Plane!
Shixiong Shang
 
Deploying and managing container-based applications with OpenStack and Kubern...
Deploying and managing container-based applications with OpenStack and Kubern...Deploying and managing container-based applications with OpenStack and Kubern...
Deploying and managing container-based applications with OpenStack and Kubern...
Ihor Dvoretskyi
 
Liquibase
LiquibaseLiquibase
Liquibase
Roman Uholnikov
 

Viewers also liked (20)

Liquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOpsLiquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOps
 
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der DatenbankmigrationstoolsJavaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
 
Continuous DB Changes Delivery With Liquibase
Continuous DB Changes Delivery With LiquibaseContinuous DB Changes Delivery With Liquibase
Continuous DB Changes Delivery With Liquibase
 
Evoluindo bancos de dados com Flyway
Evoluindo bancos de dados com FlywayEvoluindo bancos de dados com Flyway
Evoluindo bancos de dados com Flyway
 
Introdução ao Flyway
Introdução ao FlywayIntrodução ao Flyway
Introdução ao Flyway
 
Liquibase
LiquibaseLiquibase
Liquibase
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and Liquibase
 
Liquibase få kontroll på dina databasförändringar
Liquibase   få kontroll på dina databasförändringarLiquibase   få kontroll på dina databasförändringar
Liquibase få kontroll på dina databasförändringar
 
Flyway - database migrations made easy
Flyway - database migrations made easyFlyway - database migrations made easy
Flyway - database migrations made easy
 
Mini Training Flyway
Mini Training FlywayMini Training Flyway
Mini Training Flyway
 
Architecting for continuous delivery (33rd Degree)
Architecting for continuous delivery (33rd Degree)Architecting for continuous delivery (33rd Degree)
Architecting for continuous delivery (33rd Degree)
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
Flyway (33rd Degree)
Flyway (33rd Degree)Flyway (33rd Degree)
Flyway (33rd Degree)
 
2016 10-26 docker meetup - kubernetes on open stack
2016 10-26 docker meetup - kubernetes on open stack2016 10-26 docker meetup - kubernetes on open stack
2016 10-26 docker meetup - kubernetes on open stack
 
Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With Liquibase
 
Docker with OpenStack
Docker with OpenStack Docker with OpenStack
Docker with OpenStack
 
Liquibase migration for data bases
Liquibase migration for data basesLiquibase migration for data bases
Liquibase migration for data bases
 
Self Heal Your OpenStack Control Plane!
Self Heal Your OpenStack Control Plane!Self Heal Your OpenStack Control Plane!
Self Heal Your OpenStack Control Plane!
 
Deploying and managing container-based applications with OpenStack and Kubern...
Deploying and managing container-based applications with OpenStack and Kubern...Deploying and managing container-based applications with OpenStack and Kubern...
Deploying and managing container-based applications with OpenStack and Kubern...
 
Liquibase
LiquibaseLiquibase
Liquibase
 

Similar to Getting started with agile database migrations for java flywaydb

Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Alan Pinstein
 
Devopstore
DevopstoreDevopstore
Devopstore
Farkhad Badalov
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
Ian Barber
 
Omaha (Google Update) server
Omaha (Google Update) serverOmaha (Google Update) server
Omaha (Google Update) server
Dmitry Lyfar
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
Ivelina Dimova
 
Maven
MavenMaven
Maven
feng lee
 
Native Hadoop with prebuilt spark
Native Hadoop with prebuilt sparkNative Hadoop with prebuilt spark
Native Hadoop with prebuilt spark
arunkumar sadhasivam
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
Amazon Web Services
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
Jesse Gallagher
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Fabrice Bernhard
 
Migration Station at SAS - DevOps for Fusion with Version Control and Continu...
Migration Station at SAS - DevOps for Fusion with Version Control and Continu...Migration Station at SAS - DevOps for Fusion with Version Control and Continu...
Migration Station at SAS - DevOps for Fusion with Version Control and Continu...
Lucidworks
 
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.DrupalCampDN
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
Deployer - Deployment tool for PHP
Deployer - Deployment tool for PHPDeployer - Deployment tool for PHP
Deployer - Deployment tool for PHP
hernanibf
 
Riga Dev Day - Automated Android Continuous Integration
Riga Dev Day - Automated Android Continuous IntegrationRiga Dev Day - Automated Android Continuous Integration
Riga Dev Day - Automated Android Continuous Integration
Nicolas Fränkel
 
FlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootFlywayDB Migration with Spring Boot
FlywayDB Migration with Spring Boot
Inexture Solutions
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command line
Behzod Saidov
 
Azure DevOps Deployment Group
Azure DevOps Deployment GroupAzure DevOps Deployment Group
Azure DevOps Deployment Group
Riwut Libinuko
 

Similar to Getting started with agile database migrations for java flywaydb (20)

Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
 
Devopstore
DevopstoreDevopstore
Devopstore
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
Omaha (Google Update) server
Omaha (Google Update) serverOmaha (Google Update) server
Omaha (Google Update) server
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
 
Maven
MavenMaven
Maven
 
Native Hadoop with prebuilt spark
Native Hadoop with prebuilt sparkNative Hadoop with prebuilt spark
Native Hadoop with prebuilt spark
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Migration Station at SAS - DevOps for Fusion with Version Control and Continu...
Migration Station at SAS - DevOps for Fusion with Version Control and Continu...Migration Station at SAS - DevOps for Fusion with Version Control and Continu...
Migration Station at SAS - DevOps for Fusion with Version Control and Continu...
 
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Deployer - Deployment tool for PHP
Deployer - Deployment tool for PHPDeployer - Deployment tool for PHP
Deployer - Deployment tool for PHP
 
Riga Dev Day - Automated Android Continuous Integration
Riga Dev Day - Automated Android Continuous IntegrationRiga Dev Day - Automated Android Continuous Integration
Riga Dev Day - Automated Android Continuous Integration
 
FlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootFlywayDB Migration with Spring Boot
FlywayDB Migration with Spring Boot
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command line
 
Azure DevOps Deployment Group
Azure DevOps Deployment GroupAzure DevOps Deployment Group
Azure DevOps Deployment Group
 

Recently uploaded

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

Getting started with agile database migrations for java flywaydb

  • 2. Need of database migration How Flyway works Different ways to use flyway Demo • Java API •Command line • Maven • Ant
  • 3. Need of Database migration Initial setup Database Application
  • 4. Need of Database migration Database Application Development setup Database Application QA setup Database Application Integration setup Database Application Production setup Different environments Real world scenario
  • 5. Comparison between source code and database Source code •Version control tools are available •Maven, Jenkins, Hudson reproducible builds and continuous integration •Maven release plug-ins for tagging and for newer versions Database •Manually applying database scripts •What is current state of database? •Which scripts are applied? •If quick fix is applied on production after dev machine? •How to setup new DB instance?
  • 6. Solution is Database migrations  Allows to recreate a database from scratch / update from any previously migrated state  Make it clear at all times what state a database is in  Migrate in a deterministic way from your current version of the database to a newer one
  • 7. Flyway Application EMPTY Database Flyway will try to find out metadata table. As the Database is empty it does not find the same. How Flyway works
  • 8. How Flyway works SCHEMA_VERSION Flyway first creates single empty table SCHEMA_VERSION by default: This table will be used for tracking state of database. Once SCHEMA_VERSION is created, Flyway will start scanning classpath for migrations. Migrations are sorted based on version number and applied in order
  • 10.  API- Flyway can be configured directly into application. Flyway checks database version and before actual application starts, applies newer migrations  Command-line tool- CLI is for users:  Who wish to migration their database from the command- line without having to install Maven or Ant  Flyway comes with plugin for  Maven  Gradle Plugin  SBT  ANT- Ant Tasks are provided as an AntLib Different ways to use flyway
  • 11. Demo- Prerequisites & Setup-API Prerequisites: Java 5+, Maven 2 or 3 Create project mvn archetype:generate -B -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.1 -DgroupId=foo -DartifactId=bar -Dversion=1.0-SNAPSHOT -Dpackage=foobar Adding the dependencies <project ...> ... <dependencies> <dependency> <groupId>com.googlecode.flyway</groupId> <artifactId>flyway-core</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.170</version> </dependency> ... </dependencies> ... </project>
  • 12. Demo- Integrating flyway- API Create App.java in src/main/java/foobar
  • 13. Demo- first migration- API First migration: Migration directory: src/main/resources/db/migration First migration: src/main/resources/db/migration/V1__Create_person_table.sql Create table PERSON ( ID int not null, NAME varchar (100) not null ); Executing our program bar> mvn package exec:java -Dexec.mainClass=foobar.App Check the output INFO: Creating Metadata table: "PUBLIC"."schema_version" INFO: Current version of schema "PUBLIC": << Empty Schema >> INFO: Migrating schema "PUBLIC" to version 1 INFO: Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.062s).
  • 14. Demo- Second migration- API Second migration: src/main/resources/db/migration/V2__Add_people.sql insert into PERSON (ID, NAME) values (1, 'Axel'); insert into PERSON (ID, NAME) values (2, 'Mr. Foo'); insert into PERSON (ID, NAME) values (3, 'Ms. Bar'); Executing our program bar> mvn package exec:java -Dexec.mainClass=foobar.App Check the output: INFO: Current version of schema "PUBLIC": 1 INFO: Migrating schema "PUBLIC" to version 2 INFO: Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.090s).
  • 15. Demo- Integrating flyway- API Create ExistingDB.java in src/main/java/foobar
  • 16. Demo- migrations Existing database Existing database: Migration directory: src/main/resources/db/migration migrations: src/main/resources/db/migration/V1__Base_version.sql Check the output: INFO: Schema "PUBLIC" is up to date. No migration necessary. production status: State: SUCCESS version:1 INFO: Creating Metadata table: "PUBLIC"."schema_version“ INFO: Current version of schema "PUBLIC": << Empty Schema >> INFO: Migrating schema "PUBLIC" to version 1.0 INFO: Successfully applied 1 migration to schema "PUBLIC“ Sells status: State: SUCCESS version:1.0 Executing our program bar> mvn package exec:java -Dexec.mainClass=foobar.ExistingDB We have production db, we need to replicate database on other databases Generate a sql script that includes the entire DDL (including indexes, triggers, procedures, ...) of the production database. Add all insert scripts of data available on production. This script will form your base migration.
  • 17. Demo- Prerequisites & Setup- CLI Prerequisites: Java 5+ Download flyway command line distribution http://repo1.maven.org/maven2/com/googlecode/flyway/flyway- commandline/2.3/flyway-commandline-2.3.zip Download H2 jars http://repo1.maven.org/maven2/com/h2database/h2/1.3.170/ h2-1.3.170.jar Setup Create flyway-commandline-2.3 and required directories Extract flyway-commandline-2.3.zip. It will create necessary structure Configuring Flyway Edit conf/flyway.properties flyway.url= jdbc:h2:file:///E:/PROJECTS/flywaydb/flyway-2.3/commandLineDB flyway.user=SA
  • 18. Demo- first migration- CLI First migration: sql/V1__Create_person_table.sql Create table PERSON ( ID int not null, NAME varchar (100) not null ); Executing our program flyway-2.3> flyway migrate Check the output Flyway (Command-line Tool) v.2.3 Creating Metadata table: "PUBLIC"."schema_version" Current version of schema "PUBLIC": << Empty Schema >> Migrating schema "PUBLIC" to version 1 Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.194s).
  • 19. Demo- Second migration- CLI Second migration: sql/V2__Add_people.sql insert into PERSON (ID, NAME) values (1, 'Axel'); insert into PERSON (ID, NAME) values (2, 'Mr. Foo'); insert into PERSON (ID, NAME) values (3, 'Ms. Bar'); Executing our program flyway-2.3> flyway migrate Check the output: Flyway (Command-line Tool) v.2.3 Current version of schema "PUBLIC": 1 Migrating schema "PUBLIC" to version 2 Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.126s).
  • 20. Demo- Prerequisites & Setup- Maven We will use the project as earlier created just change the pom.xml Adding the dependencies <project ...> ... <build> <plugins><plugin> <groupId>com.googlecode.flyway</groupId> <artifactId>flyway-maven- plugin</artifactId> <version>2.3</version> <configuration> <url>jdbc:h2:file:///E:/PROJECTS/flywaydb/f lyway-maven/database/mavenDB</url> <user>sa</user> </configuration> <dependencies> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.170</version> </dependency> </dependencies> </plugin> </plugins> </build>
  • 21. Demo- first migration- Maven First migration: Migration directory: src/main/resources/db/migration First migration: src/main/resources/db/migration/V1__Create_person_table.sql Create table PERSON ( ID int not null, NAME varchar (100) not null ); Executing our program bar> mvn compile flyway:migrate Check the output [INFO] Creating Metadata table: "PUBLIC"."schema_version" [INFO] Current version of schema "PUBLIC": << Empty Schema >> [INFO] Migrating schema "PUBLIC" to version 1 [INFO] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00 .171s).
  • 22. Demo- Second migration- Maven Second migration: src/main/resources/db/migration/V2__Add_people.sql insert into PERSON (ID, NAME) values (1, 'Axel'); insert into PERSON (ID, NAME) values (2, 'Mr. Foo'); insert into PERSON (ID, NAME) values (3, 'Ms. Bar'); Executing our program bar> mvn compile flyway:migrate Check the output: [INFO] --- flyway-maven-plugin:2.3:migrate (default-cli) @ bar --- [INFO] Current version of schema "PUBLIC": 1 [INFO] Migrating schema "PUBLIC" to version 2 [INFO] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00 .075s).
  • 23. Demo- Prerequisites & Setup- ANT Prerequisites: Java 5+, A working Ant install Create directories # mkdir flyway-antlibs flyway-antmigrations Download ant distribution and H2 jars http://repo1.maven.org/maven2/com/googlecode/flyway/flyway- ant/2.3/flyway-ant-2.3.zip Create build.xml as below <project name="foobar" default="migrate-db” xmlns:flyway="antlib:com.googlecode.flyway.ant"> <target name="migrate-db“> <taskdef uri="antlib:com.googlecode.flyway.ant" resource="com/googlecode/flyway/ant/antlib.xml"> <classpath> <pathelement location="libs/flyway-core-2.3.jar" /> <pathelement location="libs/flyway-ant-2.3.jar" /> </classpath> </taskdef> <path id="flyway.classpath"> <fileset dir="./libs" includes="h2-1.3.170.jar" /> </path> <property name="flyway.locations" value="filesystem:./migrations" /> <flyway:migrate url="jdbc:h2:file:///E:/PROJECTS/flywaydb/flyway- ant/database/antDB" user="SA" /> </target> </project>
  • 24. Demo- first migration- ANT First migration: Migration directory: migration First migration: migration/V1__Create_person_table.sql Create table PERSON ( ID int not null, NAME varchar (100) not null ); Executing our program flyway-ant > ant Check the output [flyway:migrate] Creating Metadata table: "PUBLIC"."schema_version" [flyway:migrate] Current version of schema "PUBLIC": << Empty Schema >> [flyway:migrate] Migrating schema "PUBLIC" to version 1 [flyway:migrate] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.161s).
  • 25. Demo- Second migration- ANT Second migration: migration/V2__Add_people.sql insert into PERSON (ID, NAME) values (1, 'Axel'); insert into PERSON (ID, NAME) values (2, 'Mr. Foo'); insert into PERSON (ID, NAME) values (3, 'Ms. Bar'); Executing our program flyway-ant > ant Check the output: [flyway:migrate] Current version of schema "PUBLIC": 1 [flyway:migrate] Migrating schema "PUBLIC" to version 2 [flyway:migrate] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.085s).
  • 27.

Editor's Notes

  1. package foobar;import com.googlecode.flyway.core.Flyway; public class App { public static void main(String[] args) { // Create the Flyway instanceFlyway flyway = new Flyway(); // Point it to the database flyway.setDataSource(&quot;jdbc:h2:file:target/foobar&quot;, &quot;sa&quot;, null); // Start the migration flyway.migrate(); } }
  2. package foobar;import com.googlecode.flyway.core.Flyway;import com.googlecode.flyway.core.api.MigrationInfo;public class ExistingDB { public static void main(String[] args) { // Create the Flyway instance Flyway flyway = new Flyway();flyway.setInitVersion(&quot;1.0&quot;);flyway.setInitDescription(&quot;Base Version&quot;);flyway.setInitOnMigrate(true); // Point it to the databaseflyway.setDataSource(&quot;jdbc:h2:file:///E:/PROJECTS/flywaydb/flyway-api/database/existingProductionDB&quot;, &quot;sa&quot;, null); // Start the migrationflyway.migrate();MigrationInfo[] existingProdInfos=flyway.info().all();System.out.println(&quot;production status: &quot;); for (inti = 0; i &lt; existingProdInfos.length; i++) {MigrationInfomigrationInfo = existingProdInfos[i];System.out.println(&quot;State: &quot;+migrationInfo.getState()+&quot; version:&quot;+migrationInfo.getVersion()); } // Point it to the databaseflyway.setDataSource(&quot;jdbc:h2:file:///E:/PROJECTS/flywaydb/flyway-api/database/SellsDB&quot;, &quot;sa&quot;, null); // Start the migrationflyway.migrate();MigrationInfo[] existingSellsInfos=flyway.info().all();System.out.println(&quot;Sells status: &quot;); for (inti = 0; i &lt; existingSellsInfos.length; i++) {MigrationInfomigrationInfo = existingSellsInfos[i];System.out.println(&quot;State: &quot;+migrationInfo.getState()+&quot; version:&quot;+migrationInfo.getVersion()); } }}
  3. http://stackoverflow.com/questions/9533794/flyway-interest-of-creating-a-sql-init-file