SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Database Change Management
Roger Nilsson, Altran
Rikard Thulin, Squeed
Rikard Thulin
Has been working as a software engineer for 17 years,
mostly as an consultant with focus on the Java platform
e-mail: rikard.thulin@squeed.com, twitter: @rikard_thulin,
blog: http://squeed.com/blog
Roger Nilsson
Has been working as a software engineer and consultant
for 15 years, with focus on the Java platform
e-mail: roger.nilsson@altran.com
About the Presenters
Questions?
Questions during the presentation is
encouraged
There will be a Q&A if time permits at
the end of the presentation
The Question?
You never develop code without version
control,
why would you develop your
database without it?
Liquibase at a glance
Liquibase is an Apache 2.0 Licensed tool for
tracking, managing and applying database
changes
Database changes are stored in an XML (or
JSON, YAML, plain-ish SQL) file that is version
controlled and database independent
Liquibase managed and applies changes to the
database
Major Concepts - Changeset
A changeset is uniquely identified change that
should be applied to the database
When Liquibase runs, it queries the
DATABASECHANGELOG table for the
changesets that are marked as executed and
then executes all changesets that have not yet
been executed
Major Concepts - Changeset
Major Concepts - Changelog file
The changelog file contains Change Sets or
references to other Changelog files
Changelog files can be be arbitrarily nested for
better management
Major Concepts - Changelog file
<databaseChangeLog>
<include file="changelogs/jira-937.xml"/>
<include file="changelogs/jira-1023.xml"/>
<include file="changelogs/jira-1104.xml"/>
<!-- Stored Procedures -->
<include file="procedures/uspUpdateSearchIndex.sql"/>
</databaseChangeLog>
Major Concepts - Changes
Each changeset generally contains a change
which describes the change/refactoring to apply
to the database
Liquibase supports both descriptive changes
that generate SQL for supported databases
and raw SQL
Major Concepts - Changeset
Major Concepts - Preconditions
Preconditions can be applied to either the
changelog as a whole or individual change sets
columnExists, tableExists, viewExists, foreignKeyConstraintExists, sqlCheck, and more...
If a precondition fails, Liquibase will stop
execution
Major Concepts - Contexts
Contexts can be applied to changesets to
control which are ran in different environments
For example, some changesets can be tagged
as "production" and others as "test"
Use Contexts only when there is a good reason
● Update rollbacks
● Database ”diff“s
● Generating starting change logs from
existing databases
● Generating database change documentation
● Code branches and merging
Liquibase feature set
Database Change Management
Database deltas are part of the code change
The correlation between code revisions are
ensured
Allows the automatisation of database changes
Keeps all environments consistent
Allows reverting a previous version of a system
Why Liquibase?
Source Code
Why Liquibase?
8 developers with 8 local databases/schemas
Development server
Test / QA server
CI Server
Staging Server Node 1
Production Node 1
Staging Server Node 2
Production Node 2
Why Liquibase?
8 developers with 8 local databases/schemas
Development server
Test / QA server
CI Server
Staging Server Node 1
Production Node 1
Staging Server Node 2
Production Node 2
The four steps
1. Write your database change set
2. Run Liquibase locally to test the SQL
3. Commit your source code and change set
4. Deploy application and database changes
Liquibase plays well when merging and working
with branches
Structural Refactorings
● Add Column
● Rename Column
● Modify Column
● Drop Column
● Alter Sequence
● Create Table
● Rename Table
● Drop Table
● Create View
● Rename View
● Drop View
● Merge Columns
● Create Stored Procedure
Data Quality Refactorings
● Add Lookup Table
● Add Not-Null Constraint
● Remove Not-Null Constraint
● Add Unique Constraint
● Drop Unique Constraint
● Create Sequence
● Drop Sequence
● Add Auto-Increment
● Add Default Value
● Drop Default Value
Referential Integrity Refactorings
● Add Foreign Key Constraint
● Drop Foreign Key Constraint
● Drop All Foreign Key Constraints
● Add Primary Key Constraint
● Drop Primary Key Constraint
Non-Refactoring Transformations
● Insert Data
● Load Data
● Load Update Data
● Update Data
● Delete Data
● Tag Database
● Stop
Architectural Refactorings
● Create Index
● Drop Index
Custom Refactorings
● Modifying Generated SQL
● Custom SQL
● Custom SQL File
● Custom Refactoring Class
● Execute Shell Command
Supported Refactorings
Running Liquibase
● Manual
○ Command Line
○ Ant
○ Maven
● Automatic
○ Spring
○ Servlet Listener
○ CDI Environment
Tips and Tricks - real life experience
You must have a manual way to run Liquibase
(command line, ant or maven) during
development of changesets
Bundle your database changes into your
deployment artifact (spring, servlet listener or
CDI)
It is (mentally) scary to do, but it works!
Demo
1. Update Database with pending changesets
2. Rollback previous changes
Tips and tricks - structure
Think about the structure of your changelogs
Based on experience, when the changelog xml file is
10.000 lines long it is gets ugly. It is much more difficult
when merging and branching.
Have one master changelog that includes smaller
changelogs in turn, divided by release or issue
changelog.xml changelog.xml
jira-1.xml changelog-1_0.xml
jira-4.xml changelog-1_1.xml
Tips and tricks - structure
Liquibase should foremost be used for structural changes
but it is also possible to use it for configuration data and for
test data
Keep in mind that the use case for these are very different!
● Structural changes should be applied together with the
corresponding code
● Configuration data has en dependency to the database
structure, but is not applied at any time
● Test data has a dependency to the database structure,
may have preconditions and is typically applied by a CI
server nightly
Tips and tricks - structure
● changelog.xml for structural changes, applied when
the system is deployed
● test-data.xml for test data, applied nightly be CI server
● configuration-data.xml for system configuration
changes, applied manually when needed
When executing update or rollback there is a
handy option which do not apply changes
against the database but instead save the
resulting SQL
This can be usable when*
● the resulting SQL needs to be tweeked
● having the SQL approved by a DBA
● SOX compliance.
*) Not a recommended best practices by the authors
Advanced Topics
SQL Output
Generating RFC to DBA automatically using Jenkins
REQUEST FOR CHANGE for sqlserver://sqlprod
Planning:
1. Changeset esc-1729.xml::1::rikard::(Checksum: 3:be601b760eaccc5d864da5b3639bb031)
Reviewed by: rikard
Tested in sqldev, 2013-06-17 23:45:46, OK | Insert Column, New attribute for customer
Tested in sqltest, 2013-06-18 12:10:01, OK | Insert Column, New attribute for customer
Tested in sqlprod , 2013-09-14 20:57:44, OK | Insert Column, New attribute for customer
Implementation:
Run script using Jenkins deploy server
Implementation & Review:
Executed by Jenkins/CI-Server, 2013-09-14 20:57 Scripts successfully applied
Advanced Topics
SQL Output - real life example
Tips and tricks - wrong is right
One of the most difficult challenges is to
overcome “wrong is right” principle
● When a changeset has been committed, it
can not be modified even if it is “wrong”
● You must write another changeset to correct
the previous one
● The “wrong” changeset will hit your
production database followed by the “right”
changeset
Tips and tricks - stored procedure
If you have stored procedures the should
obviously be versioned controlled
But the CRC does not fit well as that requires
the stored procedure to be repeated for every
modification
The “run always” attribute saves the day. This
will make sure that whenever there is a change
it is applied -- a better fit for stored procedures
Tips and tricks - stored procedures
--liquibase formatted sql
--changeset rikard:1 runOnChange:true
ALTER procedure javaforum
…
● Above we use a plain sql file with two special
comments that magically makes it a
changeset
Demo
Stored procedure
1. Update database with plain SQL file
2. Change procedure and update again..
Tips and Tricks - neutralizing data
● The “run always” attribute can also be used
to neutralize data in dev and test
environments
● Useful in cases when the database is copied
for production to other environments
● The changes that has been applied is stored
in the database itself, therefore it is safe to
copy clone a database
Tips and Tricks - neutralizing data
<changeSet id="1" author="joe" runAlways="true"
context="sqld,sqlt,localhost">
<comment>Change users psw on (localhost, dev, test) to
'Secret' and their email to 'test@jforum.se'</comment>
<update tableName="user">
<column name="email" value="test@jforum.se"/>
<column name="password" value="Secret"/>
<where>email != 'test@jforum.se' OR password !=
'Secret'</where>
</update>
</changeSet>
Real life experience
We have used Liquibase in projects for many years, more
than 50 man years of development with very little problems
Overall score 97%
by Roger and Rikard
Alternatives
● Flyway
● c5-db-migration
● dbdeploy
● mybatis
● MIGRATEdb
● migrate4j
● dbmaintain
● AutoPatch
Q & A

