SlideShare a Scribd company logo
DATABASE SOURCE CONTROL Eduardo Piairo
Migrations vs State
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
• Eduardo Piairo
• @ Celfinet
• DBA
• DevOps
About me
@EdPiairo
https://pt.linkedin.com/in/jesuspiairo
eduardopiairo@outlook.com
http://www.eduardopiairo.com/
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Introduction
Source
Control
Continuous
Integration
Continuous
Delivery
Database
+
Application
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
What’s so special about databases?
Introduction
DLM – Database Lifecycle Management
• Data management and data migration
• Data monitoring
• Data recovery
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Why database source control?
• First step for database automation
• Share code (SQL scripts)
• Keep history of each change
• Your best communication system
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Migrations-based approach vs State-based approach
• Fundamental resource - SQL Script
• State based solutions
• Script represents the current database state
• Migrations based solutions
• Script represents a migration
• Migration represents how to transition to the next database version
State: Your source of truth is how the database should be
Migrations: Your source of truth is how the database should change
Alex Yates, Pre-sales engineer at Redgate
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Flyway
• Flyway – “Database migrations made easy”
• http://flywaydb.org/
• Open source database migration tool
• My reasons for adopting Flyway (command-line)
• Simplicity: easy to setup, no need to install
• Zero dependencies (java + jdbc)
• Scripts are written in SQL
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Flyway – Why database migrations?
• Migrations
• Recreate a database from scratch
• Make it clear at all time what state a database is in
• Migrate in a deterministic way from your current version of the database to a newer one
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Flyway – How it works?
• Flyway commands
• Migrate, clean info, validate, baseline repair
• Metadata table
• Used to track the state of the database
• Default name: “schema_version”
• If the database is empty, flyway won’t find it and will create it
• Flyway scans the migrations directory and check migrations against the metadata table
• Migrations are sorted based on their version number and applied in order
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Flyway – Demo
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
SQL Source Control
• SQL Source Control
• Add-in for Management Studio that links your database to your source control system
• Ability to source control schemas and reference data
• Source control systems: Git, Mercurial, TFS , Subversion
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
SQL Source Control – How it works
• SQL Compare
• Compares Git repository (your source of truth) against the target database
• Schema and data reference
• Database objects
• Static data
• Referential integrity (keys and constraints)
• Roll back changes
• Lock objects
• Apply filters to database objects
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
SQL Source Control – Demo
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Migrations-based approach vs State-based approach
• Scripts are imperative
• Each script/change is applied, in order, on the target
database
• High level of granularity
• SQL developers define change scripts upfront and have
full control over how changes are deployed
Flyway + git
• Scripts are declarative
• Compares two states (source and target) and generates a
change script
• The big picture
• Dependencies management
• Comparison engine – SQL Compare (schema and reference
data)
SQL Source Control + git
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Migrations-based approach vs State-based approach
Flyway + git SQL Source Control + git
• Scripts must be idempotent and immutable (runs 1 time
only)
• “Changes will only be made through migration tool
itself?”
• Tracking changes
• Enables continuous integration and continuous delivery
• SQL Server Management Studio
• Drop and recreate advantage
• Tracking changes
• Enables continuous integration and continuous delivery
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Migrations-based approach vs State-based approach – HOTFIX challenge
Flyway + git SQL Source Control + git
• Ignore the hotfix
• Deployment can fail or pass
• You will never find out, until you have a
problem
• Roll back the hotfix
• Target database would look like the version in
development that did not have the fix
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Migrations-based approach vs State-based approach – Tools
Migrations State
Flyway ReadyRoll
SQL
Source Control
SSDT
Database Projects
DbUp
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Migrations-based approach vs State-based approach
• Which one is better?
• Size of the database
• Complexity of the database
• Team’s capabilities or preferences
• Team’s development processes
Both approaches may be needed for different parts of the system, or at different times in
the development process.
DATABASE SOURCE CONTROL– MIGRATIONS VS STATE
Q&A
@EdPiairo
https://pt.linkedin.com/in/jesuspiairo
eduardopiairo@outlook.com
http://www.eduardopiairo.com/

More Related Content

