SlideShare a Scribd company logo
Database Version Control Without Pain




                               Harrie Verveer
                  PFCongres - April 17th 2010
Database Version Control
What’s the problem?




                           2
Here used to be an image of an airplane that I removed
 because of the license the image was published under




                                           http://www.sxc.hu/photo/754535
Here used to be an image of an airplane that I removed
 because of the license the image was published under




                                          http://www.sxc.hu/photo/1207911
http://en.wikipedia.org/wiki/File:STS120LaunchHiRes.jpg
  Here used to be an image of the space shuttle that I
removed because of the license the image was published
                        under
http://www.sxc.hu/photo/1255121




                   Here used to be an image of a bike that I removed because
                         of the license the image was published under
Why Database Version Control




                               7
Why Database Version Control




        Database Version Control
             is left behind




                                   8
Simple Patching Strategy
The basic idea




                           9
Simple patching strategy




                 Patch files




                               10
Simple patching strategy




                           11
Simple patching strategy




        Mostly structural changes




                                    12
Simple patching strategy




         Chronological filenames




                                   13
Simple patching strategy




     Remember last executed patch




                                    14
Simple patching strategy

                      Development
                            Write code
                        Write DB patches
                     Apply patches to own DB




     Apply patches                             Commit




                          Update


                                                        15
Example patch file

patch-001.sql




                     16
Fixing patches

patch-002.sql




                 17
Fixing patches

patch-002.sql




                 17
Fixing patches

patch-002.sql




                 17
Fixing patches

patch-003.sql




                 18
Fixing patches

patch-003.sql




     Never modify a patch file once
       it’s under version control


                                      18
Undo patch files

patch-001.sql




                   19
Undo patch files

undo-001.sql




                   20
Here used to be an image of a one-way sign that I
removed because of the license the image was published
                        under




                                   http://www.freefoto.com/preview/41-07-7
Process

  Copy production to test environment
  Apply patches
  Run tests
  Backup live database
  Update production




                                        22
Bonus points




               Install.sql




                             23
Bonus points




         Initial dummy content




                                 24
Here used to be an image of a guy in a rowing boat that I
removed because of the license the image was published
                        under




                                            http://www.sxc.hu/photo/643214
Here used to be an image of a sunken boat that I removed
  because of the license the image was published under




                                           http://www.sxc.hu/photo/946855
Automating the process
Faster & Safer




                         27
Typical patch script




              Run the patches




                                28
Typical patch script




    Keep track of last executed patch




                                        29
Typical patch script




                       30
Typical patch script




                       31
Typical patch script




                       32
Typical patch script

update.sh




                       33
Branches
Merge problems




                 34
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql




                    35
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql
                         Branch A
         create branch

    patch-004.sql
                               patch-004.sql
    patch-005.sql

                               patch-005.sql




                                               36
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql
                         Branch A
         create branch

    patch-004.sql
                               patch-004.sql
    patch-005.sql

                               patch-005.sql
             Merge




                                               37
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql
                         Branch A
         create branch

    patch-004.sql
                                               patch-006.sql
                               patch-004.sql
    patch-005.sql
                                               patch-007.sql
                               patch-005.sql
             Merge




                                                               37
Branches
Trunk
    patch-001.sql                             Branch A
                         create branch
    patch-002.sql

                                                    patch-002.sql
    patch-003.sql
                         Branch B
         create branch
                                                    patch-003.sql
              Merge

                                   patch-004.sql    patch-004.sql
    patch-004.sql
                                   patch-005.sql

    patch-005.sql                     Merge


                                                    patch-005.sql
                                      Merge
             Merge


                                                                    38
Separate sequence

db/patches/trunk/   db/patches/branchA/

patch-001.sql       patch-001.sql
patch-002.sql       patch-002.sql
patch-003.sql




                                          39
Separate sequence

db/patches/trunk/           db/patches/branchA/

patch-001.sql               patch-001.sql
patch-002.sql               patch-002.sql
patch-003.sql


                     Trunk version    3
                    BranchA version   2




                                                  39
Patchfile naming

  Filenames based on time




                            40
Patch log

At this point our patch number tracking doesn’t work
anymore!!!

 patch_20100322_2158.sql
 patch_20100323_0839.sql
 patch_20100327_1025.sql




                                                       41
Patch log

At this point our patch number tracking doesn’t work
anymore!!!

 patch_20100322_2158.sql
 patch_20100323_0839.sql
 patch_20100327_1025.sql




     Last executed:
 patch_20100327_1025



                                                       41
Patch log

At this point our patch number tracking doesn’t work
anymore!!!

 patch_20100322_2158.sql      patch_20100322_2253.sql
 patch_20100323_0839.sql      patch_20100325_1528.sql
 patch_20100327_1025.sql      patch_20100328_1230.sql




     Last executed:
 patch_20100327_1025



                                                        41
Patch log

