database version control without pain - the phpnw10 version

98
PHPNW10 - Manchester - 9th October 2010 Harrie Verveer Database Version Control Without Pain zaterdag 9 oktober 2010

Upload: harrie-verveer

Post on 29-Nov-2014

5.128 views

Category:

Technology


4 download

DESCRIPTION

Slides for the talk "database version control without pain", as seen at PHPNW10 in Manchester, Friday 9th October 2010.

TRANSCRIPT

Page 1: Database version control without pain - the PHPNW10 version

PHPNW10 - Manchester - 9th October 2010Harrie Verveer

Database Version Control Without Pain

zaterdag 9 oktober 2010

Page 2: Database version control without pain - the PHPNW10 version

Oh hai!

2

Harrie Verveeraka Hairy

DutchyI live in Goes, which probably sounds awkward to you

Software engineer at ibuildings since 2004Vlissingen (Flushing) office

zaterdag 9 oktober 2010

Page 3: Database version control without pain - the PHPNW10 version

zaterdag 9 oktober 2010

Page 4: Database version control without pain - the PHPNW10 version

zaterdag 9 oktober 2010

Page 5: Database version control without pain - the PHPNW10 version

zaterdag 9 oktober 2010

Page 6: Database version control without pain - the PHPNW10 version

zaterdag 9 oktober 2010

Page 7: Database version control without pain - the PHPNW10 version

zaterdag 9 oktober 2010

Page 8: Database version control without pain - the PHPNW10 version

zaterdag 9 oktober 2010

Page 9: Database version control without pain - the PHPNW10 version

“Yeah, don’t get bogged down in trying to be funny. Be yourself and present the info.”

zaterdag 9 oktober 2010

Page 10: Database version control without pain - the PHPNW10 version

9

Sorry, this talk won’t be funny

zaterdag 9 oktober 2010

Page 11: Database version control without pain - the PHPNW10 version

Database Version ControlWhat’s the problem?

10zaterdag 9 oktober 2010

Page 12: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/1207911

zaterdag 9 oktober 2010

Page 13: Database version control without pain - the PHPNW10 version

http

://en

.wik

iped

ia.o

rg/w

iki/F

ile:S

TS1

20La

unch

HiR

es.jp

g

zaterdag 9 oktober 2010

Page 14: Database version control without pain - the PHPNW10 version

http://www.flickr.com/photos/kt/1217157/

zaterdag 9 oktober 2010

Page 15: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/1255121

zaterdag 9 oktober 2010

Page 16: Database version control without pain - the PHPNW10 version

Why Database Version Control

15zaterdag 9 oktober 2010

Page 17: Database version control without pain - the PHPNW10 version

Simple Patching Strategy

16

The basic idea

zaterdag 9 oktober 2010

Page 18: Database version control without pain - the PHPNW10 version

Simple patching strategy

17zaterdag 9 oktober 2010

Page 19: Database version control without pain - the PHPNW10 version

Example patch file

18

patch-001.sql

zaterdag 9 oktober 2010

Page 20: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/314594

zaterdag 9 oktober 2010

Page 21: Database version control without pain - the PHPNW10 version

Simple patching strategy

20

Development

Write codeWrite DB patches

Apply patches to own DB

Update

Apply patches Commit

zaterdag 9 oktober 2010

Page 22: Database version control without pain - the PHPNW10 version

Fixing patches

21

patch-002.sql

zaterdag 9 oktober 2010

Page 23: Database version control without pain - the PHPNW10 version

Fixing patches

21

patch-002.sql

zaterdag 9 oktober 2010

Page 24: Database version control without pain - the PHPNW10 version

Fixing patches

21

patch-002.sql

zaterdag 9 oktober 2010

Page 25: Database version control without pain - the PHPNW10 version

Fixing patches

22

patch-003.sql

zaterdag 9 oktober 2010

Page 26: Database version control without pain - the PHPNW10 version

Fixing patches

22

patch-003.sql

