SlideShare ist ein Scribd-Unternehmen logo
1 von 95
Using Doctrine Migrations

                            by Dennis Benkert
Dennis Who?!




               2
Dennis Who?!




               2
Dennis Who?!




               2
Dennis Who?!




               2
Dennis Who?!




               2
Agenda




         3
Agenda


         Migrating by Hand




                             3
Agenda


         Migrating by Hand
         Doctrine Migrations




                               3
Agenda


          Migrating by Hand
         Doctrine Migrations
         Migrations and sf CLI




                                 3
Agenda


           Migrating by Hand
          Doctrine Migrations
         Migrations and sf CLI
         Things to keep in mind


                                  3
So, you want to change your live
   servers DB schema, right?!



                                   4
But migrating your database by hand is hard work
                                                   5
Migrating by Hand


                    6
Migrating by Hand


schema.yml




                    Live DB



  Dev DB
                              7
Migrating by Hand


schema.yml




                    Live DB



  Dev DB
                              7
Migrating by Hand


schema.yml




                    Live DB



  Dev DB
                              7
Migrating by Hand


schema.yml




                    Live DB



  Dev DB
                              7
Migrating by Hand


schema.yml




                    Live DB



  Dev DB
                              7
Migrating by Hand


schema.yml




                    Live DB



  Dev DB
                              7
What‘s so bad about it?




                          8
What‘s so bad about it?


            Error Prone




                          8
What‘s so bad about it?


            Error Prone
            No Rollback




                          8
What‘s so bad about it?


            Error Prone
           No Rollback
          Not Comfortable



                            8
Wouldn‘t it be cool if database changes were a bit
                               like SCM revisions?




                                                     9
Doctrine Migrations


                      10
Migration Process




schema.yml

                    Migration File
                                     11
Migration Process




schema.yml

                    Migration File
                                     11
Migration Process




schema.yml

                    Migration File
                                     11
Migration Process




             Compare



schema.yml

                       Migration File
                                        11
Migration Process




             Compare



schema.yml

                       Migration File
                                        11
Migration Process




             Compare

                   Generate
schema.yml

                              Migration File
                                               11
Migration Process




             Compare

                   Generate
schema.yml

                              Migration File
                                               11
Migration Process




             Compare

                   Generate
schema.yml

                              Migration File
                                               11
Migration Process



                          Migrate

             Compare

                   Generate
schema.yml

                              Migration File
                                               11
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
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
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
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
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
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
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
How Migrations work

          migration_version

             version (int)




                              13
How Migrations work

          migration_version

             version (int)




                              13
How Migrations work

          migration_version

             version (int)




              Current version stored
                in your database

                                       13
How Migrations work


    4


   3


       2

           1          14
How Migrations work


    4


   3


       2

           1          14
How Migrations work


    4          getVersion



   3


       2

           1                14
How Migrations work


    4          getVersion



   3


       2

           1                14
How Migrations work


    4          getVersion

                  Version =1

   3


       2

           1                   14
How Migrations work


    4          getVersion

                  Version =1

   3


       2

           1                   14
How Migrations work


    4             getVersion

                     Version =1

   3
           up()

       2

             1                    14
How Migrations work


    4             getVersion

                     Version =1

   3
           up()

       2

             1                    14
How Migrations work


    4             getVersion

           up()      Version =1

   3
           up()

       2

             1                    14
How Migrations work


    4             getVersion

           up()      Version =1

   3
           up()

       2

             1                    14
How Migrations work

             up()   getVersion
    4

           up()        Version =1

   3
           up()

       2

             1                      14
How Migrations work

             up()   getVersion
    4

           up()        Version =1

   3
           up()

       2

             1                      14
How Migrations work

             up()   getVersion
    4

           up()        Version =1

   3                   setVersion(4)
           up()

       2

             1                         14
Migrations and sf CLI


                        15
Migrations and sf CLI

        symfony   doctrine:generate-migrations-models
        symfony   doctrine:generate-migrations-db
        symfony   doctrine:generate-migrations-diff
        symfony   doctrine:migrate




                                                        16
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
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
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
Migrations and sf CLI


        symfony doctrine:generate-migrations-models




                                                      17
Migrations and sf CLI


        symfony doctrine:generate-migrations-models




     Compares Model files and schema.yml




                                                      17
Migrations and sf CLI


        symfony doctrine:generate-migrations-models




     Compares Model files and schema.yml
     Good when starting without schema




                                                      17
Migrations and sf CLI


        symfony doctrine:generate-migrations-db




                                                  18