At this point our patch number tracking doesn’t work
anymore!!!

 patch_20100322_2158.sql      patch_20100322_2253.sql
 patch_20100323_0839.sql      patch_20100325_1528.sql
 patch_20100327_1025.sql      patch_20100328_1230.sql




     Last executed:
 patch_20100327_1025



                                                        41
Patch log

At this point our patch number tracking doesn’t work
anymore!!!

 patch_20100322_2158.sql      patch_20100322_2253.sql
 patch_20100323_0839.sql      patch_20100325_1528.sql
 patch_20100327_1025.sql      patch_20100328_1230.sql


                            patch_20100322_2158.sql
                            patch_20100322_2253.sql
     Last executed:         patch_20100323_0839.sql
 patch_20100327_1025        patch_20100325_1528.sql
                            patch_20100327_1025.sql
                            patch_20100328_1230.sql
                                                        41
Patch log

At this point our patch number tracking doesn’t work
anymore!!!

 patch_20100322_2158.sql      patch_20100322_2253.sql
 patch_20100323_0839.sql      patch_20100325_1528.sql
 patch_20100327_1025.sql      patch_20100328_1230.sql


                            patch_20100322_2158.sql
                            patch_20100322_2253.sql
     Last executed:         patch_20100323_0839.sql
 patch_20100327_1025        patch_20100325_1528.sql
                            patch_20100327_1025.sql
                            patch_20100328_1230.sql
                                                        41
Patch log




            42
Branches




           False sense of security




                                     43
Phing
Avoiding the NIH syndrome




                            44
http://phing.info/




                     45
Phing




        46
47
DB Deploy




            48
DB Deploy




            49
DB Deploy




            49
DB Deploy

changelog table:




                   50
DB Deploy

changelog table:




                   50
Akrabat DB Schema Manager
Zend Framework specific solution




                                   51
Akrabat DB Schema Manager

  Zend Framework
  Proposed by Rob Allen in 2006
  Recently implemented
  Might be in ZF in the near future

http://github.com/akrabat/Akrabat




                                      52
Writing the patch

scripts/migrations/001-CreateUserTable.php




                                             53
Writing the patch

scripts/migrations/001-CreateUserTable.php




                                             54
Running the patch




                    55
Running the patch




                    55
Running the patch




                    56
Running the patch




                    57
Akrabat DB Schema Manager

  Easy to use if you know ZF
  PHP instead of SQL-only
  Easy to ‘undo’ patches
  Branch merging problem
  Run from your deploy script




                                58
Multiple servers
ssh harrie@webserver188




                          59
http://www.capify.org/




                         60
Capistrano




             cd /dir/where/my/app/is
             svn update
             php updatedb.php


                                       61
Capistrano




             cd /dir/where/my/app/is
             svn update
             php updatedb.php
                                       62
Capistrano & the database




                            63
Capistrano

  Automate deployment
  No coding needed
  Extending possible
  Useful tool for PHP developers
  Replace railsy voodoo with PHPish 1337ness




                                               64
Summary




          65
Summary

 Patchfiles
 • Automating
 • Branch merging


 Phing + DB Deploy
 http://phing.info
 http://dbdeploy.com


 Akrabat DB Schema Manager
 http://akrabat.com
 http://github.com/akrabat/Akrabat


 Capistrano
 http://capify.org


                                     66
Questions ?




              67
Contact me

Harrie Verveer
Software Engineer at Ibuildings


E-mail:
harrie@ibuildings.nl


Skype:
harrie-ibuildings


Twitter:
@harrieverveer




               http://joind.in/1499
                                      68
Dutch PHP Conference




              june 10 - 12
              RAI Amsterdam
             http://phpconference.nl


                                       69

More Related Content

PDF
如何安装Oracle one off临时小补丁及注意事项
PPTX
Hacking Oracle From Web Apps 1 9
PDF
Install oracle database 12c software on windows
PDF
Hacking oracle using metasploit
PDF
PTK 1.0 official presentation
PDF
Oracle-11g-upgrade
PDF
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
PDF
Upgrade 11.2.0.1 gi crs to 11.2.0.2 in linux
如何安装Oracle one off临时小补丁及注意事项
Hacking Oracle From Web Apps 1 9
Install oracle database 12c software on windows
Hacking oracle using metasploit
PTK 1.0 official presentation
Oracle-11g-upgrade
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Upgrade 11.2.0.1 gi crs to 11.2.0.2 in linux

What's hot (19)