Never modify a patch file onceit’s under version control

zaterdag 9 oktober 2010

Page 27: Database version control without pain - the PHPNW10 version

Undo patch files

23

undo-001.sql

zaterdag 9 oktober 2010

Page 28: Database version control without pain - the PHPNW10 version

http://www.freefoto.com/preview/41-07-7zaterdag 9 oktober 2010

Page 29: Database version control without pain - the PHPNW10 version

Bonus points

Install.sql

25zaterdag 9 oktober 2010

Page 30: Database version control without pain - the PHPNW10 version

Bonus points

Initial dummy content

26zaterdag 9 oktober 2010

Page 31: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/643214

zaterdag 9 oktober 2010

Page 32: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/946855

zaterdag 9 oktober 2010

Page 33: Database version control without pain - the PHPNW10 version

Automating the processFaster & Safer

29zaterdag 9 oktober 2010

Page 34: Database version control without pain - the PHPNW10 version

Typical patch script

30zaterdag 9 oktober 2010

Page 35: Database version control without pain - the PHPNW10 version

Typical patch script

31

update.sh

zaterdag 9 oktober 2010

Page 36: Database version control without pain - the PHPNW10 version

BranchesMerge problems

32zaterdag 9 oktober 2010

Page 37: Database version control without pain - the PHPNW10 version

Branches

33

Trunk

patch-001.sql

patch-002.sql

patch-003.sql

zaterdag 9 oktober 2010

Page 38: Database version control without pain - the PHPNW10 version

Trunk

patch-001.sql

patch-002.sql

patch-003.sql

create branch

patch-004.sql

patch-005.sqlpatch-004.sql

patch-005.sql

Branch A

Merge

Branches

34zaterdag 9 oktober 2010

Page 39: Database version control without pain - the PHPNW10 version

Trunk

patch-001.sql

patch-002.sql

patch-003.sql

create branch

patch-004.sql

patch-005.sqlpatch-004.sql

patch-005.sql

Branch A

Merge

Branches

34

patch-006.sql

patch-007.sql

zaterdag 9 oktober 2010

Page 40: Database version control without pain - the PHPNW10 version

Branches

35

Trunk

patch-001.sql

patch-002.sql

patch-003.sql

create branch

patch-004.sql

patch-005.sql

patch-004.sql

patch-005.sql

Branch B

create branch

patch-002.sql

patch-003.sql

Branch A

Merge

patch-004.sql

Merge

patch-005.sql

Merge

Merge

zaterdag 9 oktober 2010

Page 41: Database version control without pain - the PHPNW10 version

Separate sequence

db/patches/trunk/

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

36

db/patches/branchA/

patch-001.sqlpatch-002.sql

zaterdag 9 oktober 2010

Page 42: Database version control without pain - the PHPNW10 version

Separate sequence

db/patches/trunk/

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

36

db/patches/branchA/

patch-001.sqlpatch-002.sql

Trunk version 3BranchA version 2

zaterdag 9 oktober 2010

Page 43: Database version control without pain - the PHPNW10 version

Patchfile naming

37

patch_20100611_1430.sql

zaterdag 9 oktober 2010

Page 44: Database version control without pain - the PHPNW10 version

Patch log

38zaterdag 9 oktober 2010

Page 45: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/692740

zaterdag 9 oktober 2010

Page 46: Database version control without pain - the PHPNW10 version

There is no silver bulletWhy it can’t exist

40zaterdag 9 oktober 2010

Page 47: Database version control without pain - the PHPNW10 version

http://www.flickr.com/photos/eschipul/4160817135/

zaterdag 9 oktober 2010

Page 48: Database version control without pain - the PHPNW10 version

Comparing tables

42

Table in DB 1Table in DB 1

column 1 int

column 2 varchar(255)

column 3 varchar(255)

Table in DB 2Table in DB 2

column 1 int

column 2 varchar(255)

column 4 varchar(255)

zaterdag 9 oktober 2010

Page 49: Database version control without pain - the PHPNW10 version

