SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
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?
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
?
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

Contenu connexe

Tendances

Types of Drivers in JDBC
Types of Drivers in JDBCTypes of Drivers in JDBC
Types of Drivers in JDBCHemant Sharma
 
Web Sphere Application Server Features
Web Sphere Application Server FeaturesWeb Sphere Application Server Features
Web Sphere Application Server FeaturesSymbyo Technologies
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorSantosh Kumar Kar
 
Enterprise Java Hosting in a Cloud Environment
Enterprise Java Hosting in a Cloud EnvironmentEnterprise Java Hosting in a Cloud Environment
Enterprise Java Hosting in a Cloud EnvironmentSweta Vajjhala
 
Import Requirements Document
Import Requirements DocumentImport Requirements Document
Import Requirements DocumentEccam
 
SQL in Version Control using SQL Server Database Projects
SQL in Version Control using SQL Server Database ProjectsSQL in Version Control using SQL Server Database Projects
SQL in Version Control using SQL Server Database Projectsfloydhilton
 
Mule anypoint connector dev kit
Mule  anypoint connector dev kitMule  anypoint connector dev kit
Mule anypoint connector dev kitD.Rajesh Kumar
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005Govind Raj
 
Custom Requirement Attributes
Custom Requirement AttributesCustom Requirement Attributes
Custom Requirement AttributesEccam
 
Anypoint platform architecture and components
Anypoint platform architecture and componentsAnypoint platform architecture and components
Anypoint platform architecture and componentsD.Rajesh Kumar
 
Anypoint data gateway
Anypoint data gatewayAnypoint data gateway
Anypoint data gatewayKhan625
 
Mule Esb Basics
Mule Esb BasicsMule Esb Basics
Mule Esb Basicsmdfkhan625
 
How to – wrap soap web service around a database
How to – wrap soap web service around a databaseHow to – wrap soap web service around a database
How to – wrap soap web service around a databaseSon Nguyen
 
Mule database-connectors
Mule database-connectorsMule database-connectors
Mule database-connectorsPhaniu
 
Cloud hub and mule
Cloud hub and muleCloud hub and mule
Cloud hub and muleSon Nguyen
 
Creating a custom connector in mule
Creating a custom connector in muleCreating a custom connector in mule
Creating a custom connector in muleAchyuta Lakshmi
 
Requirements Traceability Links
Requirements Traceability LinksRequirements Traceability Links
Requirements Traceability LinksEccam
 
weblogic training | oracle weblogic online training | weblogic server course
weblogic training | oracle weblogic online training | weblogic server courseweblogic training | oracle weblogic online training | weblogic server course
weblogic training | oracle weblogic online training | weblogic server courseNancy Thomas
 

Tendances (20)

Types of Drivers in JDBC
Types of Drivers in JDBCTypes of Drivers in JDBC
Types of Drivers in JDBC
 
Jdbc driver types
Jdbc driver typesJdbc driver types
Jdbc driver types
 
Web Sphere Application Server Features
Web Sphere Application Server FeaturesWeb Sphere Application Server Features
Web Sphere Application Server Features
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
 
Enterprise Java Hosting in a Cloud Environment
Enterprise Java Hosting in a Cloud EnvironmentEnterprise Java Hosting in a Cloud Environment
Enterprise Java Hosting in a Cloud Environment
 
Import Requirements Document
Import Requirements DocumentImport Requirements Document
Import Requirements Document
 
SQL in Version Control using SQL Server Database Projects
SQL in Version Control using SQL Server Database ProjectsSQL in Version Control using SQL Server Database Projects
SQL in Version Control using SQL Server Database Projects
 
Mule anypoint connector dev kit
Mule  anypoint connector dev kitMule  anypoint connector dev kit
Mule anypoint connector dev kit
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005
 
Custom Requirement Attributes
Custom Requirement AttributesCustom Requirement Attributes
Custom Requirement Attributes
 
Anypoint platform architecture and components
Anypoint platform architecture and componentsAnypoint platform architecture and components
Anypoint platform architecture and components
 
Anypoint data gateway
Anypoint data gatewayAnypoint data gateway
Anypoint data gateway
 
