SlideShare a Scribd company logo
1 of 19
Download to read offline
Nashville symfony Group




The Art of Doctrine Migrations
           Feb 2nd, 2010


          Ryan Weaver
          @weaverryan
          iostudio.com
       www.thatsquality.com
Nashville symfony Group Feb 2010



So you've updated your code, now to update
 your database...
  
      PhpMyAdmin: post-it notes, pizza & beer
  
      SQL deltas:
      
        Pros: familiar syntax, tools available
      
        Cons: not systematic, db-specific, disconnected from ORM
  
      Doctrine Migrations:
      
        Pros: systematic, generate automatically, written in Nashville
        (probably)
      
        Cons: were a pain in the ass (until now), still a bit quirky
Nashville symfony Group Feb 2010


    A PHP file with simple
    directions on how to
    update your database

   Each file is prefixed by a
   number, which determines
   its ordering:

   /lib/migration/doctrine/
      
        1_add_brilliant_idea_table.php
      
        2_add_good_people_table.php
      
        3_add_desc_field_to_idea.php
Nashville symfony Group Feb 2010


Tracking Versions

Doctrine keeps track of
your db's “version” via
migration_version table



/lib/migration/doctrine/
   
     1_add_brilliant_idea_table.php           version 1
   
     2_add_good_people_table.php              version 2
   
     3_add_desc_field_to_idea.php             version 3
   
     4_modify_some_column.php                 version 4
   
     35_alternatively_numbered.php            version 5
Nashville symfony Group Feb 2010


Take a deep breath and migrate:
     ./symfony doctrine:migrate [migration #]
Nashville symfony Group Feb 2010


Writing Migrations
Create a blank migration file:
    doctrine:generate-migration name
 
     Creates a blank file in lib/migration/doctrine
      (e.g. 1265085881_add_another_table.php)
 
  Use the rich API to
 make changes




 www.doctrine-project.org/Doctrine-
      Cheat-Sheet-1.1.pdf
Nashville symfony Group Feb 2010




Or just generate the migrations automatically...
Nashville symfony Group Feb 2010


Generate Migrations
For an existing database & project with no migrations:
     doctrine:generate-migrations-db

• Generates migration classes for everything to date
• For example, for a project with 75 tables, this would generate
  76 migration classes
• (1 per table + 1 giant class for all indexes and foreign keys)


  This gets you “caught up”, but only works once.
Nashville symfony Group Feb 2010


Migration-diff tool
Generates new migration class(es) based on some schema
  change

1) Make a change to your schema (e.g. add a column)
2) Run the diff tool task:
     doctrine:generate-migrations-diff
3) Rebuild your model
     doctrine:build --all

This runs a “diff” between your new schema and your
old model files.
Lame/Warning: If you rebuild your model before running the diff
tool, no changes will be recognized
Nashville symfony Group Feb 2010


Filename Conventions
Generated migrations take one of these 2 forms:
       263866565_migration_name.php
       263866565_version15.php
We recommend renaming to include the version #:
      version1_migration_name.php
      263866565_version15.php
Nashville symfony Group Feb 2010


Model Name Conventions
Generated migrations take one of these 2 forms:
       class Version15
       class MigrationName

We recommend naming the class by the version #:
        class Version 15
Nashville symfony Group Feb 2010


Data Migrations – easy, but...

                                        Also can use:
                                        - preUp()
                                        - preDown()

                                         This will break
                                         eventually, when
                                         you make
                                         changes to the
                                         BrilliantIdea model
                                         (e.g. in 2 months,
                                         you remove the
                                         name field)
Nashville symfony Group Feb 2010


Doctrine Migration – Ruining your day


1) NEVER mix foreign-key changes with table or
column changes                                           Major
     $this->createTable('brilliant_idea',...)           migration
     $this->createForeignKey('brilliant_idea', …)         foul
2) If you care, be careful with your index names
       Name 'product_slug' becomes 'product_slug_idx'
Nashville symfony Group Feb 2010