Comparing tables

43

Table in DB 1Table in DB 1

id int

name varchar(255)

city varchar(255)

Table in DB 2Table in DB 2

id int

name varchar(255)

website varchar(255)

zaterdag 9 oktober 2010

Page 50: Database version control without pain - the PHPNW10 version

Comparing tables

44

Table in DB 1Table in DB 1

id int

firstname varchar(255)

lname varchar(255)

Table in DB 2Table in DB 2

id int

firstname varchar(255)

lastname varchar(255)

zaterdag 9 oktober 2010

Page 51: Database version control without pain - the PHPNW10 version

45

To synchronize two database structures without unexpected

dataloss, communicating all steps needed to get from A to B is

inevitable.

zaterdag 9 oktober 2010

Page 52: Database version control without pain - the PHPNW10 version

Phing & DB Deploy

46zaterdag 9 oktober 2010

Page 53: Database version control without pain - the PHPNW10 version

Phing & DB Deploy

47Cartoon by Oliver Widder - http://geekandpoke.typepad.com/zaterdag 9 oktober 2010

Page 54: Database version control without pain - the PHPNW10 version

48

http://phing.info/

zaterdag 9 oktober 2010

Page 55: Database version control without pain - the PHPNW10 version

Phing

49zaterdag 9 oktober 2010

Page 56: Database version control without pain - the PHPNW10 version

50zaterdag 9 oktober 2010

Page 57: Database version control without pain - the PHPNW10 version

DB Deploy

51zaterdag 9 oktober 2010

Page 58: Database version control without pain - the PHPNW10 version

Phing & DB Deploy

52zaterdag 9 oktober 2010

Page 59: Database version control without pain - the PHPNW10 version

DB Deploy

53

db/patches/1-create_user_table.sql

zaterdag 9 oktober 2010

Page 60: Database version control without pain - the PHPNW10 version

DB Deploy

54

changelog table:

zaterdag 9 oktober 2010

Page 61: Database version control without pain - the PHPNW10 version

DB Deploy

54

changelog table:

zaterdag 9 oktober 2010

Page 62: Database version control without pain - the PHPNW10 version

DB Deploy

55

PHP

zaterdag 9 oktober 2010

Page 63: Database version control without pain - the PHPNW10 version

DB Deploy

56

SQL

zaterdag 9 oktober 2010

Page 64: Database version control without pain - the PHPNW10 version

DB Deploy

57

Features

zaterdag 9 oktober 2010

Page 65: Database version control without pain - the PHPNW10 version

LiquibaseThe most complete solution I know

58zaterdag 9 oktober 2010

Page 66: Database version control without pain - the PHPNW10 version

Liquibase

59

www.liquibase.org

zaterdag 9 oktober 2010

Page 67: Database version control without pain - the PHPNW10 version

Liquibase

60zaterdag 9 oktober 2010

Page 68: Database version control without pain - the PHPNW10 version

Liquibase

61zaterdag 9 oktober 2010

Page 69: Database version control without pain - the PHPNW10 version

Liquibase

62zaterdag 9 oktober 2010

Page 70: Database version control without pain - the PHPNW10 version

Liquibase

Updating

Reverting

Tagging

Generate XML

Diff

63zaterdag 9 oktober 2010

Page 71: Database version control without pain - the PHPNW10 version

http://www.sxc.hu/photo/1241520

zaterdag 9 oktober 2010

Page 72: Database version control without pain - the PHPNW10 version

Liquibase

Branches

65zaterdag 9 oktober 2010

Page 73: Database version control without pain - the PHPNW10 version

Liquibase

DBMS Support

66zaterdag 9 oktober 2010

Page 74: Database version control without pain - the PHPNW10 version

Liquibase

Documentation

67zaterdag 9 oktober 2010

Page 75: Database version control without pain - the PHPNW10 version

Liquibase

Java

68zaterdag 9 oktober 2010

Page 76: Database version control without pain - the PHPNW10 version