PPTX
Database Source Control: Migrations vs State
PDF
Delivering changes for applications and databases
PDF
DbOps, DevOps and Ops
PDF
Road to database automation - Database source control
PDF
Road to database automation: database source control
PDF
Road to database automation: database source control
PDF
Delivering Changes for Applications and Databases
PPTX
Your API is Bad and You Should Feel Bad
Database Source Control: Migrations vs State
Delivering changes for applications and databases
DbOps, DevOps and Ops
Road to database automation - Database source control
Road to database automation: database source control
Road to database automation: database source control
Delivering Changes for Applications and Databases
Your API is Bad and You Should Feel Bad

What's hot (20)

PDF
Road to database automation: database source control
PDF
Delivering changes for applications and databases @ Azure
PDF
David Max SATURN 2018 - Migrating from Oracle to Espresso
PDF
Delivering changes for databases and applications
PPTX
EAD3 Progress Report 2014-08-13
PDF
Plug saiku
PPTX
Bringing DevOps to the Database
PPTX
SenchaCon 2016: Oracle Forms Modernisation - Owen Pagan
PDF
Apache Kafka and API Management / API Gateway – Friends, Enemies or Frenemies...
PPTX
Building Ext JS Using HATEOAS - Jeff Stano
PDF
Fashiolista
PPTX
Cross-platform interaction
PPT
introduction v4
PPTX
Performance metrics for a social network
PPTX
Antelope: A Web service for publishing Life Cycle Assessment models and resul...
PPTX
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
PPTX
Intro to API Design Principles
PDF
How to prepare your site for content migration
PPTX
Effective Microservices In a Data-centric World
Road to database automation: database source control
Delivering changes for applications and databases @ Azure
David Max SATURN 2018 - Migrating from Oracle to Espresso
Delivering changes for databases and applications
EAD3 Progress Report 2014-08-13
Plug saiku
Bringing DevOps to the Database
SenchaCon 2016: Oracle Forms Modernisation - Owen Pagan
Apache Kafka and API Management / API Gateway – Friends, Enemies or Frenemies...
Building Ext JS Using HATEOAS - Jeff Stano
Fashiolista
Cross-platform interaction
introduction v4
Performance metrics for a social network
Antelope: A Web service for publishing Life Cycle Assessment models and resul...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Intro to API Design Principles
How to prepare your site for content migration
Effective Microservices In a Data-centric World
Ad

Viewers also liked (20)

PPTX
Fm wtm12-v2
PPTX
opt-mem-trx
PDF
33rd degree talk: open and automatic coding conventions with walkmod
PPTX
The Challenges & Pitfalls of Database Continuous Delivery
PPTX
Challenges and best practices of database continuous delivery
PPTX
Building Solutions with Office Graph
PDF
walkmod: how it works
PDF
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
PDF
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
PDF
Database version control without pain - the PHPNW10 version
PPTX
Flyway (33rd Degree)
PDF
KYSUC - Keep Your Schema Under Control
PDF
Building Rich Domain Models
PDF
Database migration with flyway
PDF
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
ODP
Liquibase & Flyway @ Baltic DevOps
PDF
Database Schema Evolution
PDF
Database security issues
PDF
Database migrations with Flyway and Liquibase
Fm wtm12-v2
opt-mem-trx
33rd degree talk: open and automatic coding conventions with walkmod
The Challenges & Pitfalls of Database Continuous Delivery
Challenges and best practices of database continuous delivery
Building Solutions with Office Graph
walkmod: how it works
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
Database version control without pain - the PHPNW10 version
Flyway (33rd Degree)
KYSUC - Keep Your Schema Under Control
Building Rich Domain Models
Database migration with flyway
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Liquibase & Flyway @ Baltic DevOps
Database Schema Evolution
Database security issues
Database migrations with Flyway and Liquibase
Ad

Similar to Database Source Control: Migrations vs State (20)

