SlideShare a Scribd company logo
DATABASE SOURCE CONTROL Eduardo Piairo
Migrations vs State
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
•Eduardo Piairo
•DBA & DevOps
About me
@EdPiairo
https://pt.linkedin.com/in/jesuspiai
ro
eduardopiairo@outlook.com
http://www.eduardopiairo.com/
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Introduction
Source
Control
Continuous
Integration
Continuo
us
Delivery
Databas
e
+
Applicati
on
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
What’s so special about databases?
Introduction
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Why database source control?
• First step in your database deployment pipeline
• Traceability through change history
• Shared code-base and shared process
• SQL as documentation
• Enforce standards to reduce conflits
• Your best communication system
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Migrations-based approach vs State-based approach
• Fundamental resource: SQL Script
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Migrations-based approach vs State-based approach
• State based solutions
• Script represents the current database state
• Your source of truth is how the database should be
• Migrations based solutions
• Script represents a migration
• Migration represents how to transition to the next database version
• Your source of truth is how the database should change
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Flyway
• Flyway – “Database migrations made easy”
• http://flywaydb.org/
• Open source database migration tool
• Flyway command-line enabled
• Simplicity: easy to setup, no need to install
• Zero dependencies (java + jdbc)
• Scripts are written in SQL
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
• 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
ROAD TO DATABASE AUTOMATION – DATABASE
SOURCE CONTROL
Flyway - Version Control System
• Two components
• Database scripts repository
• Flyway – database migrations
Example:
V20160220.1100__Create_TB_MyTable.sql
• Rule 1: Script version (timestamp)
• Rule 2: Operation type
• Rule 3: Object type
• Rule 4: Object name
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Flyway – Demo
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
SQL Source Control
• SQL Source Control
• Add-in for SSMS
• Links your database to your source control system
• Ability to source control schemas and reference data
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
Migration
s
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
Links
• Flyway
• https://flywaydb.org/
• Redgate SQL Source Control
• http://www.red-gate.com/products/sql-development/sql-source-control/
• Simple Talk - DLM Patterns and Practices
• https://www.simple-talk.com/collections/database-lifecycle-management-patterns-
practices-library/
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Reading Material
DATABASE SOURCE CONTROL– MIGRATIONS VS
STATE
Q&A
@EdPiairo
https://pt.linkedin.com/in/jesuspiai
ro
eduardopiairo@outlook.com
http://www.eduardopiairo.com/

More Related Content

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

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

PDF
Database Source Control: Migrations vs State
PPTX
Database CI/CD Pipeline
PPTX
Flyway (33rd Degree)
PDF
Flyway _ A Database Version Management Tool
PDF
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
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 ...
PPTX
Getting CI right for SQL Server
PPTX
Part of the DLM story: Get your Database under Source Control - SQL In The City
PDF
Migrating from PostgreSQL to MySQL Without Downtime
PPTX
Getting CI right for SQL Server
PDF
Embracing DevOps through database migrations with Flyway
PPTX
Flyway: The agile database migration framework for Java
PPTX
#DOAW16 - DevOps@work Roma 2016 - Databases under source control
PPTX
Evolutionary database design
PPTX
SQL in Version Control using SQL Server Database Projects
PDF
Database Source Control
PPTX
Evolutionary database design
PPTX
Declarative Database Development with SQL Server Data Tools
PDF
[db tech showcase Tokyo 2017] C34: Replacing Oracle Database at DBS Bank ~Ora...
Database Source Control: Migrations vs State
Database CI/CD Pipeline
Flyway (33rd Degree)
Flyway _ A Database Version Management Tool
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
Are we there Yet?? (The long journey of Migrating from close source to opens...
Automated Build and Test (for Continuous Integration) - David Atkinson - SQL ...
Getting CI right for SQL Server
Part of the DLM story: Get your Database under Source Control - SQL In The City
Migrating from PostgreSQL to MySQL Without Downtime
Getting CI right for SQL Server
Embracing DevOps through database migrations with Flyway
Flyway: The agile database migration framework for Java
#DOAW16 - DevOps@work Roma 2016 - Databases under source control
Evolutionary database design
SQL in Version Control using SQL Server Database Projects
Database Source Control
Evolutionary database design
Declarative Database Development with SQL Server Data Tools
[db tech showcase Tokyo 2017] C34: Replacing Oracle Database at DBS Bank ~Ora...
Ad

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)

PDF
Digital Strategies for Manufacturing Companies
PPTX
assetexplorer- product-overview - presentation
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Nekopoi APK 2025 free lastest update
PPTX
Introduction to Artificial Intelligence
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPT
Introduction Database Management System for Course Database
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Digital Strategies for Manufacturing Companies
assetexplorer- product-overview - presentation
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Nekopoi APK 2025 free lastest update
Introduction to Artificial Intelligence
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
CHAPTER 2 - PM Management and IT Context
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Introduction Database Management System for Course Database
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms I-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Systems & Binary Numbers (comprehensive )
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

Database Source Control: Migrations vs State

  • 1. DATABASE SOURCE CONTROL Eduardo Piairo Migrations vs State
  • 2. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE •Eduardo Piairo •DBA & DevOps About me @EdPiairo https://pt.linkedin.com/in/jesuspiai ro eduardopiairo@outlook.com http://www.eduardopiairo.com/
  • 3. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Introduction Source Control Continuous Integration Continuo us Delivery Databas e + Applicati on
  • 4. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE What’s so special about databases? Introduction
  • 5. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Why database source control? • First step in your database deployment pipeline • Traceability through change history • Shared code-base and shared process • SQL as documentation • Enforce standards to reduce conflits • Your best communication system
  • 6. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach • Fundamental resource: SQL Script
  • 7. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach • State based solutions • Script represents the current database state • Your source of truth is how the database should be • Migrations based solutions • Script represents a migration • Migration represents how to transition to the next database version • Your source of truth is how the database should change
  • 8. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Flyway • Flyway – “Database migrations made easy” • http://flywaydb.org/ • Open source database migration tool • Flyway command-line enabled • Simplicity: easy to setup, no need to install • Zero dependencies (java + jdbc) • Scripts are written in SQL
  • 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 • 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. ROAD TO DATABASE AUTOMATION – DATABASE SOURCE CONTROL Flyway - Version Control System • Two components • Database scripts repository • Flyway – database migrations Example: V20160220.1100__Create_TB_MyTable.sql • Rule 1: Script version (timestamp) • Rule 2: Operation type • Rule 3: Object type • Rule 4: Object name
  • 11. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Flyway – Demo
  • 12. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE SQL Source Control • SQL Source Control • Add-in for SSMS • Links your database to your source control system • Ability to source control schemas and reference data
  • 13. 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
  • 14. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE SQL Source Control – Demo
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Migrations-based approach vs State-based approach – Tools Migration s State Flyway ReadyRoll SQL Source Control SSDT Database Projects DbUp
  • 19. 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.
  • 20. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Links • Flyway • https://flywaydb.org/ • Redgate SQL Source Control • http://www.red-gate.com/products/sql-development/sql-source-control/ • Simple Talk - DLM Patterns and Practices • https://www.simple-talk.com/collections/database-lifecycle-management-patterns- practices-library/
  • 21. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Reading Material
  • 22. DATABASE SOURCE CONTROL– MIGRATIONS VS STATE Q&A @EdPiairo https://pt.linkedin.com/in/jesuspiai ro eduardopiairo@outlook.com http://www.eduardopiairo.com/