SlideShare a Scribd company logo
2
Most read
4
Most read
Database Migrations
What's the problem?
Provide upgrades of applications and databases to our
customers
Some customers require SQL scripts to run via DB admin
tools, e.g. Oracle (sqlplus)
We don't have database schemas that reflect what's been
applied in terms of updates - always the newest
We don't really understand what Hibernate is doing to
create/modify tables based on our persistent objects, we
rely on it for optimization, indexes etc...
Database Migrations
Structure SQL scripts for creation of the
schema, updates of the schema accordingly
Use a tool to run these migrations:
● In a specific order
● Against a specific database (MySQL,
Oracle)
● Recording the actions in a schema version
table
Lots of tools that do this
Flyway
Allows us to do migrations:
● From a shell script
● Programmatically
● When Spring starts
● Using Maven as a build tool
Introducing Flyway into your project
Has been done for MIF - there's a dbtool folder
in the source structure. We can provide a
template in SVN that can be used.
1. Download the dbtool structure
2. Generate an export of the schema that
Hibernate has created for your project
Introducing Flyway into your project
3. Tweak/optimise if necessary
4. Run the following command:
./flyway.sh init
Introducing Flyway into your project
This creates the SCHEMA_VERSION table:
mysql> desc SCHEMA_VERSION;
+-----------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+-------------------+-------+
| version | varchar(20) | NO | PRI | NULL | |
| description | varchar(100) | YES | | NULL | |
| type | varchar(10) | NO | | NULL | |
| script | varchar(200) | NO | UNI | NULL | |
| checksum | int(11) | YES | | NULL | |
| installed_by | varchar(30) | NO | | NULL | |
| installed_on | timestamp | NO | | CURRENT_TIMESTAMP | |
| execution_time | int(11) | YES | | NULL | |
| state | varchar(15) | NO | | NULL | |
| current_version | tinyint(1) | NO | MUL | NULL | |
+-----------------+--------------+------+-----+-------------------+-------+
Performing a migration
Assume you've added a new script in the
<dbname>/sql folder of dbtool
Run:
./flyway.sh migrate
This will run the script and record the action in
the SCHEMA_VERSION table.
Flyway dbtool structure
├── mysql
│ ├── conf
│ │ └── flyway.properties
│ ├── flyway.cmd
│ ├── flyway.sh
│ ├── jars
│ │ └── mysql-connector-java-5.1.14.jar
│ └── sql
│ ├── V1__MIFBaseSchema.sql
│ └── V2__JOB.DATE_ACKNOWLEDGED.sql
└── oracle
├── conf
│ └── flyway.properties
├── flyway.cmd
├── flyway.sh
├── jars
│ └── ojdbc14-10.2.0.5.jar
└── sql
Process Change
Need to change the way we develop persistent
objects with Hibernate
As well as changing an object we also need to
provide a migration script (and a rollback script)
Put it in the <dbname>/sql folder.
ls -Al mysql/sql
V1__MIFBaseSchema.sql
V2__JOB.DATE_ACKNOWLEDGED.sql
Example
Change a persistent object to add a new field
Write a script with the appropriate ALTER
TABLE ADD COLUMN statement.
Write the rollback script
Test

More Related Content

PPTX
Flyway: The agile database migration framework for Java
PPTX
Getting started with agile database migrations for java flywaydb
PDF
Database migrations with Flyway and Liquibase
PPTX
Liquibase migration for data bases
PDF
Flyway _ A Database Version Management Tool
PPTX
Continuous DB Changes Delivery With Liquibase
Flyway: The agile database migration framework for Java
Getting started with agile database migrations for java flywaydb
Database migrations with Flyway and Liquibase
Liquibase migration for data bases
Flyway _ A Database Version Management Tool
Continuous DB Changes Delivery With Liquibase

What's hot (20)