Migrations and sf CLI


          symfony doctrine:generate-migrations-db




      Compares DB tables and schema.yml




                                                    18
Migrations and sf CLI


          symfony doctrine:generate-migrations-db




      Compares DB tables and schema.yml
       Good when starting with schema




                                                    18
Creating a Migration Diff


                        Before
 BlogPost:
   # [...]
   columns:
     title:    { type: string(255), notnull: true }
     # [...]




                                                      19
Creating a Migration Diff


                         After
 BlogPost:
   # [...]
   columns:
     title:    { type: string(255), notnull: true }
     # [...]
     tags:     { type: string(255) }




                                                      20
Migrations and sf CLI


        symfony doctrine:generate-migrations-diff




                                                    21
Migrations and sf CLI


           symfony doctrine:generate-migrations-diff




   Compares changed schema.yml and Model files




                                                       21
Migrations and sf CLI


           symfony doctrine:generate-migrations-diff




   Compares changed schema.yml and Model files
      Good when already using Migrations




                                                       21
Migrating using sf CLI

           symfony   doctrine:migrate
           symfony   doctrine:build-model
           symfony   doctrine:build-filters
           symfony   doctrine:build-forms




                                              22
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
Migrating using sf CLI


          symfony doctrine:migrate
          symfony doctrine:build --all-classes




                                                 23
Migrating using sf CLI


          symfony doctrine:migrate
          symfony doctrine:build --all-classes




             That‘s the nice way




                                                 23
Migrating using sf CLI


       symfony doctrine:build --all-classes --and-migrate




                                                            24
Migrating using sf CLI


       symfony doctrine:build --all-classes --and-migrate




             That‘s the cool sf 1.3 way




                                                            24
Things to keep in mind


                         25
Big vs. small Migrations



          aka. „Complete Migrations“
   vs. „Wild West Cowboy Style Migrations“




                                             26
Big vs. small Migrations




                           27
Big vs. small Migrations


         Small Migrations more Agile




                                       27
Big vs. small Migrations


         Small Migrations more Agile
          Really need to be Agile?!




                                       27
Big vs. small Migrations


         Small Migrations more Agile
          Really need to be Agile?!
         Small Migrations more dirty




                                       27
Big vs. small Migrations


         Small Migrations more Agile
           Really need to be Agile?!
         Small Migrations more dirty
       Big Migrations more complicated




                                         27
Keep in mind


     Run a diff before building the model




                                            28
Keep in mind


      Run a diff before building the model



    After migrating you can‘t generate the diff!




                                                   28
Keep in mind


       Keep Data Migrations simple




                                     29
Keep in mind


         Keep Data Migrations simple



      Migrate the Data as easy as possible!




                                              29
Keep in mind


  Version get‘s updated after all Migrations are run




                                                       30
Keep in mind


  Version get‘s updated after all Migrations are run



    You have to fix problems by hand if they fail.




                                                       30
Thank you!


             31
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

Weitere ähnliche Inhalte

Ähnlich wie Doctrine Migrations: Automate Database Changes

Flyway (33rd Degree)
Flyway (33rd Degree)Flyway (33rd Degree)
Flyway (33rd Degree)Axel Fontaine
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaAxel Fontaine
 
Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)Patrick Crowley
 
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Alan Pinstein
 
Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...
Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...
Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...Philip Stehlik
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best PracticesBurt Beckwith
 
Using Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize DatabasesUsing Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize DatabasesBryce Embry
 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...HostedbyConfluent
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfKarsten Dambekalns
 
Evolutionary Database Design
Evolutionary Database DesignEvolutionary Database Design
Evolutionary Database DesignAndrei Solntsev
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteDr Nic Williams
 
Db2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallsDb2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallssam2sung2
 
Come Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayCome Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayJoris Kuipers
 
MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011Mats Kindahl
 
Immutable kubernetes architecture by linuxkit
Immutable kubernetes architecture by linuxkitImmutable kubernetes architecture by linuxkit
Immutable kubernetes architecture by linuxkit어형 이
 
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architectureOpenStack Korea Community
 

Ähnlich wie Doctrine Migrations: Automate Database Changes (20)

Flyway (33rd Degree)
Flyway (33rd Degree)Flyway (33rd Degree)
Flyway (33rd Degree)
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for Java
 
Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)
 
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
 
Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...
Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...
Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup ...
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best Practices
 
Using Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize DatabasesUsing Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize Databases
 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
 
Containers 101
Containers 101Containers 101
Containers 101
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using Surf
 