PDF
Database Source Control: Migrations vs State
PPTX
Database CI/CD Pipeline
PDF
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
PDF
Flyway _ A Database Version Management Tool
PPTX
DevOps+Data: Working with Source Control
PPTX
Part of the DLM story: Get your Database under Source Control - SQL In The City
PPTX
Getting CI right for SQL Server
PDF
Are we there Yet?? (The long journey of Migrating from close source to opens...
PDF
Automated Build and Test (for Continuous Integration) - David Atkinson - SQL ...
PDF
Migrating from PostgreSQL to MySQL Without Downtime
PPTX
#DOAW16 - DevOps@work Roma 2016 - Databases under source control
PDF
Database Source Control
PPTX
Getting CI right for SQL Server
PPTX
Evolutionary database design
PDF
SQL Server Source Control Basics
PPTX
SQL in Version Control using SQL Server Database Projects
PDF
Migración desde BBDD propietarias a MariaDB
PDF
[db tech showcase Tokyo 2017] C34: Replacing Oracle Database at DBS Bank ~Ora...
PPT
Manager's Guide To Oracle Cost Containment
 
PPTX
Evolutionary database design
Database Source Control: Migrations vs State
Database CI/CD Pipeline
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
Flyway _ A Database Version Management Tool
DevOps+Data: Working with Source Control
Part of the DLM story: Get your Database under Source Control - SQL In The City
Getting CI right for SQL Server
Are we there Yet?? (The long journey of Migrating from close source to opens...
Automated Build and Test (for Continuous Integration) - David Atkinson - SQL ...
Migrating from PostgreSQL to MySQL Without Downtime
#DOAW16 - DevOps@work Roma 2016 - Databases under source control
Database Source Control
Getting CI right for SQL Server
Evolutionary database design
SQL Server Source Control Basics
SQL in Version Control using SQL Server Database Projects
Migración desde BBDD propietarias a MariaDB
[db tech showcase Tokyo 2017] C34: Replacing Oracle Database at DBS Bank ~Ora...
Manager's Guide To Oracle Cost Containment
 
Evolutionary database design

More from Eduardo Piairo (18)

PDF
ADDO 2021: Why and how to include database changes in the deployment pipeline
PDF
Adding unit tests to the database deployment pipeline
PDF
Start by changing the way of work
PDF
Adding unit tests to the database deployment pipeline
PDF
Adding unit tests with tSQLt to the database deployment pipeline
PDF
Adding unit tests with tSQLt to the database deployment pipeline
PDF
Operations for databases – The DevOps journey
PDF
Deployment pipeline for databases
PDF
Deployment pipeline for databases
PDF
Adding unit tests with tSQLt to the database deployment pipeline
PDF
Operations for databases: the agile/devops journey
PDF
Setting a WordPress website using Azure Web Apps And Azure Database for MySQL
PDF
SQL Server 2017 CLR
PDF
SQL Server 2017 CLR
PDF
Deployment pipeline for Azure SQL Databases
PDF
Operations for databases – the agile/devops journey
PDF
Workshop: Delivering chnages for applications and databases
PDF
Deployment Pipeline for databases (Azure SQL Database, SQL Server)
ADDO 2021: Why and how to include database changes in the deployment pipeline
Adding unit tests to the database deployment pipeline
Start by changing the way of work
Adding unit tests to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
Operations for databases – The DevOps journey
Deployment pipeline for databases
Deployment pipeline for databases
Adding unit tests with tSQLt to the database deployment pipeline
Operations for databases: the agile/devops journey
Setting a WordPress website using Azure Web Apps And Azure Database for MySQL
SQL Server 2017 CLR
SQL Server 2017 CLR
Deployment pipeline for Azure SQL Databases
Operations for databases – the agile/devops journey
Workshop: Delivering chnages for applications and databases
Deployment Pipeline for databases (Azure SQL Database, SQL Server)

Recently uploaded (20)

PPTX
Save Business Costs with CRM Software for Insurance Agents
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
DOCX
The Five Best AI Cover Tools in 2025.docx
PPTX
Introduction to Artificial Intelligence
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
PDF
AI in Product Development-omnex systems
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PDF
Forouzan Book Information Security Chaper - 1
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PDF
Jenkins: An open-source automation server powering CI/CD Automation
PPTX
ai tools demonstartion for schools and inter college
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPT
JAVA ppt tutorial basics to learn java programming
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
Save Business Costs with CRM Software for Insurance Agents
How a Careem Clone App Allows You to Compete with Large Mobility Brands
The Five Best AI Cover Tools in 2025.docx
Introduction to Artificial Intelligence
ManageIQ - Sprint 268 Review - Slide Deck
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
AI in Product Development-omnex systems
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Forouzan Book Information Security Chaper - 1
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
Jenkins: An open-source automation server powering CI/CD Automation
ai tools demonstartion for schools and inter college
Best Practices for Rolling Out Competency Management Software.pdf
Online Work Permit System for Fast Permit Processing
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Upgrade and Innovation Strategies for SAP ERP Customers
JAVA ppt tutorial basics to learn java programming
Materi-Enum-and-Record-Data-Type (1).pptx

Database Source Control: Migrations vs State

  • 1. DATABASE SOURCE CONTROL Eduardo Piairo Migrations vs State
  • 2. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE • Eduardo Piairo • @ Celfinet • DBA • DevOps About me @EdPiairo https://pt.linkedin.com/in/jesuspiairo [email protected] http://www.eduardopiairo.com/
  • 3. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Introduction Source Control Continuous Integration Continuous Delivery Database + Application
  • 4. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE What’s so special about databases? Introduction DLM – Database Lifecycle Management • Data management and data migration • Data monitoring • Data recovery
  • 5. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Why database source control? • First step for database automation • Share code (SQL scripts) • Keep history of each change • Your best communication system
  • 6. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach • Fundamental resource - SQL Script • State based solutions • Script represents the current database state • Migrations based solutions • Script represents a migration • Migration represents how to transition to the next database version State: Your source of truth is how the database should be Migrations: Your source of truth is how the database should change Alex Yates, Pre-sales engineer at Redgate
  • 7. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Flyway • Flyway – “Database migrations made easy” • http://flywaydb.org/ • Open source database migration tool • My reasons for adopting Flyway (command-line) • Simplicity: easy to setup, no need to install • Zero dependencies (java + jdbc) • Scripts are written in SQL
  • 8. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Flyway – Why database migrations? • Migrations • Recreate a database from scratch • Make it clear at all time what state a database is in • Migrate in a deterministic way from your current version of the database to a newer one
  • 9. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Flyway – How it works? • Flyway commands • Migrate, clean info, validate, baseline repair • Metadata table • Used to track the state of the database • Default name: “schema_version” • If the database is empty, flyway won’t find it and will create it • Flyway scans the migrations directory and check migrations against the metadata table • Migrations are sorted based on their version number and applied in order
  • 10. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Flyway – Demo
  • 11. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE SQL Source Control • SQL Source Control • Add-in for Management Studio that links your database to your source control system • Ability to source control schemas and reference data • Source control systems: Git, Mercurial, TFS , Subversion
  • 12. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE SQL Source Control – How it works • SQL Compare • Compares Git repository (your source of truth) against the target database • Schema and data reference • Database objects • Static data • Referential integrity (keys and constraints) • Roll back changes • Lock objects • Apply filters to database objects
  • 13. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE SQL Source Control – Demo
  • 14. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach • Scripts are imperative • Each script/change is applied, in order, on the target database • High level of granularity • SQL developers define change scripts upfront and have full control over how changes are deployed Flyway + git • Scripts are declarative • Compares two states (source and target) and generates a change script • The big picture • Dependencies management • Comparison engine – SQL Compare (schema and reference data) SQL Source Control + git
  • 15. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach Flyway + git SQL Source Control + git • Scripts must be idempotent and immutable (runs 1 time only) • “Changes will only be made through migration tool itself?” • Tracking changes • Enables continuous integration and continuous delivery • SQL Server Management Studio • Drop and recreate advantage • Tracking changes • Enables continuous integration and continuous delivery
  • 16. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach – HOTFIX challenge Flyway + git SQL Source Control + git • Ignore the hotfix • Deployment can fail or pass • You will never find out, until you have a problem • Roll back the hotfix • Target database would look like the version in development that did not have the fix
  • 17. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach – Tools Migrations State Flyway ReadyRoll SQL Source Control SSDT Database Projects DbUp
  • 18. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach • Which one is better? • Size of the database • Complexity of the database • Team’s capabilities or preferences • Team’s development processes Both approaches may be needed for different parts of the system, or at different times in the development process.
  • 19. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Q&A @EdPiairo https://pt.linkedin.com/in/jesuspiairo [email protected] http://www.eduardopiairo.com/