Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Art of Doctrine Migrations

27,113 views

Published on

Doctrine Migrations presentation from the nasvhille symfony user group - February 2010

Published in: Technology
  • A professional Paper writing services can alleviate your stress in writing a successful paper and take the pressure off you to hand it in on time. Check out, please ⇒ www.HelpWriting.net ⇐
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❤❤❤ http://bit.ly/2F90ZZC ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ♥♥♥ http://bit.ly/2F90ZZC ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @beachDefender-

    I don't exactly what problem you're getting at, but I do know that there are definitely issues with Doctrine1 (and Doctrine1's migrations) related to the naming of things, how versions are tracked etc. In fact, the importance of this presentation is really to highlight how you can use a system that's far from perfect to solve a problem.

    The better answer is this: Symfony2 and Doctrine2 are different. The Doctrine migrations now exist as a standalone library from the Doctrine community and - while not yet stable - is very well done (the design takes a lot from other languages and how they solve the problem of migrations). Symfony2 is much the same way - nothing is imposed on you and where there *are* standards, they exist only for convenience and you're free to use whatever standard you want.

    So, if you're frustrated by some issues or conventions with Doctrine1 or symfony1, I'd encourage you to have a look at Doctrine2 and Symfony2 - a lot of work has been done to learn from the first versions.

    And if I totally missed your question/comment, let me know :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

The Art of Doctrine Migrations

  1. 1. Nashville symfony Group The Art of Doctrine Migrations Feb 2nd, 2010 Ryan Weaver @weaverryan iostudio.com www.thatsquality.com
  2. 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. 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. 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. 5. Nashville symfony Group Feb 2010 Take a deep breath and migrate: ./symfony doctrine:migrate [migration #]
  6. 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. 7. Nashville symfony Group Feb 2010 Or just generate the migrations automatically...
  8. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 19. Nashville symfony Group Feb 2010 Questions? Idea Bubbles? Ryan Weaver @weaverryan iostudio.com www.thatsquality.com

×