PPTX
Come Fly With Me: Database Migration Patterns with Flyway
PPTX
Database versioning with liquibase
PDF
Rest API
PDF
What is DevOps | DevOps Introduction | DevOps Training | DevOps Tutorial | Ed...
PPTX
Liquibase case study
PDF
Salesforce CI/CD - A strategy for success
PPTX
Azure DevOps Best Practices Webinar
PPTX
Azure DevOps in Action
PPTX
GitHub Basics - Derek Bable
PDF
DevOps
PPTX
Feature Toggles
PPTX
MuleSoft Architecture Presentation
PPTX
Liquibase for java developers
PPTX
Copado - SoftClouds | Expertise
PDF
OpenShift 4, the smarter Kubernetes platform
PPTX
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
ODP
Liquibase & Flyway @ Baltic DevOps
PDF
MySQL Deep dive with FusionIO
PPTX
Migration from Oracle to PostgreSQL: NEED vs REALITY
PDF
Azure DevOps Presentation
Come Fly With Me: Database Migration Patterns with Flyway
Database versioning with liquibase
Rest API
What is DevOps | DevOps Introduction | DevOps Training | DevOps Tutorial | Ed...
Liquibase case study
Salesforce CI/CD - A strategy for success
Azure DevOps Best Practices Webinar
Azure DevOps in Action
GitHub Basics - Derek Bable
DevOps
Feature Toggles
MuleSoft Architecture Presentation
Liquibase for java developers
Copado - SoftClouds | Expertise
OpenShift 4, the smarter Kubernetes platform
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
Liquibase & Flyway @ Baltic DevOps
MySQL Deep dive with FusionIO
Migration from Oracle to PostgreSQL: NEED vs REALITY
Azure DevOps Presentation
Ad

Viewers also liked (20)

PDF
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
PPTX
Evoluindo bancos de dados com Flyway
PDF
Introdução ao Flyway
PPTX
Liquibase
PDF
Gitora, Version Control for PL/SQL
PDF
Gitora, Version Control for PL/SQL
PDF
Version control for PL/SQL
PPTX
Flyway - database migrations made easy
PDF
Liquibase få kontroll på dina databasförändringar
PDF
33rd degree talk: open and automatic coding conventions with walkmod
PPTX
The Challenges & Pitfalls of Database Continuous Delivery
PPTX
Challenges and best practices of database continuous delivery
PDF
walkmod: how it works
PDF
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
PDF
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
PDF
Database version control without pain - the PHPNW10 version
PDF
Database Source Control: Migrations vs State
PDF
Road to database automation: database source control
PPTX
Deploying Symfony2 app with Ansible
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Evoluindo bancos de dados com Flyway
Introdução ao Flyway
Liquibase
Gitora, Version Control for PL/SQL
Gitora, Version Control for PL/SQL
Version control for PL/SQL
Flyway - database migrations made easy
Liquibase få kontroll på dina databasförändringar
33rd degree talk: open and automatic coding conventions with walkmod
The Challenges & Pitfalls of Database Continuous Delivery
Challenges and best practices of database continuous delivery
walkmod: how it works
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
Database version control without pain - the PHPNW10 version
Database Source Control: Migrations vs State
Road to database automation: database source control
Deploying Symfony2 app with Ansible
Ad

Similar to Database migration with flyway (20)

PPT
SQL Server 2008 Integration Services
PDF
Simple ETL Solution - Marco Kiesewetter
PDF
Flexviews materialized views for my sql
PPTX
WebLogic Scripting Tool made Cool!
PPTX
WinOps Conf 2016 - Ed Wilson - Configuration Management with Azure DSC
PDF
How to instantiate any view controller for free
PPT
Mmik powershell dsc_slideshare_v1
PPT
Mmik_Powershell_DSC_Azure_DSC
PPT
40084_graves.ppt : Oracle Database Documentation
PPTX
Procedures and triggers in SQL
PPT
Mobile
PPTX
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
PPTX
Mocking with salesforce using Munit
PDF
Airflow presentation
PPT
WF 4.0 Overview
PPTX
VM Job Queues in CloudStack
POTX
Apache Spark Streaming: Architecture and Fault Tolerance
PDF
从 Oracle 合并到 my sql npr 实例分析
PPTX
Intro to Environment as a Service - Cloudify 5.0.5 Webinar
PPT
Chapter09
SQL Server 2008 Integration Services
Simple ETL Solution - Marco Kiesewetter
Flexviews materialized views for my sql
WebLogic Scripting Tool made Cool!
WinOps Conf 2016 - Ed Wilson - Configuration Management with Azure DSC
How to instantiate any view controller for free
Mmik powershell dsc_slideshare_v1
Mmik_Powershell_DSC_Azure_DSC
40084_graves.ppt : Oracle Database Documentation
Procedures and triggers in SQL
Mobile
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
Mocking with salesforce using Munit
Airflow presentation
WF 4.0 Overview
VM Job Queues in CloudStack
Apache Spark Streaming: Architecture and Fault Tolerance
从 Oracle 合并到 my sql npr 实例分析
Intro to Environment as a Service - Cloudify 5.0.5 Webinar
Chapter09