Mule Esb Basics
Mule Esb BasicsMule Esb Basics
Mule Esb Basics
 
How to – wrap soap web service around a database
How to – wrap soap web service around a databaseHow to – wrap soap web service around a database
How to – wrap soap web service around a database
 
Mule database-connectors
Mule database-connectorsMule database-connectors
Mule database-connectors
 
Cloud hub and mule
Cloud hub and muleCloud hub and mule
Cloud hub and mule
 
Weblogic - clustering failover, and load balancing
Weblogic - clustering failover, and load balancingWeblogic - clustering failover, and load balancing
Weblogic - clustering failover, and load balancing
 
Creating a custom connector in mule
Creating a custom connector in muleCreating a custom connector in mule
Creating a custom connector in mule
 
Requirements Traceability Links
Requirements Traceability LinksRequirements Traceability Links
Requirements Traceability Links
 
weblogic training | oracle weblogic online training | weblogic server course
weblogic training | oracle weblogic online training | weblogic server courseweblogic training | oracle weblogic online training | weblogic server course
weblogic training | oracle weblogic online training | weblogic server course
 

En vedette

MongoDB Distilled
MongoDB DistilledMongoDB Distilled
MongoDB Distilledb0ris_1
 
Bending Spark towards enterprise needs
Bending Spark towards enterprise needsBending Spark towards enterprise needs
Bending Spark towards enterprise needsb0ris_1
 
Audience counting at Scale
Audience counting at ScaleAudience counting at Scale
Audience counting at Scaleb0ris_1
 
Scalding Big (Ad)ta
Scalding Big (Ad)taScalding Big (Ad)ta
Scalding Big (Ad)tab0ris_1
 
Scalding big ADta
Scalding big ADtaScalding big ADta
Scalding big ADtab0ris_1
 
MySQLドライバの改良と軽量O/Rマッパーの紹介
MySQLドライバの改良と軽量O/Rマッパーの紹介MySQLドライバの改良と軽量O/Rマッパーの紹介
MySQLドライバの改良と軽量O/Rマッパーの紹介kwatch
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashingJohan Tibell
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introductionb0ris_1
 
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
Large Scale Data Analytics with Spark and Cassandra on the DSE PlatformLarge Scale Data Analytics with Spark and Cassandra on the DSE Platform
Large Scale Data Analytics with Spark and Cassandra on the DSE PlatformDataStax Academy
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scalab0ris_1
 
Clustering Java applications with Terracotta and Hazelcast
Clustering Java applications with Terracotta and HazelcastClustering Java applications with Terracotta and Hazelcast
Clustering Java applications with Terracotta and Hazelcastb0ris_1
 
Managing (Schema) Migrations in Cassandra
Managing (Schema) Migrations in CassandraManaging (Schema) Migrations in Cassandra
Managing (Schema) Migrations in CassandraDataStax Academy
 
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!kwatch
 
Spring Bootで変わる Javaアプリ開発! #jsug
Spring Bootで変わる Javaアプリ開発! #jsugSpring Bootで変わる Javaアプリ開発! #jsug
Spring Bootで変わる Javaアプリ開発! #jsugToshiaki Maki
 
リーンキャンバスとは
リーンキャンバスとはリーンキャンバスとは
リーンキャンバスとはStudyTech
 

En vedette (15)

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

Similaire à Continuous DB migration based on carbon5 framework

TheTricky Bits of Deployment Automation
TheTricky Bits of Deployment Automation TheTricky Bits of Deployment Automation
TheTricky Bits of Deployment Automation IBM UrbanCode Products
 
Database CI Demo Using Sql Server
Database CI  Demo Using Sql ServerDatabase CI  Demo Using Sql Server
Database CI Demo Using Sql ServerUmesh Kumar
 
Build on AWS: Migrating And Platforming
Build on AWS: Migrating And PlatformingBuild on AWS: Migrating And Platforming
Build on AWS: Migrating And PlatformingAmazon Web Services
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First MigrationsDiluka99999
 