PDF
Upgrade 11.2.0.1 rac db to 11.2.0.2 in linux
PDF
En rhel-deploy-oracle-rac-database-12c-rhel-7
PDF
Install Solaris 11.1 on a Virtualbox VM
PDF
Oracle 12c r1 installation on solaris 11.1
PDF
Installing oracle grid infrastructure and database 12c r1
KEY
10x Performance Improvements
PDF
Writing Plugged-in Java EE Apps: Jason Lee
PPT
Oracle 10g Performance: chapter 00 statspack
PDF
12c (12.1) Database installation on Solaris 11(11.2)
PDF
Second Step to the NoSQL Side: MySQL JSON Functions
DOCX
how to protect your sensitive data using oracle database vault
DOCX
Vbox virtual box在oracle linux 5 - shoug 梁洪响
PDF
SOUG - Experiences with Oracle Solaris 11.4
PDF
Sprytniejsze testowanie kodu java ze spock framework (zaawansowane techniki) ...
PDF
Capturing, Analyzing, and Optimizing your SQL
PDF
Solaris 9 Installation Guide
DOC
Upgrade 10204-to-10205 on-2-node_rac_linux_x86_64_detail-steps_v0.1
PDF
Mysql 56-experiences-bugs-solutions-50mins
DOCX
greenplum installation guide - 4 node VM
Upgrade 11.2.0.1 rac db to 11.2.0.2 in linux
En rhel-deploy-oracle-rac-database-12c-rhel-7
Install Solaris 11.1 on a Virtualbox VM
Oracle 12c r1 installation on solaris 11.1
Installing oracle grid infrastructure and database 12c r1
10x Performance Improvements
Writing Plugged-in Java EE Apps: Jason Lee
Oracle 10g Performance: chapter 00 statspack
12c (12.1) Database installation on Solaris 11(11.2)
Second Step to the NoSQL Side: MySQL JSON Functions
how to protect your sensitive data using oracle database vault
Vbox virtual box在oracle linux 5 - shoug 梁洪响
SOUG - Experiences with Oracle Solaris 11.4
Sprytniejsze testowanie kodu java ze spock framework (zaawansowane techniki) ...
Capturing, Analyzing, and Optimizing your SQL
Solaris 9 Installation Guide
Upgrade 10204-to-10205 on-2-node_rac_linux_x86_64_detail-steps_v0.1
Mysql 56-experiences-bugs-solutions-50mins
greenplum installation guide - 4 node VM
Ad

Viewers also liked (6)

KEY
Database version control DPC version
PDF
Database version control without pain - the PHP Barcelona version
PPTX
Database Change Management
PDF
Database version control without pain - the PHPNW10 version
PPTX
Database versioning with liquibase
PDF
Leveraging Open Source for Database Development: Database Version Control wit...
Database version control DPC version
Database version control without pain - the PHP Barcelona version
Database Change Management
Database version control without pain - the PHPNW10 version
Database versioning with liquibase
Leveraging Open Source for Database Development: Database Version Control wit...
Ad

Similar to Database version control - pf congres version (20)

DOC
Group3 sap nw3 7.0 install
PDF
MirrorMaker: Beyond the Basics with Mickael Maison
PDF
2024_05_16_doag_out-of-place_patching.pdf
PDF
Tracing Software Build Processes to Uncover License Compliance Inconsistencies
PPTX
Cisco IOS shellcode: All-in-one
PPTX
Windows Debugging with WinDbg
PPTX
Data Virtualization: Revolutionizing data cloning
KEY
Sane SQL Change Management with Sqitch
PDF
BenchFlow: A Platform for End-to-end Automation of Performance Testing and An...
KEY
Simple SQL Change Management with Sqitch
PPTX
JavaEdge 2008: Your next version control system
PDF
[AMD] Novel Use of Perforce for Software Auto-updates and File Transfer
PPTX
[Rakuten TechConf2014] [C-5] Ichiba Architecture on ExaLogic
PDF
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
PDF
havcs-410-101 a-2-10-srt-pg_2
PDF
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
PDF
Delivering Microservices Using Docker
PPT
What to Do When You Don’t Know What to Do: Control System Patching Problems a...
PPTX
Advanced Index Tuning
PDF
eu-19-Abbasi-Doors-Of-Durin-The-Veiled-Gate-To-Siemens-S7-Silicon.pdf
Group3 sap nw3 7.0 install
MirrorMaker: Beyond the Basics with Mickael Maison
2024_05_16_doag_out-of-place_patching.pdf
Tracing Software Build Processes to Uncover License Compliance Inconsistencies
Cisco IOS shellcode: All-in-one
Windows Debugging with WinDbg
Data Virtualization: Revolutionizing data cloning
Sane SQL Change Management with Sqitch
BenchFlow: A Platform for End-to-end Automation of Performance Testing and An...
Simple SQL Change Management with Sqitch
JavaEdge 2008: Your next version control system
[AMD] Novel Use of Perforce for Software Auto-updates and File Transfer
[Rakuten TechConf2014] [C-5] Ichiba Architecture on ExaLogic
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
havcs-410-101 a-2-10-srt-pg_2
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
Delivering Microservices Using Docker
What to Do When You Don’t Know What to Do: Control System Patching Problems a...
Advanced Index Tuning
eu-19-Abbasi-Doors-Of-Durin-The-Veiled-Gate-To-Siemens-S7-Silicon.pdf

Database version control - pf congres version