Your SlideShare is downloading. ×
symfony Live 2010 -  Using Doctrine Migrations
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

symfony Live 2010 - Using Doctrine Migrations

19,272
views

Published on

Published in: Technology

4 Comments
39 Likes
Statistics
Notes
No Downloads
Views
Total Views
19,272
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
496
Comments
4
Likes
39
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. Using Doctrine Migrations by Dennis Benkert
    • 2. Dennis Who?! 2
    • 3. Dennis Who?! 2
    • 4. Dennis Who?! 2
    • 5. Dennis Who?! 2
    • 6. Dennis Who?! 2
    • 7. Agenda 3
    • 8. Agenda Migrating by Hand 3
    • 9. Agenda Migrating by Hand Doctrine Migrations 3
    • 10. Agenda Migrating by Hand Doctrine Migrations Migrations and sf CLI 3
    • 11. Agenda Migrating by Hand Doctrine Migrations Migrations and sf CLI Things to keep in mind 3
    • 12. So, you want to change your live servers DB schema, right?! 4
    • 13. But migrating your database by hand is hard work 5
    • 14. Migrating by Hand 6
    • 15. Migrating by Hand schema.yml Live DB Dev DB 7
    • 16. Migrating by Hand schema.yml Live DB Dev DB 7
    • 17. Migrating by Hand schema.yml Live DB Dev DB 7
    • 18. Migrating by Hand schema.yml Live DB Dev DB 7
    • 19. Migrating by Hand schema.yml Live DB Dev DB 7
    • 20. Migrating by Hand schema.yml Live DB Dev DB 7
    • 21. What‘s so bad about it? 8
    • 22. What‘s so bad about it? Error Prone 8
    • 23. What‘s so bad about it? Error Prone No Rollback 8
    • 24. What‘s so bad about it? Error Prone No Rollback Not Comfortable 8
    • 25. Wouldn‘t it be cool if database changes were a bit like SCM revisions? 9
    • 26. Doctrine Migrations 10
    • 27. Migration Process schema.yml Migration File 11
    • 28. Migration Process schema.yml Migration File 11
    • 29. Migration Process schema.yml Migration File 11
    • 30. Migration Process Compare schema.yml Migration File 11
    • 31. Migration Process Compare schema.yml Migration File 11
    • 32. Migration Process Compare Generate schema.yml Migration File 11
    • 33. Migration Process Compare Generate schema.yml Migration File 11
    • 34. Migration Process Compare Generate schema.yml Migration File 11
    • 35. Migration Process Migrate Compare Generate schema.yml Migration File 11
    • 36. Migration Files class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } 12
    • 37. Migration Files class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } 12
    • 38. Migration Files Used for upgrading class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } 12
    • 39. Migration Files Used for upgrading class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } 12
    • 40. Migration Files Used for upgrading class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } Used for downgrading 12
    • 41. Migration Files Used for upgrading class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } Used for downgrading 12
    • 42. Migration Files Used for upgrading Table / Data Manipulation class VersionXX extends Doctrine_Migration_Base { public function up() { $this->addColumn('blog_post', 'tags', 'string', '255', array( )); } public function down() { $this->removeColumn('blog_post', 'tags'); } } Used for downgrading 12
    • 43. How Migrations work migration_version version (int) 13
    • 44. How Migrations work migration_version version (int) 13
    • 45. How Migrations work migration_version version (int) Current version stored in your database 13
    • 46. How Migrations work 4 3 2 1 14
    • 47. How Migrations work 4 3 2 1 14
    • 48. How Migrations work 4 getVersion 3 2 1 14
    • 49. How Migrations work 4 getVersion 3 2 1 14
    • 50. How Migrations work 4 getVersion Version =1 3 2 1 14
    • 51. How Migrations work 4 getVersion Version =1 3 2 1 14
    • 52. How Migrations work 4 getVersion Version =1 3 up() 2 1 14
    • 53. How Migrations work 4 getVersion Version =1 3 up() 2 1 14
    • 54. How Migrations work 4 getVersion up() Version =1 3 up() 2 1 14
    • 55. How Migrations work 4 getVersion up() Version =1 3 up() 2 1 14
    • 56. How Migrations work up() getVersion 4 up() Version =1 3 up() 2 1 14
    • 57. How Migrations work up() getVersion 4 up() Version =1 3 up() 2 1 14
    • 58. How Migrations work up() getVersion 4 up() Version =1 3 setVersion(4) up() 2 1 14
    • 59. Migrations and sf CLI 15
    • 60. Migrations and sf CLI symfony doctrine:generate-migrations-models symfony doctrine:generate-migrations-db symfony doctrine:generate-migrations-diff symfony doctrine:migrate 16
    • 61. Migrations and sf CLI symfony doctrine:generate-migrations-models symfony doctrine:generate-migrations-db symfony doctrine:generate-migrations-diff symfony doctrine:migrate Available in other tasks, too 16
    • 62. Migrations and sf CLI symfony doctrine:generate-migrations-models symfony doctrine:generate-migrations-db symfony doctrine:generate-migrations-diff symfony doctrine:migrate Available in other tasks, too Even works with plugins 16
    • 63. Migrations and sf CLI symfony doctrine:generate-migrations-models symfony doctrine:generate-migrations-db symfony doctrine:generate-migrations-diff symfony doctrine:migrate Available in other tasks, too Even works with plugins (only in sf, sorry Matthew :P) 16
    • 64. Migrations and sf CLI symfony doctrine:generate-migrations-models 17
    • 65. Migrations and sf CLI symfony doctrine:generate-migrations-models Compares Model files and schema.yml 17
    • 66. Migrations and sf CLI symfony doctrine:generate-migrations-models Compares Model files and schema.yml Good when starting without schema 17
    • 67. Migrations and sf CLI symfony doctrine:generate-migrations-db 18
    • 68. Migrations and sf CLI symfony doctrine:generate-migrations-db Compares DB tables and schema.yml 18
    • 69. Migrations and sf CLI symfony doctrine:generate-migrations-db Compares DB tables and schema.yml Good when starting with schema 18
    • 70. Creating a Migration Diff Before BlogPost: # [...] columns: title: { type: string(255), notnull: true } # [...] 19
    • 71. Creating a Migration Diff After BlogPost: # [...] columns: title: { type: string(255), notnull: true } # [...] tags: { type: string(255) } 20
    • 72. Migrations and sf CLI symfony doctrine:generate-migrations-diff 21
    • 73. Migrations and sf CLI symfony doctrine:generate-migrations-diff Compares changed schema.yml and Model files 21
    • 74. Migrations and sf CLI symfony doctrine:generate-migrations-diff Compares changed schema.yml and Model files Good when already using Migrations 21
    • 75. Migrating using sf CLI symfony doctrine:migrate symfony doctrine:build-model symfony doctrine:build-filters symfony doctrine:build-forms 22
    • 76. Migrating using sf CLI symfony doctrine:migrate symfony doctrine:build-model symfony doctrine:build-filters symfony doctrine:build-forms That‘s the obvious way 22
    • 77. Migrating using sf CLI symfony doctrine:migrate symfony doctrine:build --all-classes 23
    • 78. Migrating using sf CLI symfony doctrine:migrate symfony doctrine:build --all-classes That‘s the nice way 23
    • 79. Migrating using sf CLI symfony doctrine:build --all-classes --and-migrate 24
    • 80. Migrating using sf CLI symfony doctrine:build --all-classes --and-migrate That‘s the cool sf 1.3 way 24
    • 81. Things to keep in mind 25
    • 82. Big vs. small Migrations aka. „Complete Migrations“ vs. „Wild West Cowboy Style Migrations“ 26
    • 83. Big vs. small Migrations 27
    • 84. Big vs. small Migrations Small Migrations more Agile 27
    • 85. Big vs. small Migrations Small Migrations more Agile Really need to be Agile?! 27
    • 86. Big vs. small Migrations Small Migrations more Agile Really need to be Agile?! Small Migrations more dirty 27
    • 87. Big vs. small Migrations Small Migrations more Agile Really need to be Agile?! Small Migrations more dirty Big Migrations more complicated 27
    • 88. Keep in mind Run a diff before building the model 28
    • 89. Keep in mind Run a diff before building the model After migrating you can‘t generate the diff! 28
    • 90. Keep in mind Keep Data Migrations simple 29
    • 91. Keep in mind Keep Data Migrations simple Migrate the Data as easy as possible! 29
    • 92. Keep in mind Version get‘s updated after all Migrations are run 30
    • 93. Keep in mind Version get‘s updated after all Migrations are run You have to fix problems by hand if they fail. 30
    • 94. Thank you! 31
    • 95. Credits Thanks to: - Ryan Weaver for his presentation about Doctrine ...Migrations - Samim for the designs and the artworks. Picture „Von A nach B“ - photocase.com © Anna-Lena Thamm : cydonna Creative Commons stuff used: - „Application, Mime, Vnd.sun.xml.draw“ icon by „New Mooon“ - http://www.iconfinder.net/ icondetails/28957/128/ - „Application, Sqlite2, X“ icon by „New Mooon“ - http://www.iconfinder.net/icondetails/ 28899/128/ - „Application, Php, X “ icon by „New Mooon“ - http://www.iconfinder.net/icondetails/28894/128/ 32