Build on AWS: Migrating and Platforming
Build on AWS: Migrating and PlatformingBuild on AWS: Migrating and Platforming
Build on AWS: Migrating and PlatformingAmazon Web Services
 
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
DWX 2023 - Datenbank-Schema Deployment im Kubernetes ReleaseDWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
DWX 2023 - Datenbank-Schema Deployment im Kubernetes ReleaseMarc Müller
 
Practical Guidance for SharePoint 2010 Upgrade
Practical Guidance for SharePoint 2010 UpgradePractical Guidance for SharePoint 2010 Upgrade
Practical Guidance for SharePoint 2010 UpgradeJoel Oleson
 
Upgrading to SharePoint 2010 - Teched Middle East
Upgrading to SharePoint 2010 - Teched Middle EastUpgrading to SharePoint 2010 - Teched Middle East
Upgrading to SharePoint 2010 - Teched Middle EastJoel Oleson
 
Migrate Access to SQL Server/Azure
Migrate Access to SQL Server/AzureMigrate Access to SQL Server/Azure
Migrate Access to SQL Server/AzureADNUG
 
Delivering changes for databases and applications
Delivering changes for databases and applicationsDelivering changes for databases and applications
Delivering changes for databases and applicationsEduardo Piairo
 
FlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootFlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootInexture Solutions
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 
Using MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlexUsing MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlexwebhostingguy
 
SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...
SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...
SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...Ivan Sanders
 
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...FIWARE
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaContinuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaDr. John Tunnicliffe
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaContinuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaDr. John Tunnicliffe
 

Similaire à Continuous DB migration based on carbon5 framework (20)

Database CI/CD Pipeline
Database CI/CD PipelineDatabase CI/CD Pipeline
Database CI/CD Pipeline
 
TheTricky Bits of Deployment Automation
TheTricky Bits of Deployment Automation TheTricky Bits of Deployment Automation
TheTricky Bits of Deployment Automation
 
Database CI Demo Using Sql Server
Database CI  Demo Using Sql ServerDatabase CI  Demo Using Sql Server
Database CI Demo Using Sql Server
 
Build on AWS: Migrating And Platforming
Build on AWS: Migrating And PlatformingBuild on AWS: Migrating And Platforming
Build on AWS: Migrating And Platforming
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
 
Build on AWS: Migrating and Platforming
Build on AWS: Migrating and PlatformingBuild on AWS: Migrating and Platforming
Build on AWS: Migrating and Platforming
 
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
DWX 2023 - Datenbank-Schema Deployment im Kubernetes ReleaseDWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
 
Practical Guidance for SharePoint 2010 Upgrade
Practical Guidance for SharePoint 2010 UpgradePractical Guidance for SharePoint 2010 Upgrade
Practical Guidance for SharePoint 2010 Upgrade
 
Upgrading to SharePoint 2010 - Teched Middle East
Upgrading to SharePoint 2010 - Teched Middle EastUpgrading to SharePoint 2010 - Teched Middle East
Upgrading to SharePoint 2010 - Teched Middle East
 
Migrate Access to SQL Server/Azure
Migrate Access to SQL Server/AzureMigrate Access to SQL Server/Azure
Migrate Access to SQL Server/Azure
 
Delivering changes for databases and applications
Delivering changes for databases and applicationsDelivering changes for databases and applications
Delivering changes for databases and applications
 
FlywayDB Migration with Spring Boot
FlywayDB Migration with Spring BootFlywayDB Migration with Spring Boot
FlywayDB Migration with Spring Boot
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Using MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlexUsing MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlex
 
SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...
SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...
SoCalCodeCamp Upgrade Microsoft Office SharePoint Server 2007 to SharePoint S...
 
Praveen Kumar Resume
Praveen Kumar ResumePraveen Kumar Resume
Praveen Kumar Resume
 
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
 
Mobile
MobileMobile
Mobile
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaContinuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaContinuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
 

Plus de b0ris_1

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

Plus de b0ris_1 (8)

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

Dernier

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 2024The Digital Insurer
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - 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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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 WorkerThousandEyes
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Dernier (20)

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
 
+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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - 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...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

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
  • 32.
  • 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
  • 36.
  • 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.