SlideShare une entreprise Scribd logo
1  sur  28
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

Contenu connexe

Tendances

Flyway _ A Database Version Management Tool
Flyway _ A Database Version Management ToolFlyway _ A Database Version Management Tool
Flyway _ A Database Version Management ToolKnoldus Inc.
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11 Knoldus Inc.
 
Salesforce DevOps using GitHub Action
Salesforce DevOps using GitHub ActionSalesforce DevOps using GitHub Action
Salesforce DevOps using GitHub ActionSakthivel Madesh
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!Maarten Smeets
 
Introduction to .NET Core
Introduction to .NET CoreIntroduction to .NET Core
Introduction to .NET CoreMarco Parenzan
 
Top frontend web development tools
Top frontend web development toolsTop frontend web development tools
Top frontend web development toolsBenji Harrison
 
Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOTVMware Tanzu
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Practical Design Patterns in Docker Networking
Practical Design Patterns in Docker NetworkingPractical Design Patterns in Docker Networking
Practical Design Patterns in Docker NetworkingDocker, Inc.
 

Tendances (20)

Flyway _ A Database Version Management Tool
Flyway _ A Database Version Management ToolFlyway _ A Database Version Management Tool
Flyway _ A Database Version Management Tool
 
LiquiBase
LiquiBaseLiquiBase
LiquiBase
 
devops
devops devops
devops
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11
 
Salesforce DevOps using GitHub Action
Salesforce DevOps using GitHub ActionSalesforce DevOps using GitHub Action
Salesforce DevOps using GitHub Action
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Introduction to .NET Core
Introduction to .NET CoreIntroduction to .NET Core
Introduction to .NET Core
 
Top frontend web development tools
Top frontend web development toolsTop frontend web development tools
Top frontend web development tools
 
Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOT
 
DevOps - A Gentle Introduction
DevOps - A Gentle IntroductionDevOps - A Gentle Introduction
DevOps - A Gentle Introduction
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
 
Spring boot
Spring bootSpring boot
Spring boot
 
Practical Design Patterns in Docker Networking
Practical Design Patterns in Docker NetworkingPractical Design Patterns in Docker Networking
Practical Design Patterns in Docker Networking
 

En vedette

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 DatenbankmigrationstoolsStephan Kaps
 
Continuous DB Changes Delivery With Liquibase
Continuous DB Changes Delivery With LiquibaseContinuous DB Changes Delivery With Liquibase
Continuous DB Changes Delivery With LiquibaseAidas Dragūnas
 
Evoluindo bancos de dados com Flyway
Evoluindo bancos de dados com FlywayEvoluindo bancos de dados com Flyway
Evoluindo bancos de dados com FlywayVitor Albuquerque
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaAxel Fontaine
 
Introdução ao Flyway
Introdução ao FlywayIntrodução ao Flyway
Introdução ao FlywayJadson Santos
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDan 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ändringarSqueed
 
Flyway - database migrations made easy
Flyway - database migrations made easyFlyway - database migrations made easy
Flyway - database migrations made easyjstack
 
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 practicesAnkita 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 stackAmrita Prasad
 
Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With LiquibaseIASA
 
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 basesRoman 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
 

En vedette (20)

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
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for Java
 
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
 

Similaire à 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
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment TacticsIan Barber
 
Omaha (Google Update) server
Omaha (Google Update) serverOmaha (Google Update) server
Omaha (Google Update) serverDmitry Lyfar
 
Professional deployment
Professional deploymentProfessional deployment
Professional deploymentIvelina Dimova
 
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
 
Deployer - Deployment tool for PHP
Deployer - Deployment tool for PHPDeployer - Deployment tool for PHP
Deployer - Deployment tool for PHPhernanibf
 
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 IntegrationNicolas Fränkel
 
FlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootFlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootInexture 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 lineBehzod Saidov
 
Azure DevOps Deployment Group
Azure DevOps Deployment GroupAzure DevOps Deployment Group
Azure DevOps Deployment GroupRiwut Libinuko
 

Similaire à 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
 

Dernier

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Dernier (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

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.

Notes de l'éditeur

  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