Contenu connexe

Tendances

Liquibase for java developers
Liquibase for java developersLiquibase for java developers
Liquibase for java developersIllia Seleznov
 
Liquibase migration for data bases
Liquibase migration for data basesLiquibase migration for data bases
Liquibase migration for data basesRoman Uholnikov
 
Liquibase – a time machine for your data
Liquibase – a time machine for your dataLiquibase – a time machine for your data
Liquibase – a time machine for your dataNeev Technologies
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaAxel Fontaine
 
Agile Database Development with Liquibase
Agile Database Development with LiquibaseAgile Database Development with Liquibase
Agile Database Development with LiquibaseTim Berglund
 
Database migrations with Flyway and Liquibase
Database migrations with Flyway and LiquibaseDatabase migrations with Flyway and Liquibase
Database migrations with Flyway and LiquibaseLars Östling
 
Successful DB migrations with Liquibase
 Successful DB migrations with Liquibase Successful DB migrations with Liquibase
Successful DB migrations with LiquibaseIllia Seleznov
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flywayJonathan Holloway
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 
Liquibase - Open Source version control for your database
Liquibase - Open Source version control for your databaseLiquibase - Open Source version control for your database
Liquibase - Open Source version control for your databaseBlaine Carter
 
Liquidating database frustrations with liquibase
Liquidating database frustrations with liquibaseLiquidating database frustrations with liquibase
Liquidating database frustrations with liquibasePaul Churchward
 