Tools – MySQLdiff (http://www.mysqldiff.org/)
 • Simple: compares two databases and gives you a list of their
 differences
     – build-all-reload your main database
     – Migrate your test database
Nashville symfony Group Feb 2010


Discussion Notes from the Presentation

 Migration Failures
 Suppose you're migrating from version 2-10 and migration
 #5 fails:
    ●
        Migrations 6-10 will continue to try to run
    ●
        The migration_version table will still be set to 2 after
        the migration, even though versions 3 & 4 were
        successful
Nashville symfony Group Feb 2010


Discussion Notes from the Presentation

 generate-migrations-db
    ●
        In theory, this task compares your db to your models
        and generate migrations based on the difference.
    ●
        After weeks of dev, all migrations could be generated
        at once
    ●
        At least 2 bugs exist in this task:
         ●
           http://pastebin.com/f7e11c784
         ●
           Models prefixed with a lowercase letter will not
           work. But, this does not affect most MACs
Nashville symfony Group Feb 2010


Discussion Notes from the Presentation
 Resetting your migrations
    ●
        To battle “broken” migrations that result from data
        migrations that reference no-longer-used fields, it
        may be a good idea to adopt a strategy of periodically
        “resetting” your migrations:
         ●
           Delete all migration files
         ●
           Run doctrine:generate-migrations-db
         ●
           Manually set your migration_version number to the
           last, newly-generated migration file
Nashville symfony Group Feb 2010


Discussion Notes from the Presentation
 Autoloading Bugs in generate-migrations-diff
    ●
        When using the diff tool, you may get an error such
        as: “Cannot find class PrfxSomeClass”
    ●
        The diff tool generates temporary models and in
        some cases (specifically doctrine model subclassing)
        will require the files in the wrong order
    ●
        There is a hack (try the autoload.yml hack):
         ●
           http://trac.symfony-
           project.org/ticket/7272#comment:13
Nashville symfony Group Feb 2010


Questions? Idea Bubbles?



                   Ryan Weaver
                   @weaverryan
                   iostudio.com
                www.thatsquality.com

More Related Content

What's hot

Bab v. kepribadian dan gaya hidup
Bab v. kepribadian dan gaya hidupBab v. kepribadian dan gaya hidup
Bab v. kepribadian dan gaya hidupvajri rahman
 
Bab 10. mempengaruhi perilaku konsumen
Bab 10. mempengaruhi perilaku konsumenBab 10. mempengaruhi perilaku konsumen
Bab 10. mempengaruhi perilaku konsumenJudianto Nugroho
 
Báo cáo về thói quen mua hàng và quảng cáo online 2014
Báo cáo về thói quen mua hàng và quảng cáo online 2014Báo cáo về thói quen mua hàng và quảng cáo online 2014
Báo cáo về thói quen mua hàng và quảng cáo online 2014Nguyễn Duy Nhân
 
Bab ii. pengambilan keputusan konsumen
Bab ii. pengambilan keputusan konsumenBab ii. pengambilan keputusan konsumen
Bab ii. pengambilan keputusan konsumenvajri rahman
 
Giáo trình hành vi người tiêu dùng
Giáo trình hành vi người tiêu dùngGiáo trình hành vi người tiêu dùng
Giáo trình hành vi người tiêu dùngbookboomingslide
 
Etika Bisnis_Periklanan dan Etika
Etika Bisnis_Periklanan dan EtikaEtika Bisnis_Periklanan dan Etika
Etika Bisnis_Periklanan dan EtikaRatnawaty_RMG
 
Pertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.ppt
Pertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.pptPertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.ppt
Pertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.pptLalu M
 
Cocacola vietnam
Cocacola vietnamCocacola vietnam
Cocacola vietnamEric Bui
 
E Com Ch01 Tong Quan Thuong Mai Dien Tu
E Com Ch01 Tong Quan Thuong Mai Dien TuE Com Ch01 Tong Quan Thuong Mai Dien Tu
E Com Ch01 Tong Quan Thuong Mai Dien TuChuong Nguyen
 
Bab 8 mengidentifikasi segmen dan target pasar
Bab 8 mengidentifikasi segmen dan target pasarBab 8 mengidentifikasi segmen dan target pasar
Bab 8 mengidentifikasi segmen dan target pasarJudianto Nugroho
 
Cerpen Pengalaman Pribadi
Cerpen Pengalaman PribadiCerpen Pengalaman Pribadi
Cerpen Pengalaman PribadiDevi Putri
 
Analisis perilaku konsumen menurut schiffman n kanuk
Analisis perilaku konsumen menurut schiffman n kanukAnalisis perilaku konsumen menurut schiffman n kanuk
Analisis perilaku konsumen menurut schiffman n kanukINDOMARET
 
Ppt lingkungan pemasaran
Ppt lingkungan pemasaranPpt lingkungan pemasaran
Ppt lingkungan pemasaranLauraNirma
 
Giáo trình xây dựng hệ thống Vision
Giáo trình xây dựng hệ thống VisionGiáo trình xây dựng hệ thống Vision
Giáo trình xây dựng hệ thống VisionVision-VN
 

What's hot (20)

Bab v. kepribadian dan gaya hidup
Bab v. kepribadian dan gaya hidupBab v. kepribadian dan gaya hidup
Bab v. kepribadian dan gaya hidup
 
Bab 10. mempengaruhi perilaku konsumen
Bab 10. mempengaruhi perilaku konsumenBab 10. mempengaruhi perilaku konsumen
Bab 10. mempengaruhi perilaku konsumen
 
Báo cáo về thói quen mua hàng và quảng cáo online 2014
Báo cáo về thói quen mua hàng và quảng cáo online 2014Báo cáo về thói quen mua hàng và quảng cáo online 2014
Báo cáo về thói quen mua hàng và quảng cáo online 2014
 
Bab ii. pengambilan keputusan konsumen
Bab ii. pengambilan keputusan konsumenBab ii. pengambilan keputusan konsumen
Bab ii. pengambilan keputusan konsumen
 
Loship Culture Deck
Loship Culture DeckLoship Culture Deck
Loship Culture Deck
 
Đề tài: Phân tích chiến lược bán hàng trực tuyến Lazada
Đề tài: Phân tích chiến lược bán hàng trực tuyến LazadaĐề tài: Phân tích chiến lược bán hàng trực tuyến Lazada
Đề tài: Phân tích chiến lược bán hàng trực tuyến Lazada
 
Giáo trình hành vi người tiêu dùng
Giáo trình hành vi người tiêu dùngGiáo trình hành vi người tiêu dùng
Giáo trình hành vi người tiêu dùng
 
Etika Bisnis_Periklanan dan Etika
Etika Bisnis_Periklanan dan EtikaEtika Bisnis_Periklanan dan Etika
Etika Bisnis_Periklanan dan Etika
 
Bài tập tự luyện Content - Copywriting
Bài tập tự luyện Content - CopywritingBài tập tự luyện Content - Copywriting
Bài tập tự luyện Content - Copywriting
 
Pertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.ppt
Pertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.pptPertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.ppt
Pertemuan Ke 2,3 MOTIVASI-DAN-KEBUTUHAN.ppt
 
Cocacola vietnam
Cocacola vietnamCocacola vietnam
Cocacola vietnam
 
E Com Ch01 Tong Quan Thuong Mai Dien Tu
E Com Ch01 Tong Quan Thuong Mai Dien TuE Com Ch01 Tong Quan Thuong Mai Dien Tu
E Com Ch01 Tong Quan Thuong Mai Dien Tu
 
BÀI MẪU tiểu luận về thời trang, HAY
BÀI MẪU tiểu luận về thời trang, HAY BÀI MẪU tiểu luận về thời trang, HAY
BÀI MẪU tiểu luận về thời trang, HAY
 
Bab 8 mengidentifikasi segmen dan target pasar
Bab 8 mengidentifikasi segmen dan target pasarBab 8 mengidentifikasi segmen dan target pasar
Bab 8 mengidentifikasi segmen dan target pasar
 
Cerpen Pengalaman Pribadi
Cerpen Pengalaman PribadiCerpen Pengalaman Pribadi
Cerpen Pengalaman Pribadi
 
Bí mật Dotcom
Bí mật DotcomBí mật Dotcom
Bí mật Dotcom
 
Analisis perilaku konsumen menurut schiffman n kanuk
Analisis perilaku konsumen menurut schiffman n kanukAnalisis perilaku konsumen menurut schiffman n kanuk
Analisis perilaku konsumen menurut schiffman n kanuk
 
Ppt lingkungan pemasaran
Ppt lingkungan pemasaranPpt lingkungan pemasaran
Ppt lingkungan pemasaran
 
Giáo trình xây dựng hệ thống Vision
Giáo trình xây dựng hệ thống VisionGiáo trình xây dựng hệ thống Vision
Giáo trình xây dựng hệ thống Vision
 
QUẢN TRỊ HỌC VỀ XÂY DỰNG CHIẾN LƯỢC KINH DOANH QUÁN CAFE (TẢI FREE ZALO 093 4...
QUẢN TRỊ HỌC VỀ XÂY DỰNG CHIẾN LƯỢC KINH DOANH QUÁN CAFE (TẢI FREE ZALO 093 4...QUẢN TRỊ HỌC VỀ XÂY DỰNG CHIẾN LƯỢC KINH DOANH QUÁN CAFE (TẢI FREE ZALO 093 4...
QUẢN TRỊ HỌC VỀ XÂY DỰNG CHIẾN LƯỢC KINH DOANH QUÁN CAFE (TẢI FREE ZALO 093 4...
 

Similar to The Art of Doctrine Migrations

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
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesdrupalindia
 
AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!
AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!
AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!Christoph Adler
 
PHP North-East - Automated Deployment
PHP North-East - Automated DeploymentPHP North-East - Automated Deployment
PHP North-East - Automated DeploymentMichael Peacock
 
Automated Deployment
Automated DeploymentAutomated Deployment
Automated Deploymentphpne
 
Designing For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps SlideshareDesigning For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps SlideshareDean Willson
 
ICONUK 2014 Connections Migration Tips and Tricks
ICONUK 2014 Connections Migration Tips and TricksICONUK 2014 Connections Migration Tips and Tricks
ICONUK 2014 Connections Migration Tips and TricksVictor Toal
 
SVN Tool Information : Best Practices
SVN Tool Information  : Best PracticesSVN Tool Information  : Best Practices
SVN Tool Information : Best PracticesMaidul Islam
 
IBM Notes 10.0.1 FP2 Client Upgrades - made easy!
IBM Notes 10.0.1 FP2 Client Upgrades - made easy!IBM Notes 10.0.1 FP2 Client Upgrades - made easy!
IBM Notes 10.0.1 FP2 Client Upgrades - made easy!panagenda
 
BW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & Migration
BW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & MigrationBW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & Migration
BW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & MigrationLinh Nguyen
 
Schema migration (DB migration) with Phinx
Schema migration (DB migration) with PhinxSchema migration (DB migration) with Phinx
Schema migration (DB migration) with PhinxHadi Ariawan
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 
2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficiently2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficientlyBruno Capuano
 
RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...
RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...
RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...Christoph Adler
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationMassimo Menichinelli
 
Git and GitFlow branching model
Git and GitFlow branching modelGit and GitFlow branching model
Git and GitFlow branching modelPavlo Hodysh
 
Feature Based Web Development with Bazaar
Feature Based Web Development with BazaarFeature Based Web Development with Bazaar
Feature Based Web Development with Bazaaryogomozilla
 
Drupal Version Control & File System Basics
Drupal Version Control & File System BasicsDrupal Version Control & File System Basics
Drupal Version Control & File System BasicsJulia Kulla-Mader
 

Similar to The Art of Doctrine Migrations (20)

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 ...
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
 
Recipes for Drupal distributions
Recipes for Drupal distributionsRecipes for Drupal distributions
Recipes for Drupal distributions
 
AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!
AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!
AdminCamp2019 - Notes V10 Upgrades - Alles was man wissen muss!
 
PHP North-East - Automated Deployment
PHP North-East - Automated DeploymentPHP North-East - Automated Deployment
PHP North-East - Automated Deployment
 
Automated Deployment
Automated DeploymentAutomated Deployment
Automated Deployment
 
Designing For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps SlideshareDesigning For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps Slideshare
 
ICONUK 2014 Connections Migration Tips and Tricks
ICONUK 2014 Connections Migration Tips and TricksICONUK 2014 Connections Migration Tips and Tricks
ICONUK 2014 Connections Migration Tips and Tricks
 
SVN Tool Information : Best Practices
SVN Tool Information  : Best PracticesSVN Tool Information  : Best Practices
SVN Tool Information : Best Practices
 
IBM Notes 10.0.1 FP2 Client Upgrades - made easy!
IBM Notes 10.0.1 FP2 Client Upgrades - made easy!IBM Notes 10.0.1 FP2 Client Upgrades - made easy!
IBM Notes 10.0.1 FP2 Client Upgrades - made easy!
 
BW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & Migration
BW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & MigrationBW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & Migration
BW Migration to HANA Part 2 - SUM DMO Tool for SAP Upgrade & Migration
 
Schema migration (DB migration) with Phinx
Schema migration (DB migration) with PhinxSchema migration (DB migration) with Phinx
Schema migration (DB migration) with Phinx
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Svn Basic Tutorial
Svn Basic TutorialSvn Basic Tutorial
Svn Basic Tutorial
 
2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficiently2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficiently
 
RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...
RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...
RNUG - SUPERCHARGED HCL Notes V11 Upgrades: Turning the WORST Notes deploymen...
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: Information
 
Git and GitFlow branching model
Git and GitFlow branching modelGit and GitFlow branching model
Git and GitFlow branching model
 
Feature Based Web Development with Bazaar
Feature Based Web Development with BazaarFeature Based Web Development with Bazaar
Feature Based Web Development with Bazaar
 
Drupal Version Control & File System Basics
Drupal Version Control & File System BasicsDrupal Version Control & File System Basics
Drupal Version Control & File System Basics
 

More from Ryan Weaver

Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017Ryan Weaver
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Ryan Weaver
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityRyan Weaver
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 
Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Ryan Weaver
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexRyan Weaver
 
Silex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonySilex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonyRyan Weaver
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itRyan Weaver
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsRyan Weaver
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsRyan Weaver
 
A PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appA PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appRyan Weaver
 
Symfony2: Get your project started
Symfony2: Get your project startedSymfony2: Get your project started
Symfony2: Get your project startedRyan Weaver
 
Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkRyan Weaver
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkRyan Weaver
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Ryan Weaver
 
Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with TwigRyan Weaver
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 MinutesRyan Weaver
 

More from Ryan Weaver (20)

Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Silex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender SymfonySilex: Microframework y camino fácil de aprender Symfony
Silex: Microframework y camino fácil de aprender Symfony
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony Components
 
A PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 appA PHP Christmas Miracle - 3 Frameworks, 1 app
A PHP Christmas Miracle - 3 Frameworks, 1 app
 
Symfony2: Get your project started
Symfony2: Get your project startedSymfony2: Get your project started
Symfony2: Get your project started
 
Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP Framework
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
 
Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)Being Dangerous with Twig (Symfony Live Paris)
Being Dangerous with Twig (Symfony Live Paris)
 
Being Dangerous with Twig
Being Dangerous with TwigBeing Dangerous with Twig
Being Dangerous with Twig
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 Minutes
 

Recently uploaded

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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
[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
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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 ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
[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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

The Art of Doctrine Migrations

  • 1. Nashville symfony Group The Art of Doctrine Migrations Feb 2nd, 2010 Ryan Weaver @weaverryan iostudio.com www.thatsquality.com
  • 2. Nashville symfony Group Feb 2010 So you've updated your code, now to update your database...  PhpMyAdmin: post-it notes, pizza & beer  SQL deltas:  Pros: familiar syntax, tools available  Cons: not systematic, db-specific, disconnected from ORM  Doctrine Migrations:  Pros: systematic, generate automatically, written in Nashville (probably)  Cons: were a pain in the ass (until now), still a bit quirky
  • 3. Nashville symfony Group Feb 2010 A PHP file with simple directions on how to update your database Each file is prefixed by a number, which determines its ordering: /lib/migration/doctrine/  1_add_brilliant_idea_table.php  2_add_good_people_table.php  3_add_desc_field_to_idea.php
  • 4. Nashville symfony Group Feb 2010 Tracking Versions Doctrine keeps track of your db's “version” via migration_version table /lib/migration/doctrine/  1_add_brilliant_idea_table.php version 1  2_add_good_people_table.php version 2  3_add_desc_field_to_idea.php version 3  4_modify_some_column.php version 4  35_alternatively_numbered.php version 5
  • 5. Nashville symfony Group Feb 2010 Take a deep breath and migrate: ./symfony doctrine:migrate [migration #]
  • 6. Nashville symfony Group Feb 2010 Writing Migrations Create a blank migration file: doctrine:generate-migration name  Creates a blank file in lib/migration/doctrine (e.g. 1265085881_add_another_table.php)  Use the rich API to make changes www.doctrine-project.org/Doctrine- Cheat-Sheet-1.1.pdf
  • 7. Nashville symfony Group Feb 2010 Or just generate the migrations automatically...
  • 8. Nashville symfony Group Feb 2010 Generate Migrations For an existing database & project with no migrations: doctrine:generate-migrations-db • Generates migration classes for everything to date • For example, for a project with 75 tables, this would generate 76 migration classes • (1 per table + 1 giant class for all indexes and foreign keys) This gets you “caught up”, but only works once.
  • 9. Nashville symfony Group Feb 2010 Migration-diff tool Generates new migration class(es) based on some schema change 1) Make a change to your schema (e.g. add a column) 2) Run the diff tool task: doctrine:generate-migrations-diff 3) Rebuild your model doctrine:build --all This runs a “diff” between your new schema and your old model files. Lame/Warning: If you rebuild your model before running the diff tool, no changes will be recognized
  • 10. Nashville symfony Group Feb 2010 Filename Conventions Generated migrations take one of these 2 forms: 263866565_migration_name.php 263866565_version15.php We recommend renaming to include the version #: version1_migration_name.php 263866565_version15.php
  • 11. Nashville symfony Group Feb 2010 Model Name Conventions Generated migrations take one of these 2 forms: class Version15 class MigrationName We recommend naming the class by the version #: class Version 15
  • 12. Nashville symfony Group Feb 2010 Data Migrations – easy, but... Also can use: - preUp() - preDown() This will break eventually, when you make changes to the BrilliantIdea model (e.g. in 2 months, you remove the name field)
  • 13. Nashville symfony Group Feb 2010 Doctrine Migration – Ruining your day 1) NEVER mix foreign-key changes with table or column changes Major $this->createTable('brilliant_idea',...) migration $this->createForeignKey('brilliant_idea', …) foul 2) If you care, be careful with your index names Name 'product_slug' becomes 'product_slug_idx'
  • 14. Nashville symfony Group Feb 2010 Tools – MySQLdiff (http://www.mysqldiff.org/) • Simple: compares two databases and gives you a list of their differences – build-all-reload your main database – Migrate your test database
  • 15. Nashville symfony Group Feb 2010 Discussion Notes from the Presentation Migration Failures Suppose you're migrating from version 2-10 and migration #5 fails: ● Migrations 6-10 will continue to try to run ● The migration_version table will still be set to 2 after the migration, even though versions 3 & 4 were successful
  • 16. Nashville symfony Group Feb 2010 Discussion Notes from the Presentation generate-migrations-db ● In theory, this task compares your db to your models and generate migrations based on the difference. ● After weeks of dev, all migrations could be generated at once ● At least 2 bugs exist in this task: ● http://pastebin.com/f7e11c784 ● Models prefixed with a lowercase letter will not work. But, this does not affect most MACs
  • 17. Nashville symfony Group Feb 2010 Discussion Notes from the Presentation Resetting your migrations ● To battle “broken” migrations that result from data migrations that reference no-longer-used fields, it may be a good idea to adopt a strategy of periodically “resetting” your migrations: ● Delete all migration files ● Run doctrine:generate-migrations-db ● Manually set your migration_version number to the last, newly-generated migration file
  • 18. Nashville symfony Group Feb 2010 Discussion Notes from the Presentation Autoloading Bugs in generate-migrations-diff ● When using the diff tool, you may get an error such as: “Cannot find class PrfxSomeClass” ● The diff tool generates temporary models and in some cases (specifically doctrine model subclassing) will require the files in the wrong order ● There is a hack (try the autoload.yml hack): ● http://trac.symfony- project.org/ticket/7272#comment:13
  • 19. Nashville symfony Group Feb 2010 Questions? Idea Bubbles? Ryan Weaver @weaverryan iostudio.com www.thatsquality.com