SlideShare uma empresa Scribd logo
1 de 60
Baixar para ler offline
Database versioning
with FlywayDB
Manuel de la Peña
Software Engineer
@mdelapenya
Why DB migration tools?
Why DB migration tools?
Lots of developers!!!
Why DB migration tools?
https://cdn1.iconfinder.com/data/icons/database/PNG/256/Database_3.png
CI
Test
Development
Pre
Pro
Lots of developers!!!
…in the code side…
Version Control
Release tool/plugins on CI
…but in the Database…
Which version is your DB?
What we’d love is…
What we’d love is…
Recreate DB from scratch
Make it clear the state of the DB
Migrate in a deterministic way!!
Database migrations
Made easy
How FlywayDB works
How FlywayDB works
Metadata table (SCHEMA_VERSION)
How FlywayDB works
Metadata table (SCHEMA_VERSION)
Classpath search for migrations
How FlywayDB works
Metadata table (SCHEMA_VERSION)
Classpath search for migrations
SQL or Java
How FlywayDB works
Metadata table (SCHEMA_VERSION)
Classpath search for migrations
SQL or Java
Sorted by version, and applied in order
How FlywayDB works
Metadata table (SCHEMA_VERSION)
Classpath search for migrations
SQL or Java
Compared against current version
Sorted by version, and applied in order
How FlywayDB works
Metadata table (SCHEMA_VERSION)
Classpath search for migrations
SQL or Java
Compared against current version
Sorted by version, and applied in order
Checksum change-detection validation
Supported DB’s
Oracle
SQL Server
SQL Azure
DB2MySQL
MariaDB
Google Cloud SQL
PostgreSQL
H2
HSQL
Derby Android SQLite
Executing FlywayDB
Command Line
Executing FlywayDB
Command Line
flyway.properties
jars dir
migrations dir
flyway migrate
Executing FlywayDB
Command Line
Maven Plugin
Executing FlywayDB
Command Line
Maven Plugin
Ant
Executing FlywayDB
Command Line
Maven Plugin
Ant
Gradle
Executing FlywayDB
Command Line
Maven Plugin
Ant
Gradle
SBT (Scala Build Tool)
Executing FlywayDB
Command Line
Maven Plugin
Ant
Gradle
SBT (Scala Build Tool)
API
Java classes
Spring configuration
Migrations
Versions
One or more numeric parts
Separated by a dots or an underscore
Underscores are replaced by dots at runtime
Leading zeros are ignored on each part
Version examples
1
001
5.2
5_2 (5.2 at runtime)
205.68
1.2.3.4.5.6.7.8.9
20130115113556
2013.1.15.11.35.56
2013.01.15.11.35.56
SQL Migrations
Discovery
Discovery
Filesystem locationClasspath location
Automatically at runtime
Naming
prefix: Configurable, default: V
version: Dots or underscores separate the parts,
as many parts as you like
separator: Configurable, default: __ (2 underscores)
description: Underscores or spaces to separate
the words
suffix: Configurable, default: .sql
Sample SQL versions
V_1__Add_phone_number_to_user.sql
V_2__Remove_picture_to_user.sql
V_3__Add_folders_to_article.sql
Syntax
Syntax
Single/multiline statements
Single/multiline comments
Placeholder replacements
DB specific extensions
Java Migrations
¿Java migrations?
¿Java migrations?
C/LOB changes
Advanced Bulk data operations
Discovery
flyway.setLocations(…)
Naming
prefix: Always V
version: Underscores separate the parts, as many
parts as you like
separator: __ (2 underscores)
description: Underscores to separate the words
Sample Java versions
V_1__Add_phone_number_to_user.java
V_2__Remove_picture_to_user.java
V_3__Add_folders_to_article.java
Usage
Usage
Implements JdbcMigration
Wraps the migration in a transaction
Extracts the version from class name
Advanced usage
Advanced usage
MigrationProviderInfo:
redefine prefix, version, separator...
Advanced usage
MigrationProviderInfo:
redefine prefix, version, separator...
MigrationChecksumProvider:
getChecksum()
Advanced usage
MigrationProviderInfo:
redefine prefix, version, separator...
MigrationChecksumProvider:
getChecksum()
Spring support:
implements SpringJdbcMigration
(JdbcTemplate)
Migrating existing databases
Steps
1. Take a DDL from production
2. Add inserts for all reference data you need
3. Give relevant version number
(V1__Base-.version.sql)
4. Clean all databases
5. Remove their contents with flyway:clean
6. Align databases with production
7. Exactly the same DDL
8. The objects they migrate must be identical to
what is present in production.
9. Give databases initial version
More advanced usage
Advanced usage
OSGi support
Cluster migrations in parallel
Multiple schema support
Placeholder replacements ${placeholder}
Before-Hibernate-Export integration
Drawbacks
Drawbacks
Rollback migrations with destructive changes
Initial schema not retrieved from existing
database
DB-specific code must be separated by locations
FlywayDB
Demo
Thank you!
Questions?

Mais conteúdo relacionado

Mais procurados

Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A GrzesikApache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
mfrancis
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 

Mais procurados (20)

Liquibase
LiquibaseLiquibase
Liquibase
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A GrzesikApache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
 
LiquiBase
LiquiBaseLiquiBase
LiquiBase
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 
Microsoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxMicrosoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptx
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to vue.js
 
.Net Core 1.0 vs .NET Framework
.Net Core 1.0 vs .NET Framework.Net Core 1.0 vs .NET Framework
.Net Core 1.0 vs .NET Framework
 
MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바
 
Automating security test using Selenium and OWASP ZAP - Practical DevSecOps
Automating security test using Selenium and OWASP ZAP - Practical DevSecOpsAutomating security test using Selenium and OWASP ZAP - Practical DevSecOps
Automating security test using Selenium and OWASP ZAP - Practical DevSecOps
 