More from Jonathan Holloway (11)

PPTX
The Role of the Architect
PPTX
Spring boot - an introduction
PPTX
Jenkins CI presentation
PPTX
Mockito intro
PPTX
PPTX
SOLID principles
PPTX
Application design for the cloud using AWS
PPTX
Building data pipelines
PPTX
Introduction to JVM languages and Fantom (very brief)
PDF
Lightweight web frameworks
PDF
Introduction to using MongoDB with Ruby
The Role of the Architect
Spring boot - an introduction
Jenkins CI presentation
Mockito intro
SOLID principles
Application design for the cloud using AWS
Building data pipelines
Introduction to JVM languages and Fantom (very brief)
Lightweight web frameworks
Introduction to using MongoDB with Ruby

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Encapsulation theory and applications.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Unlocking AI with Model Context Protocol (MCP)
Electronic commerce courselecture one. Pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Modernizing your data center with Dell and AMD
Encapsulation theory and applications.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Unlocking AI with Model Context Protocol (MCP)

Database migration with flyway

  • 2. What's the problem? Provide upgrades of applications and databases to our customers Some customers require SQL scripts to run via DB admin tools, e.g. Oracle (sqlplus) We don't have database schemas that reflect what's been applied in terms of updates - always the newest We don't really understand what Hibernate is doing to create/modify tables based on our persistent objects, we rely on it for optimization, indexes etc...
  • 3. Database Migrations Structure SQL scripts for creation of the schema, updates of the schema accordingly Use a tool to run these migrations: ● In a specific order ● Against a specific database (MySQL, Oracle) ● Recording the actions in a schema version table Lots of tools that do this
  • 4. Flyway Allows us to do migrations: ● From a shell script ● Programmatically ● When Spring starts ● Using Maven as a build tool
  • 5. Introducing Flyway into your project Has been done for MIF - there's a dbtool folder in the source structure. We can provide a template in SVN that can be used. 1. Download the dbtool structure 2. Generate an export of the schema that Hibernate has created for your project
  • 6. Introducing Flyway into your project 3. Tweak/optimise if necessary 4. Run the following command: ./flyway.sh init
  • 7. Introducing Flyway into your project This creates the SCHEMA_VERSION table: mysql> desc SCHEMA_VERSION; +-----------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+-------------------+-------+ | version | varchar(20) | NO | PRI | NULL | | | description | varchar(100) | YES | | NULL | | | type | varchar(10) | NO | | NULL | | | script | varchar(200) | NO | UNI | NULL | | | checksum | int(11) | YES | | NULL | | | installed_by | varchar(30) | NO | | NULL | | | installed_on | timestamp | NO | | CURRENT_TIMESTAMP | | | execution_time | int(11) | YES | | NULL | | | state | varchar(15) | NO | | NULL | | | current_version | tinyint(1) | NO | MUL | NULL | | +-----------------+--------------+------+-----+-------------------+-------+
  • 8. Performing a migration Assume you've added a new script in the <dbname>/sql folder of dbtool Run: ./flyway.sh migrate This will run the script and record the action in the SCHEMA_VERSION table.
  • 9. Flyway dbtool structure ├── mysql │ ├── conf │ │ └── flyway.properties │ ├── flyway.cmd │ ├── flyway.sh │ ├── jars │ │ └── mysql-connector-java-5.1.14.jar │ └── sql │ ├── V1__MIFBaseSchema.sql │ └── V2__JOB.DATE_ACKNOWLEDGED.sql └── oracle ├── conf │ └── flyway.properties ├── flyway.cmd ├── flyway.sh ├── jars │ └── ojdbc14-10.2.0.5.jar └── sql
  • 10. Process Change Need to change the way we develop persistent objects with Hibernate As well as changing an object we also need to provide a migration script (and a rollback script) Put it in the <dbname>/sql folder. ls -Al mysql/sql V1__MIFBaseSchema.sql V2__JOB.DATE_ACKNOWLEDGED.sql
  • 11. Example Change a persistent object to add a new field Write a script with the appropriate ALTER TABLE ADD COLUMN statement. Write the rollback script Test