Evolutionary Database Design
Evolutionary Database DesignEvolutionary Database Design
Evolutionary Database Design
 
Offline Html5 3days
Offline Html5 3daysOffline Html5 3days
Offline Html5 3days
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Upgrading 11i E-business Suite to R12 E-business Suite
Upgrading 11i E-business Suite to R12 E-business SuiteUpgrading 11i E-business Suite to R12 E-business Suite
Upgrading 11i E-business Suite to R12 E-business Suite
 
Db2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallsDb2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfalls
 
Come Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayCome Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with Flyway
 
MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011
 
Immutable kubernetes architecture by linuxkit
Immutable kubernetes architecture by linuxkitImmutable kubernetes architecture by linuxkit
Immutable kubernetes architecture by linuxkit
 
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
 
Migrate in Drupal 8
Migrate in Drupal 8Migrate in Drupal 8
Migrate in Drupal 8
 

Mehr von D

Monitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandMonitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandD
 
Introduction to Docker & CoreOS - Symfony User Group Cologne
Introduction to Docker & CoreOS - Symfony User Group CologneIntroduction to Docker & CoreOS - Symfony User Group Cologne
Introduction to Docker & CoreOS - Symfony User Group CologneD
 
The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013D
 
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013D
 
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...D
 
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…D
 
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...D
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012D
 
Cologne Web Performance Optimization Group Web - Varnish
Cologne Web Performance Optimization Group Web - VarnishCologne Web Performance Optimization Group Web - Varnish
Cologne Web Performance Optimization Group Web - VarnishD
 
symfony live 2010 - Using symfony events to create clean class interfaces
symfony live 2010 - Using symfony events to create clean class interfacessymfony live 2010 - Using symfony events to create clean class interfaces
symfony live 2010 - Using symfony events to create clean class interfacesD
 
symfony and immobilienscout24.de - Dennis Benkert
symfony and immobilienscout24.de - Dennis Benkertsymfony and immobilienscout24.de - Dennis Benkert
symfony and immobilienscout24.de - Dennis BenkertD
 
symfony and immobilienscout24.de - Rob Bors
symfony and immobilienscout24.de - Rob Borssymfony and immobilienscout24.de - Rob Bors
symfony and immobilienscout24.de - Rob BorsD
 
Railslove Lightningtalk 20 02 09 - Web Debug Toolbars
Railslove Lightningtalk 20 02 09 - Web Debug ToolbarsRailslove Lightningtalk 20 02 09 - Web Debug Toolbars
Railslove Lightningtalk 20 02 09 - Web Debug ToolbarsD
 

Mehr von D (13)

Monitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandMonitoring und Metriken im Wunderland
Monitoring und Metriken im Wunderland
 
Introduction to Docker & CoreOS - Symfony User Group Cologne
Introduction to Docker & CoreOS - Symfony User Group CologneIntroduction to Docker & CoreOS - Symfony User Group Cologne
Introduction to Docker & CoreOS - Symfony User Group Cologne
 
The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013
 
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
 
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
 
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
 
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Cologne Web Performance Optimization Group Web - Varnish
Cologne Web Performance Optimization Group Web - VarnishCologne Web Performance Optimization Group Web - Varnish
Cologne Web Performance Optimization Group Web - Varnish
 
symfony live 2010 - Using symfony events to create clean class interfaces
symfony live 2010 - Using symfony events to create clean class interfacessymfony live 2010 - Using symfony events to create clean class interfaces
symfony live 2010 - Using symfony events to create clean class interfaces
 
symfony and immobilienscout24.de - Dennis Benkert
symfony and immobilienscout24.de - Dennis Benkertsymfony and immobilienscout24.de - Dennis Benkert
symfony and immobilienscout24.de - Dennis Benkert
 
symfony and immobilienscout24.de - Rob Bors
symfony and immobilienscout24.de - Rob Borssymfony and immobilienscout24.de - Rob Bors
symfony and immobilienscout24.de - Rob Bors
 
Railslove Lightningtalk 20 02 09 - Web Debug Toolbars
Railslove Lightningtalk 20 02 09 - Web Debug ToolbarsRailslove Lightningtalk 20 02 09 - Web Debug Toolbars
Railslove Lightningtalk 20 02 09 - Web Debug Toolbars
 

Kürzlich hochgeladen

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Doctrine Migrations: Automate Database Changes

  • 1. Using Doctrine Migrations by Dennis Benkert
  • 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
  • 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
  • 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
  • 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
  • 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