[네이버오픈소스세미나] Next Generation Spring Security OAuth2.0 - 이명현
[네이버오픈소스세미나] Next Generation Spring Security OAuth2.0 - 이명현[네이버오픈소스세미나] Next Generation Spring Security OAuth2.0 - 이명현
[네이버오픈소스세미나] Next Generation Spring Security OAuth2.0 - 이명현
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Local storage
Local storageLocal storage
Local storage
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Jenkins tutorial for beginners
Jenkins tutorial for beginnersJenkins tutorial for beginners
Jenkins tutorial for beginners
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 

Semelhante a Flywaydb

Борис Трофимов. Continuous Database migration-это просто!
Борис Трофимов. Continuous Database migration-это просто!Борис Трофимов. Continuous Database migration-это просто!
Борис Трофимов. Continuous Database migration-это просто!
Volha Banadyseva
 
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
PostgresOpen
 
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 EditionEnter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Mark Broadbent
 
Oracle To Sql Server migration process
Oracle To Sql Server migration processOracle To Sql Server migration process
Oracle To Sql Server migration process
harirk1986
 

Semelhante a Flywaydb (20)

Obevo Javasig.pptx
Obevo Javasig.pptxObevo Javasig.pptx
Obevo Javasig.pptx
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Continuous DB migration based on carbon5 framework
Continuous DB migration based on carbon5 frameworkContinuous DB migration based on carbon5 framework
Continuous DB migration based on carbon5 framework
 
Борис Трофимов. Continuous Database migration-это просто!
Борис Трофимов. Continuous Database migration-это просто!Борис Трофимов. Continuous Database migration-это просто!
Борис Трофимов. Continuous Database migration-это просто!
 
Tauhid: SQL Server Database Change Automation
Tauhid: SQL Server Database Change AutomationTauhid: SQL Server Database Change Automation
Tauhid: SQL Server Database Change Automation
 
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
 
Sql server
Sql serverSql server
Sql server
 
FlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootFlywayDB Migration with Spring Boot
FlywayDB Migration with Spring Boot
 
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 EditionEnter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
 
Database CI/CD Pipeline
Database CI/CD PipelineDatabase CI/CD Pipeline
Database CI/CD Pipeline
 
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 ...
 
Oracle To Sql Server migration process
Oracle To Sql Server migration processOracle To Sql Server migration process
Oracle To Sql Server migration process
 
Javaone 2014
Javaone 2014Javaone 2014
Javaone 2014
 
Mobile
MobileMobile
Mobile
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
 
Simple SQL Change Management with Sqitch
Simple SQL Change Management with SqitchSimple SQL Change Management with Sqitch
Simple SQL Change Management with Sqitch
 
Flyway (33rd Degree)
Flyway (33rd Degree)Flyway (33rd Degree)
Flyway (33rd Degree)
 
Evolutionary Database Design
Evolutionary Database DesignEvolutionary Database Design
Evolutionary Database Design
 
Road to database automation: database source control
Road to database automation: database source controlRoad to database automation: database source control
Road to database automation: database source control
 
Level up your deployments for SQL Source Control
Level up your deployments for SQL Source Control Level up your deployments for SQL Source Control
Level up your deployments for SQL Source Control
 

Mais de Manuel de la Peña Peña

Mais de Manuel de la Peña Peña (16)

202204-Modernizando aplicaciones legacy
202204-Modernizando aplicaciones legacy202204-Modernizando aplicaciones legacy
202204-Modernizando aplicaciones legacy
 
Dream QA: Designing the QA team where we'd love to work
Dream QA: Designing the QA team where we'd love to workDream QA: Designing the QA team where we'd love to work
Dream QA: Designing the QA team where we'd love to work
 
Plataforma Eagle - GoApps Toledo
Plataforma Eagle - GoApps ToledoPlataforma Eagle - GoApps Toledo
Plataforma Eagle - GoApps Toledo
 
swcraftersclm - Retrospectiva 2017
swcraftersclm - Retrospectiva 2017swcraftersclm - Retrospectiva 2017
swcraftersclm - Retrospectiva 2017
 
Kanban
KanbanKanban
Kanban
 
Modern Continuous Delivery with Docker and Liferay
Modern Continuous Delivery with Docker and LiferayModern Continuous Delivery with Docker and Liferay
Modern Continuous Delivery with Docker and Liferay
 
Testing 101
Testing 101Testing 101
Testing 101
 
Docker zero
Docker zeroDocker zero
Docker zero
 
Ansible - A 'crowd' introduction
Ansible - A 'crowd' introductionAnsible - A 'crowd' introduction
Ansible - A 'crowd' introduction
 
Katanga
KatangaKatanga
Katanga
 
Deployments in one click!
Deployments in one click!Deployments in one click!
Deployments in one click!
 
Compras en Internet: Fácil y Seguro
Compras en Internet: Fácil y SeguroCompras en Internet: Fácil y Seguro
Compras en Internet: Fácil y Seguro
 
Redes sociales orientadas al autoempleo
Redes sociales orientadas al autoempleoRedes sociales orientadas al autoempleo
Redes sociales orientadas al autoempleo
 
Productividad en tu mano
Productividad en tu manoProductividad en tu mano
Productividad en tu mano
 
Sostenibilidad y Software Libre
Sostenibilidad y Software LibreSostenibilidad y Software Libre
Sostenibilidad y Software Libre
 
Manuel de la Peña & Liferay EVP
Manuel de la Peña & Liferay EVPManuel de la Peña & Liferay EVP
Manuel de la Peña & Liferay EVP
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

Flywaydb