New awesome features in MySQL 5.7
New awesome features in MySQL 5.7New awesome features in MySQL 5.7
New awesome features in MySQL 5.7Zhaoyang Wang
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum versionsqlserver.co.il
 
Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...
Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...
Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...Andrejs Prokopjevs
 
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...Dave Stokes
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 

Tendances (20)

Liquibase for java developers
Liquibase for java developersLiquibase for java developers
Liquibase for java developers
 
Database change management with Liquibase
Database change management with LiquibaseDatabase change management with Liquibase
Database change management with Liquibase
 
Liquibase case study
Liquibase case studyLiquibase case study
Liquibase case study
 
Liquibase migration for data bases
Liquibase migration for data basesLiquibase migration for data bases
Liquibase migration for data bases
 
Liquibase – a time machine for your data
Liquibase – a time machine for your dataLiquibase – a time machine for your data
Liquibase – a time machine for your data
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for Java
 
Agile Database Development with Liquibase
Agile Database Development with LiquibaseAgile Database Development with Liquibase
Agile Database Development with Liquibase
 
Database migrations with Flyway and Liquibase
Database migrations with Flyway and LiquibaseDatabase migrations with Flyway and Liquibase
Database migrations with Flyway and Liquibase
 
Successful DB migrations with Liquibase
 Successful DB migrations with Liquibase Successful DB migrations with Liquibase
Successful DB migrations with Liquibase
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flyway
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Liquibase - Open Source version control for your database
Liquibase - Open Source version control for your databaseLiquibase - Open Source version control for your database
Liquibase - Open Source version control for your database
 
Liquidating database frustrations with liquibase
Liquidating database frustrations with liquibaseLiquidating database frustrations with liquibase
Liquidating database frustrations with liquibase
 
Oozie meetup - HA
Oozie meetup - HAOozie meetup - HA
Oozie meetup - HA
 
