SlideShare a Scribd company logo
Continuous DB migration
Boris Trofimov
@b0ris_1
www.btrofimoff.com
Agenda
 Dealing with changes
 Perfect solution or Continuous DB migration
 Carbon5 Introduction
 Maven-driven mode
 Embedded mode
 Pros/Cos and best practices
Dealing with Changes
 Applications evolve. God, bless bugs, refactoring and
business changes.
 We love applications and configure CI, VCS in order to
track source code/application version.
 But what’s about DB?
Dealing with Schema Change
 FACT: Some modifications might require changes in DB
schema.
Dealing with Schema Change
 FACT: Some modifications might require changes in DB
schema.
 Changes are simple and risky.
Dealing with Schema Change
 FACT: Some modifications might require changes in DB
schema.
 Changes are simple and risky.
 Simple changes:
– add one more table
– add index
Dealing with Schema Change
 FACT: Some application modifications might require
changes in DB schema.
 Changes are simple and risky.
 Simple changes:
– add one more table
– add index
 Risky changes:
– rename/add column
– change foreign key
– migrate data from one table/column to another
– denormalization on a fly
Dealing with Schema Change
 What’s about old apps upgrade and multiple schema changes?
App
v1
App
v10
The Impact
 Risks to lose data
 Painful downtime
 Risks to break application (see #1 and #2)
 Resources, efforts and budget
Friday’s deployment in some teams
How people solve it
 Deny Friday’s deployments
 Manual deployment
 Hibernate-like schema update + SQLexec
 Self-developed tools based on version number approach
Perfect solution
 Dedicated reusable framework
 Every Feature request leads to separated SQL migration script.
 Framework tracks which changes were not applied and applies
them.
 Configurable time to launch apply procedure
 Prevent Double changes
 Have Change Log
 Simple integration to existent project
Continuous DB Migration approach
min + automatic migration = Continuous DB Migration
Carbon V
Why Carbon V
 DB-migration framework
 Open Source project
 Lightweight framework
 Simple usage
How it works
 Dedicated project folder for SQL migration scripts. This folder
should be available when framework takes control.
 Each SQL migration script is pure SQL/DDL file with migration
SQL code for specific feature
 Each Delta file should have name
YYYYMMDDHHMMSS_<FEATURE>.sql
 When framework take control it checks and applies only new
changes.
 C5 uses own JDBC connection.
 Way to re-usue existent DataSources with connection params
No magic, just…
 C5 creates own table “schema_version” inside your database
 C5 controls this table by itself (no needs to create or update).
sql_file_name date duration
201405170900_user_auth.sql 2014-05-17
13:00:00
8 sec
201404130400_award_4565.sql 2014-04-14
14:00:00
6 sec
When to initiate migration procedure?
 Maven-driven approach
 Embedded mode
Maven-driven mode
Maven-driven mode
Configure Maven project
 Update POM definition
 Configure Explicit DB connection
 Can be configured depending on specific maven profiles
(staging, production)
Add SQL migration files
 Use Project/src/main/db/migrations directory
Launch it
 performs migration
$ mvn db-migration:migrate
 resets migration
$ mvn db-migration:reset
 check if DB is up to date
$ mvn db-migration:validate
 create new feature
$ mvn db-migration:new -Dname=new_feature
Use cases
 Manual runs from developer machine
 Part of Continuous Deivery process
– Add just one more Maven action inside specific CI configuration before
deployment action
Embedded mode
Embedded mode
 Schema Check is constituent part of application.
 SQL changes are built-in into the application
 Any checks and possible DB migration is performed every time
when application launches.
 Dedicated bean to carry out this responsibility
Create application bean
import com.carbonfive.db.migration.DataSourceMigrationManager;
import com.carbonfive.db.migration.DriverManagerMigrationManager;
import com.carbonfive.db.migration.MigrationManager;
import com.carbonfive.db.migration.ResourceMigrationResolver;
public class DBMigratorImpl {
DataSource dataSource;
...
public void init(){
DataSourceMigrationManager migrationManager = new
DataSourceMigrationManager(dataSource);
migrationManager.setMigrationResolver(new
ResourceMigrationResolver("classpath:/db/migrations"));
migrationManager.migrate();
}
}
Inject the bean into application context
 Seamless integrated with Spring DI
 It is possible to initialize ResourceMigrationResolver
DataSourceMigrationManager directly though Spring DI without any line of code
 Two places where bean might be integrated inside Spring context
 Before Persistent beans
 After Persistent beans
Embedded vs maven driven
 E: Consistent and grace application upgrade
 E: No delays between deployment and schema upgrade
 M: Simple integration with CI
 M: External commands like validate & reset
 M: Quick manual migrations (hotfixes for instance)
Carbon5 Benefits
 Lightweight framework
 Brilliant extensibility (thanks to reasonable design)
 Support many DBMS in unofficial mode
 Simple integration
 Real continuous DB migration
Need more features?
Continuous DB migration based on carbon5 framework
Flyway framework
 Rich support for different build tools
 The same integration approach on Carbon V
 Pluggable architecture
 Java-based migrations (two options: through JDBC Connection &
Spring JDBCTemplate)
 Extended service table
Best practices
 Feature driven development (each SQL feature change in own
file)
 Make sql files safe in order to prevent it from double execution
 Keep database connection settings in single place (use shared
DataSource)
 Do not make structure changes to the DB outside of your
framework
What’s about schemaless
?
Continuous DB migration based on carbon5 framework
NoSQL migration approach
 No dedicated explicit migration procedure (solved on business
level in case of needs)
 No shutdown or downtime
 Rolling update
– Every domain entity has version number
– your v2 application should handle the v1 db format
– Write code to convert entity to v2 on a fly (repository level)
– Write modified entities to v2 on demand
 Some DBs like RavenDB are able to perform auto-migration
References
 https://code.google.com/p/c5-db-migration/
 http://flywaydb.org/
 Martin Fowler Evolutionary Database Design
http://www.martinfowler.com/articles/evodb.html
 Refactoring Databases
Presentation in a nutshell
 Keep in mind this problem
 Do not invent wheels, use external frameworks/techniques
 And do not be afraid of Friday’s deployment then.
Thank you!
Q&A

More Related Content

PPTX
Websphere Application Server V8.5
PDF
jdbc
PPT
ibm websphere admin training | websphere admin course | ibm websphere adminis...
PPTX
Simple Yet Powerful Software and System Requirements Management
PPT
MuleSoft Database Connector
PDF
Offline Review of Requirements Documents in ReqIF Format
PPT
Jdbc drivers
PPTX
JDBC Driver Types
Websphere Application Server V8.5
jdbc
ibm websphere admin training | websphere admin course | ibm websphere adminis...
Simple Yet Powerful Software and System Requirements Management
MuleSoft Database Connector
Offline Review of Requirements Documents in ReqIF Format
Jdbc drivers
JDBC Driver Types

What's hot (20)

PPTX
Types of Drivers in JDBC
DOCX
Jdbc driver types
DOCX
Web Sphere Application Server Features
PPTX
Writing simple web services in java using eclipse editor
PDF
Enterprise Java Hosting in a Cloud Environment
PDF
Import Requirements Document
PPTX
SQL in Version Control using SQL Server Database Projects
PPT
Mule anypoint connector dev kit
PPT
New features of sql server 2005
PDF
Custom Requirement Attributes
ODP
Anypoint platform architecture and components
PPT
Anypoint data gateway
PPTX
Mule Esb Basics
PPTX
How to – wrap soap web service around a database
PPT
Mule database-connectors
PPTX
Cloud hub and mule
PPT
Weblogic - clustering failover, and load balancing
PPTX
Creating a custom connector in mule
PDF
Requirements Traceability Links
PPT
weblogic training | oracle weblogic online training | weblogic server course
Types of Drivers in JDBC
Jdbc driver types
Web Sphere Application Server Features
Writing simple web services in java using eclipse editor
Enterprise Java Hosting in a Cloud Environment
Import Requirements Document
SQL in Version Control using SQL Server Database Projects
Mule anypoint connector dev kit
New features of sql server 2005
Custom Requirement Attributes
Anypoint platform architecture and components
Anypoint data gateway
Mule Esb Basics
How to – wrap soap web service around a database
Mule database-connectors
Cloud hub and mule
Weblogic - clustering failover, and load balancing
Creating a custom connector in mule
Requirements Traceability Links
weblogic training | oracle weblogic online training | weblogic server course
Ad

Viewers also liked (15)

ODP
MongoDB Distilled
PDF
Bending Spark towards enterprise needs
PDF
Audience counting at Scale
PPTX
Scalding Big (Ad)ta
PDF
Scalding big ADta
PDF
MySQLドライバの改良と軽量O/Rマッパーの紹介
PDF
Faster persistent data structures through hashing
PPTX
Spring AOP Introduction
PDF
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
PDF
So various polymorphism in Scala
PPTX
Clustering Java applications with Terracotta and Hazelcast
PPTX
Managing (Schema) Migrations in Cassandra
PDF
DBスキーマもバージョン管理したい!
PDF
Spring Bootで変わる Javaアプリ開発! #jsug
PPTX
リーンキャンバスとは
MongoDB Distilled
Bending Spark towards enterprise needs
Audience counting at Scale
Scalding Big (Ad)ta
Scalding big ADta
MySQLドライバの改良と軽量O/Rマッパーの紹介
Faster persistent data structures through hashing
Spring AOP Introduction
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
So various polymorphism in Scala
Clustering Java applications with Terracotta and Hazelcast
Managing (Schema) Migrations in Cassandra
DBスキーマもバージョン管理したい!
Spring Bootで変わる Javaアプリ開発! #jsug
リーンキャンバスとは
Ad

Similar to Continuous DB migration based on carbon5 framework (20)

PDF
Migrating from RDBMS to MongoDB
PPTX
Webinar: Migrating from RDBMS to MongoDB (June 2015)
PPTX
NoSQL Architecture Overview
PPTX
Webinar: Migrating from RDBMS to MongoDB
PDF
KYSUC - Keep Your Schema Under Control
PPT
SQL/NoSQL How to choose ?
PPTX
mongodb_DS.pptx
PDF
Migration from MySQL to Cassandra for millions of active users
PPTX
Overview of MongoDB and Other Non-Relational Databases
PPTX
Discover the Power of the NoSQL + SQL with MySQL
PPTX
Discover The Power of NoSQL + MySQL with MySQL
PDF
Relational Database CI/CD
PPTX
Continuous database deployment
PPTX
Database for cloud
PDF
SQL? NoSQL? NewSQL?!? What’s a Java developer to do? - JDC2012 Cairo, Egypt
PDF
Introduction to MySQL Document Store
PPT
Document Databases & RavenDB
PDF
MySQL Document Store (Oracle Code Warsaw 2018)
PPTX
NoSQL and MongoDB
ODP
MySQL And Search At Craigslist
Migrating from RDBMS to MongoDB
Webinar: Migrating from RDBMS to MongoDB (June 2015)
NoSQL Architecture Overview
Webinar: Migrating from RDBMS to MongoDB
KYSUC - Keep Your Schema Under Control
SQL/NoSQL How to choose ?
mongodb_DS.pptx
Migration from MySQL to Cassandra for millions of active users
Overview of MongoDB and Other Non-Relational Databases
Discover the Power of the NoSQL + SQL with MySQL
Discover The Power of NoSQL + MySQL with MySQL
Relational Database CI/CD
Continuous database deployment
Database for cloud
SQL? NoSQL? NewSQL?!? What’s a Java developer to do? - JDC2012 Cairo, Egypt
Introduction to MySQL Document Store
Document Databases & RavenDB
MySQL Document Store (Oracle Code Warsaw 2018)
NoSQL and MongoDB
MySQL And Search At Craigslist

More from b0ris_1 (8)

PDF
Learning from nature or human body as a source on inspiration for software en...
PDF
Devoxx 2022
PDF
IT Arena-2021
PDF
New accelerators in Big Data - Upsolver
PDF
Learning from nature [slides from Software Architecture meetup]
PDF
Cowboy dating with big data TechDays at Lohika-2020
PDF
Cowboy dating with big data
PDF
Ultimate journey towards realtime data platform with 2.5M events per sec
Learning from nature or human body as a source on inspiration for software en...
Devoxx 2022
IT Arena-2021
New accelerators in Big Data - Upsolver
Learning from nature [slides from Software Architecture meetup]
Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data
Ultimate journey towards realtime data platform with 2.5M events per sec

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
Digital-Transformation-Roadmap-for-Companies.pptx
MIND Revenue Release Quarter 2 2025 Press Release

Continuous DB migration based on carbon5 framework

  • 1. Continuous DB migration Boris Trofimov @b0ris_1 www.btrofimoff.com
  • 2. Agenda  Dealing with changes  Perfect solution or Continuous DB migration  Carbon5 Introduction  Maven-driven mode  Embedded mode  Pros/Cos and best practices
  • 3. Dealing with Changes  Applications evolve. God, bless bugs, refactoring and business changes.  We love applications and configure CI, VCS in order to track source code/application version.  But what’s about DB?
  • 4. Dealing with Schema Change  FACT: Some modifications might require changes in DB schema.
  • 5. Dealing with Schema Change  FACT: Some modifications might require changes in DB schema.  Changes are simple and risky.
  • 6. Dealing with Schema Change  FACT: Some modifications might require changes in DB schema.  Changes are simple and risky.  Simple changes: – add one more table – add index
  • 7. Dealing with Schema Change  FACT: Some application modifications might require changes in DB schema.  Changes are simple and risky.  Simple changes: – add one more table – add index  Risky changes: – rename/add column – change foreign key – migrate data from one table/column to another – denormalization on a fly
  • 8. Dealing with Schema Change  What’s about old apps upgrade and multiple schema changes? App v1 App v10
  • 9. The Impact  Risks to lose data  Painful downtime  Risks to break application (see #1 and #2)  Resources, efforts and budget
  • 11. How people solve it  Deny Friday’s deployments  Manual deployment  Hibernate-like schema update + SQLexec  Self-developed tools based on version number approach
  • 12. Perfect solution  Dedicated reusable framework  Every Feature request leads to separated SQL migration script.  Framework tracks which changes were not applied and applies them.  Configurable time to launch apply procedure  Prevent Double changes  Have Change Log  Simple integration to existent project
  • 13. Continuous DB Migration approach min + automatic migration = Continuous DB Migration
  • 15. Why Carbon V  DB-migration framework  Open Source project  Lightweight framework  Simple usage
  • 16. How it works  Dedicated project folder for SQL migration scripts. This folder should be available when framework takes control.  Each SQL migration script is pure SQL/DDL file with migration SQL code for specific feature  Each Delta file should have name YYYYMMDDHHMMSS_<FEATURE>.sql  When framework take control it checks and applies only new changes.  C5 uses own JDBC connection.  Way to re-usue existent DataSources with connection params
  • 17. No magic, just…  C5 creates own table “schema_version” inside your database  C5 controls this table by itself (no needs to create or update). sql_file_name date duration 201405170900_user_auth.sql 2014-05-17 13:00:00 8 sec 201404130400_award_4565.sql 2014-04-14 14:00:00 6 sec
  • 18. When to initiate migration procedure?  Maven-driven approach  Embedded mode
  • 21. Configure Maven project  Update POM definition  Configure Explicit DB connection  Can be configured depending on specific maven profiles (staging, production)
  • 22. Add SQL migration files  Use Project/src/main/db/migrations directory
  • 23. Launch it  performs migration $ mvn db-migration:migrate  resets migration $ mvn db-migration:reset  check if DB is up to date $ mvn db-migration:validate  create new feature $ mvn db-migration:new -Dname=new_feature
  • 24. Use cases  Manual runs from developer machine  Part of Continuous Deivery process – Add just one more Maven action inside specific CI configuration before deployment action
  • 26. Embedded mode  Schema Check is constituent part of application.  SQL changes are built-in into the application  Any checks and possible DB migration is performed every time when application launches.  Dedicated bean to carry out this responsibility
  • 27. Create application bean import com.carbonfive.db.migration.DataSourceMigrationManager; import com.carbonfive.db.migration.DriverManagerMigrationManager; import com.carbonfive.db.migration.MigrationManager; import com.carbonfive.db.migration.ResourceMigrationResolver; public class DBMigratorImpl { DataSource dataSource; ... public void init(){ DataSourceMigrationManager migrationManager = new DataSourceMigrationManager(dataSource); migrationManager.setMigrationResolver(new ResourceMigrationResolver("classpath:/db/migrations")); migrationManager.migrate(); } }
  • 28. Inject the bean into application context  Seamless integrated with Spring DI  It is possible to initialize ResourceMigrationResolver DataSourceMigrationManager directly though Spring DI without any line of code  Two places where bean might be integrated inside Spring context  Before Persistent beans  After Persistent beans
  • 29. Embedded vs maven driven  E: Consistent and grace application upgrade  E: No delays between deployment and schema upgrade  M: Simple integration with CI  M: External commands like validate & reset  M: Quick manual migrations (hotfixes for instance)
  • 30. Carbon5 Benefits  Lightweight framework  Brilliant extensibility (thanks to reasonable design)  Support many DBMS in unofficial mode  Simple integration  Real continuous DB migration
  • 33. Flyway framework  Rich support for different build tools  The same integration approach on Carbon V  Pluggable architecture  Java-based migrations (two options: through JDBC Connection & Spring JDBCTemplate)  Extended service table
  • 34. Best practices  Feature driven development (each SQL feature change in own file)  Make sql files safe in order to prevent it from double execution  Keep database connection settings in single place (use shared DataSource)  Do not make structure changes to the DB outside of your framework
  • 37. NoSQL migration approach  No dedicated explicit migration procedure (solved on business level in case of needs)  No shutdown or downtime  Rolling update – Every domain entity has version number – your v2 application should handle the v1 db format – Write code to convert entity to v2 on a fly (repository level) – Write modified entities to v2 on demand  Some DBs like RavenDB are able to perform auto-migration
  • 38. References  https://code.google.com/p/c5-db-migration/  http://flywaydb.org/  Martin Fowler Evolutionary Database Design http://www.martinfowler.com/articles/evodb.html  Refactoring Databases
  • 39. Presentation in a nutshell  Keep in mind this problem  Do not invent wheels, use external frameworks/techniques  And do not be afraid of Friday’s deployment then.