Akrabat DB Schema ManagerZend Framework specific solution

69zaterdag 9 oktober 2010

Page 77: Database version control without pain - the PHPNW10 version

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

70zaterdag 9 oktober 2010

Page 78: Database version control without pain - the PHPNW10 version

Akrabat DB Schema Manager

Zend Framework

Proposed by Rob Allen in 2006

Recently implemented

Might be in ZF in the near future

Might not be in ZF in the near future as well

http://github.com/akrabat/Akrabat

71zaterdag 9 oktober 2010

Page 79: Database version control without pain - the PHPNW10 version

Writing the patch

72

scripts/migrations/001-CreateUserTable.php

zaterdag 9 oktober 2010

Page 80: Database version control without pain - the PHPNW10 version

Writing the patch

73

scripts/migrations/001-CreateUserTable.php

zaterdag 9 oktober 2010

Page 81: Database version control without pain - the PHPNW10 version

Akrabat DB Schema Manager

PHP Patches

74zaterdag 9 oktober 2010

Page 82: Database version control without pain - the PHPNW10 version

Akrabat DB Schema Manager

Easy syntax if you know ZF

75zaterdag 9 oktober 2010

Page 83: Database version control without pain - the PHPNW10 version

Akrabat DB Schema Manager

Easy to install, easy to use

76zaterdag 9 oktober 2010

Page 84: Database version control without pain - the PHPNW10 version

Akrabat DB Schema Manager

Easy to install, easy to use

76zaterdag 9 oktober 2010

Page 85: Database version control without pain - the PHPNW10 version

Akrabat DB Schema Manager

Branch merging

77zaterdag 9 oktober 2010

Page 86: Database version control without pain - the PHPNW10 version

Doctrine MigrationsDoctrine ORM specific solution

78zaterdag 9 oktober 2010

Page 87: Database version control without pain - the PHPNW10 version

Doctrine Migrations

79

http://www.doctrine-project.org/

zaterdag 9 oktober 2010

Page 88: Database version control without pain - the PHPNW10 version

Doctrine Migrations Patch

80zaterdag 9 oktober 2010

Page 89: Database version control without pain - the PHPNW10 version

Doctrine Migrations

81

Update-to-version

./doctrine migrate

zaterdag 9 oktober 2010

Page 90: Database version control without pain - the PHPNW10 version

YAML

82zaterdag 9 oktober 2010

Page 91: Database version control without pain - the PHPNW10 version

YAML

82

./doctrine generate-migrations-diff

zaterdag 9 oktober 2010

Page 92: Database version control without pain - the PHPNW10 version

Doctrine Migrations

83zaterdag 9 oktober 2010

Page 93: Database version control without pain - the PHPNW10 version

Doctrine Migrations

84

Generate patches

zaterdag 9 oktober 2010

Page 94: Database version control without pain - the PHPNW10 version

Doctrine Migrations

85

Useful if you’re already using Doctrine ORM

zaterdag 9 oktober 2010

Page 95: Database version control without pain - the PHPNW10 version

Summary

86zaterdag 9 oktober 2010

Page 96: Database version control without pain - the PHPNW10 version

Summary

Patchfiles• Automating

• Branch merging

• Why there is no silver bullet

Phing + DB Deployhttp://phing.infohttp://dbdeploy.com

Liquibasehttp://www.liquibase.org

87

Akrabat DB Schema Managerhttp://akrabat.comhttp://github.com/akrabat/Akrabat

Doctrine Migrationshttp://www.doctrine-project.org

zaterdag 9 oktober 2010

Page 97: Database version control without pain - the PHPNW10 version

Questions ?

88zaterdag 9 oktober 2010

Page 98: Database version control without pain - the PHPNW10 version

89

Contact me

Harrie VerveerSoftware Engineer at Ibuildings

E-mail:[email protected]

Skype:harrie-ibuildings

Twitter:@harrieverveer

http://joind.in/2056

zaterdag 9 oktober 2010