New awesome features in MySQL 5.7
New awesome features in MySQL 5.7New awesome features in MySQL 5.7
New awesome features in MySQL 5.7
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum version
 
Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...
Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...
Oracle Unified Directory. Lessons learnt. Is it ready for a move from OID? (O...
 
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
 
October 2014 HUG : Oozie HA
October 2014 HUG : Oozie HAOctober 2014 HUG : Oozie HA
October 2014 HUG : Oozie HA
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 

En vedette

Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With LiquibaseTim Berglund
 
Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With LiquibaseIASA
 
Database Change Management
Database Change ManagementDatabase Change Management
Database Change ManagementDominik Hirt
 
Last Month in PHP - February 2017
Last Month in PHP - February 2017Last Month in PHP - February 2017
Last Month in PHP - February 2017Eric Poe
 
Getting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGetting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGirish Bapat
 
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der DatenbankmigrationstoolsJavaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der DatenbankmigrationstoolsStephan Kaps
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDan Stine
 

En vedette (8)

Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With Liquibase
 
Database Refactoring With Liquibase
Database Refactoring With LiquibaseDatabase Refactoring With Liquibase
Database Refactoring With Liquibase
 
Database Change Management
Database Change ManagementDatabase Change Management
Database Change Management
 
Last Month in PHP - February 2017
Last Month in PHP - February 2017Last Month in PHP - February 2017
Last Month in PHP - February 2017
 
Mini Training Flyway
Mini Training FlywayMini Training Flyway
Mini Training Flyway
 
Getting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGetting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydb
 
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der DatenbankmigrationstoolsJavaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and Liquibase
 

Similaire à Liquibase få kontroll på dina databasförändringar

KoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT_Session2_SDNEvent_SourceControlForDBAKoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT_Session2_SDNEvent_SourceControlForDBATobias Koprowski
 
Liquibase Integration with MuleSoft
Liquibase Integration with MuleSoftLiquibase Integration with MuleSoft
Liquibase Integration with MuleSoftNeerajKumar1965
 
Schema migration in agile environmnets
Schema migration in agile environmnetsSchema migration in agile environmnets
Schema migration in agile environmnetsVivek Dhayalan
 
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
 
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3MysoreMuleSoftMeetup
 
Database Build and Release - SQL In The City - Ernest Hwang
Database Build and Release - SQL In The City - Ernest HwangDatabase Build and Release - SQL In The City - Ernest Hwang
Database Build and Release - SQL In The City - Ernest HwangRed Gate Software
 
Microsoft SQL Server Continuous Integration
Microsoft SQL Server Continuous IntegrationMicrosoft SQL Server Continuous Integration
Microsoft SQL Server Continuous IntegrationMark Ginnebaugh
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDAGEOP LTD
 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMonica Li
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMonica Li
 
Upgrading to my sql 8.0
Upgrading to my sql 8.0Upgrading to my sql 8.0
Upgrading to my sql 8.0Ståle Deraas
 
What's New in MySQL 5.7
What's New in MySQL 5.7What's New in MySQL 5.7
What's New in MySQL 5.7Olivier DASINI
 
MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015Mario Beck
 
Remote DBA Experts 11g Features
Remote DBA Experts 11g FeaturesRemote DBA Experts 11g Features
Remote DBA Experts 11g FeaturesRemote DBA Experts
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresJitendra Singh
 
Database automated build and test - SQL In The City Cambridge
Database automated build and test - SQL In The City CambridgeDatabase automated build and test - SQL In The City Cambridge
Database automated build and test - SQL In The City CambridgeRed Gate Software
 
Why retail companies can't afford database downtime
Why retail companies can't afford database downtimeWhy retail companies can't afford database downtime
Why retail companies can't afford database downtimeDBmaestro - Database DevOps
 
Evolutionary database design
Evolutionary database designEvolutionary database design
Evolutionary database designSalehein Syed
 
SQL Server DevOps Jumpstart
SQL Server DevOps JumpstartSQL Server DevOps Jumpstart
SQL Server DevOps JumpstartOri Donner
 

Similaire à Liquibase få kontroll på dina databasförändringar (20)

KoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT_Session2_SDNEvent_SourceControlForDBAKoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
 
Liquibase Integration with MuleSoft
Liquibase Integration with MuleSoftLiquibase Integration with MuleSoft
Liquibase Integration with MuleSoft
 
Schema migration in agile environmnets
Schema migration in agile environmnetsSchema migration in agile environmnets
Schema migration in agile environmnets
 
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
 
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
 
Database CI/CD Pipeline
Database CI/CD PipelineDatabase CI/CD Pipeline
Database CI/CD Pipeline
 
Database Build and Release - SQL In The City - Ernest Hwang
Database Build and Release - SQL In The City - Ernest HwangDatabase Build and Release - SQL In The City - Ernest Hwang
Database Build and Release - SQL In The City - Ernest Hwang
 
Microsoft SQL Server Continuous Integration
Microsoft SQL Server Continuous IntegrationMicrosoft SQL Server Continuous Integration
Microsoft SQL Server Continuous Integration
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance Analysis
 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical Examples
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your Data
 
Upgrading to my sql 8.0
Upgrading to my sql 8.0Upgrading to my sql 8.0
Upgrading to my sql 8.0
 
What's New in MySQL 5.7
What's New in MySQL 5.7What's New in MySQL 5.7
What's New in MySQL 5.7
 
MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015
 
Remote DBA Experts 11g Features
Remote DBA Experts 11g FeaturesRemote DBA Experts 11g Features
Remote DBA Experts 11g Features
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
Database automated build and test - SQL In The City Cambridge
Database automated build and test - SQL In The City CambridgeDatabase automated build and test - SQL In The City Cambridge
Database automated build and test - SQL In The City Cambridge
 
Why retail companies can't afford database downtime
Why retail companies can't afford database downtimeWhy retail companies can't afford database downtime
Why retail companies can't afford database downtime
 
Evolutionary database design
Evolutionary database designEvolutionary database design
Evolutionary database design
 
SQL Server DevOps Jumpstart
SQL Server DevOps JumpstartSQL Server DevOps Jumpstart
SQL Server DevOps Jumpstart
 

Plus de Squeed

Efficient Code Organisation
Efficient Code OrganisationEfficient Code Organisation
Efficient Code OrganisationSqueed
 
Groovy moppingjavaforum
Groovy moppingjavaforumGroovy moppingjavaforum
Groovy moppingjavaforumSqueed
 
Refactoring toward deeper insight java forum
Refactoring toward deeper insight   java forumRefactoring toward deeper insight   java forum
Refactoring toward deeper insight java forumSqueed
 
Javaforum looking into the memory
Javaforum   looking into the memoryJavaforum   looking into the memory
Javaforum looking into the memorySqueed
 
Personal kaizen
Personal kaizenPersonal kaizen
Personal kaizenSqueed
 
Java one 2011_v0.9
Java one 2011_v0.9Java one 2011_v0.9
Java one 2011_v0.9Squeed
 
Javaforum coin
Javaforum coinJavaforum coin
Javaforum coinSqueed
 
Javaforum indy
Javaforum indyJavaforum indy
Javaforum indySqueed
 
Javaforum 20110915
Javaforum 20110915Javaforum 20110915
Javaforum 20110915Squeed
 

Plus de Squeed (9)

Efficient Code Organisation
Efficient Code OrganisationEfficient Code Organisation
Efficient Code Organisation
 
Groovy moppingjavaforum
Groovy moppingjavaforumGroovy moppingjavaforum
Groovy moppingjavaforum
 
Refactoring toward deeper insight java forum
Refactoring toward deeper insight   java forumRefactoring toward deeper insight   java forum
Refactoring toward deeper insight java forum
 
Javaforum looking into the memory
Javaforum   looking into the memoryJavaforum   looking into the memory
Javaforum looking into the memory
 
Personal kaizen
Personal kaizenPersonal kaizen
Personal kaizen
 
Java one 2011_v0.9
Java one 2011_v0.9Java one 2011_v0.9
Java one 2011_v0.9
 
Javaforum coin
Javaforum coinJavaforum coin
Javaforum coin
 
Javaforum indy
Javaforum indyJavaforum indy
Javaforum indy
 
Javaforum 20110915
Javaforum 20110915Javaforum 20110915
Javaforum 20110915
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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)wesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Liquibase få kontroll på dina databasförändringar

  • 1. Database Change Management Roger Nilsson, Altran Rikard Thulin, Squeed
  • 2. Rikard Thulin Has been working as a software engineer for 17 years, mostly as an consultant with focus on the Java platform e-mail: rikard.thulin@squeed.com, twitter: @rikard_thulin, blog: http://squeed.com/blog Roger Nilsson Has been working as a software engineer and consultant for 15 years, with focus on the Java platform e-mail: roger.nilsson@altran.com About the Presenters
  • 3. Questions? Questions during the presentation is encouraged There will be a Q&A if time permits at the end of the presentation
  • 4. The Question? You never develop code without version control, why would you develop your database without it?
  • 5. Liquibase at a glance Liquibase is an Apache 2.0 Licensed tool for tracking, managing and applying database changes Database changes are stored in an XML (or JSON, YAML, plain-ish SQL) file that is version controlled and database independent Liquibase managed and applies changes to the database
  • 6. Major Concepts - Changeset A changeset is uniquely identified change that should be applied to the database When Liquibase runs, it queries the DATABASECHANGELOG table for the changesets that are marked as executed and then executes all changesets that have not yet been executed
  • 7. Major Concepts - Changeset
  • 8. Major Concepts - Changelog file The changelog file contains Change Sets or references to other Changelog files Changelog files can be be arbitrarily nested for better management
  • 9. Major Concepts - Changelog file <databaseChangeLog> <include file="changelogs/jira-937.xml"/> <include file="changelogs/jira-1023.xml"/> <include file="changelogs/jira-1104.xml"/> <!-- Stored Procedures --> <include file="procedures/uspUpdateSearchIndex.sql"/> </databaseChangeLog>
  • 10. Major Concepts - Changes Each changeset generally contains a change which describes the change/refactoring to apply to the database Liquibase supports both descriptive changes that generate SQL for supported databases and raw SQL
  • 11. Major Concepts - Changeset
  • 12. Major Concepts - Preconditions Preconditions can be applied to either the changelog as a whole or individual change sets columnExists, tableExists, viewExists, foreignKeyConstraintExists, sqlCheck, and more... If a precondition fails, Liquibase will stop execution
  • 13. Major Concepts - Contexts Contexts can be applied to changesets to control which are ran in different environments For example, some changesets can be tagged as "production" and others as "test" Use Contexts only when there is a good reason
  • 14. ● Update rollbacks ● Database ”diff“s ● Generating starting change logs from existing databases ● Generating database change documentation ● Code branches and merging Liquibase feature set
  • 15. Database Change Management Database deltas are part of the code change The correlation between code revisions are ensured Allows the automatisation of database changes Keeps all environments consistent Allows reverting a previous version of a system
  • 17. Why Liquibase? 8 developers with 8 local databases/schemas Development server Test / QA server CI Server Staging Server Node 1 Production Node 1 Staging Server Node 2 Production Node 2
  • 18. Why Liquibase? 8 developers with 8 local databases/schemas Development server Test / QA server CI Server Staging Server Node 1 Production Node 1 Staging Server Node 2 Production Node 2
  • 19. The four steps 1. Write your database change set 2. Run Liquibase locally to test the SQL 3. Commit your source code and change set 4. Deploy application and database changes Liquibase plays well when merging and working with branches
  • 20. Structural Refactorings ● Add Column ● Rename Column ● Modify Column ● Drop Column ● Alter Sequence ● Create Table ● Rename Table ● Drop Table ● Create View ● Rename View ● Drop View ● Merge Columns ● Create Stored Procedure Data Quality Refactorings ● Add Lookup Table ● Add Not-Null Constraint ● Remove Not-Null Constraint ● Add Unique Constraint ● Drop Unique Constraint ● Create Sequence ● Drop Sequence ● Add Auto-Increment ● Add Default Value ● Drop Default Value Referential Integrity Refactorings ● Add Foreign Key Constraint ● Drop Foreign Key Constraint ● Drop All Foreign Key Constraints ● Add Primary Key Constraint ● Drop Primary Key Constraint Non-Refactoring Transformations ● Insert Data ● Load Data ● Load Update Data ● Update Data ● Delete Data ● Tag Database ● Stop Architectural Refactorings ● Create Index ● Drop Index Custom Refactorings ● Modifying Generated SQL ● Custom SQL ● Custom SQL File ● Custom Refactoring Class ● Execute Shell Command Supported Refactorings
  • 21. Running Liquibase ● Manual ○ Command Line ○ Ant ○ Maven ● Automatic ○ Spring ○ Servlet Listener ○ CDI Environment
  • 22. Tips and Tricks - real life experience You must have a manual way to run Liquibase (command line, ant or maven) during development of changesets Bundle your database changes into your deployment artifact (spring, servlet listener or CDI) It is (mentally) scary to do, but it works!
  • 23. Demo 1. Update Database with pending changesets 2. Rollback previous changes
  • 24. Tips and tricks - structure Think about the structure of your changelogs Based on experience, when the changelog xml file is 10.000 lines long it is gets ugly. It is much more difficult when merging and branching. Have one master changelog that includes smaller changelogs in turn, divided by release or issue changelog.xml changelog.xml jira-1.xml changelog-1_0.xml jira-4.xml changelog-1_1.xml
  • 25. Tips and tricks - structure Liquibase should foremost be used for structural changes but it is also possible to use it for configuration data and for test data Keep in mind that the use case for these are very different! ● Structural changes should be applied together with the corresponding code ● Configuration data has en dependency to the database structure, but is not applied at any time ● Test data has a dependency to the database structure, may have preconditions and is typically applied by a CI server nightly
  • 26. Tips and tricks - structure ● changelog.xml for structural changes, applied when the system is deployed ● test-data.xml for test data, applied nightly be CI server ● configuration-data.xml for system configuration changes, applied manually when needed
  • 27. When executing update or rollback there is a handy option which do not apply changes against the database but instead save the resulting SQL This can be usable when* ● the resulting SQL needs to be tweeked ● having the SQL approved by a DBA ● SOX compliance. *) Not a recommended best practices by the authors Advanced Topics SQL Output
  • 28. Generating RFC to DBA automatically using Jenkins REQUEST FOR CHANGE for sqlserver://sqlprod Planning: 1. Changeset esc-1729.xml::1::rikard::(Checksum: 3:be601b760eaccc5d864da5b3639bb031) Reviewed by: rikard Tested in sqldev, 2013-06-17 23:45:46, OK | Insert Column, New attribute for customer Tested in sqltest, 2013-06-18 12:10:01, OK | Insert Column, New attribute for customer Tested in sqlprod , 2013-09-14 20:57:44, OK | Insert Column, New attribute for customer Implementation: Run script using Jenkins deploy server Implementation & Review: Executed by Jenkins/CI-Server, 2013-09-14 20:57 Scripts successfully applied Advanced Topics SQL Output - real life example
  • 29. Tips and tricks - wrong is right One of the most difficult challenges is to overcome “wrong is right” principle ● When a changeset has been committed, it can not be modified even if it is “wrong” ● You must write another changeset to correct the previous one ● The “wrong” changeset will hit your production database followed by the “right” changeset
  • 30. Tips and tricks - stored procedure If you have stored procedures the should obviously be versioned controlled But the CRC does not fit well as that requires the stored procedure to be repeated for every modification The “run always” attribute saves the day. This will make sure that whenever there is a change it is applied -- a better fit for stored procedures
  • 31. Tips and tricks - stored procedures --liquibase formatted sql --changeset rikard:1 runOnChange:true ALTER procedure javaforum … ● Above we use a plain sql file with two special comments that magically makes it a changeset
  • 32. Demo Stored procedure 1. Update database with plain SQL file 2. Change procedure and update again..
  • 33. Tips and Tricks - neutralizing data ● The “run always” attribute can also be used to neutralize data in dev and test environments ● Useful in cases when the database is copied for production to other environments ● The changes that has been applied is stored in the database itself, therefore it is safe to copy clone a database
  • 34. Tips and Tricks - neutralizing data <changeSet id="1" author="joe" runAlways="true" context="sqld,sqlt,localhost"> <comment>Change users psw on (localhost, dev, test) to 'Secret' and their email to 'test@jforum.se'</comment> <update tableName="user"> <column name="email" value="test@jforum.se"/> <column name="password" value="Secret"/> <where>email != 'test@jforum.se' OR password != 'Secret'</where> </update> </changeSet>
  • 35. Real life experience We have used Liquibase in projects for many years, more than 50 man years of development with very little problems Overall score 97% by Roger and Rikard
  • 36. Alternatives ● Flyway ● c5-db-migration ● dbdeploy ● mybatis ● MIGRATEdb ● migrate4j ● dbmaintain ● AutoPatch
  • 37. Q & A