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.

PHP Tour 2016 Phinx Presentation

695 views

Published on

Phinx is one of the most popular standalone database migration tools. Learn the basic concepts of Phinx with its creator Rob Morgan. This presentation covers adding it to a project, creating new migrations and then executing them, . You are also exposed to more advanced features of Phinx and everyday use cases.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

PHP Tour 2016 Phinx Presentation

  1. 1. Rob Morgan @_rjm_ #phinx #php #phptour
  2. 2. What is a Database or Schema Migration?
  3. 3. “A schema migration is performed on a database whenever it is necessary to update or revert that database's schema to some newer or older version. Migrations are performed programmatically by using a schema migration tool.”
  4. 4. source: https://en.wikipedia.org/wiki/Schema_migration
  5. 5. What is Phinx? “Phinx is a tool that allows you to migrate your database schema over time”
  6. 6. Rob Morgan • Creator & Lead Developer of Phinx • Writing PHP for almost 15 years • Email: robbym@gmail.com • https://robmorgan.id.au @_rjm_
  7. 7. asd Australia
  8. 8. Brief History • Open Sourced in 2012 under the MIT License • 38 Releases to Date • 1.2 million Downloads and 115+ Contributors • Used in CakePHP 3.0.0 • Built on top of Symfony Components (and only 3)
  9. 9. Features • Write database migrations using PHP code • Migrate up and down • Seed data after database creation • Take advantage of SCM features such as branching • Integrate with any app • Get going in less than 5 minutes
  10. 10. Supported Databases
  11. 11. Test Matrix MySQL PostgreSQL SQLite SQL Server PHP 5.4 ❌ ❌ ❌ ❌ PHP 5.5 ❌ ❌ ❌ ❌ PHP 5.6 ❌ ❌ ❌ ❌ PHP 7 ❌ ❌ ❌ ❌ HHVM ❌
  12. 12. Why did I write Phinx?
  13. 13. We started to look for better solutions
  14. 14. Phing with DbDeploy
  15. 15. We developed on Mac & Linux, but deployed on Windows
  16. 16. Why Should I Use Phinx?
  17. 17. Phinx is Fast
  18. 18. It requires PHP 5.4
  19. 19. Production Ready
  20. 20. How can I install Phinx? • Pear • Composer • Build a Phar package (see Github)
  21. 21. How can I install Phinx? • Pear • Composer • Build a Phar package (see Github)
  22. 22. It’s a command line application (although it does contain a web application)
  23. 23. $ vendor/bin/phinx
  24. 24. Creating a migration
  25. 25. $ vendor/bin/phinx create CreatePostsTable
  26. 26. Phinx by Rob Morgan - https://phinx.org. version 0.5.3 using config file ./phinx.yml using config parser yaml using migration path /Users/robbym/Code/phinx/db/migrations using seed path /Users/robbym/Code/phinx/db/seeds using migration base class PhinxMigrationAbstractMigration using default template created ./db/migrations/20160309162303_create_posts_table.php
  27. 27. Phinx by Rob Morgan - https://phinx.org. version 0.5.3 using config file ./phinx.yml using config parser yaml using migration path /Users/robbym/Code/phinx/db/migrations using seed path /Users/robbym/Code/phinx/db/seeds using migration base class PhinxMigrationAbstractMigration using default template created ./db/migrations/20160309162303_create_posts_table.php
  28. 28. Best Practises • Write environment agnostic code • Version control your migrations • Enforce default values in the migrations themselves • Avoid custom SQL if possible • Use the change method by default
  29. 29. Reversible Migrations
  30. 30. Only some methods can be reversed!
  31. 31. createTable renameTable addColumn renameColumn addIndex addForeignIndex
  32. 32. Seed Command
  33. 33. $ vendor/bin/phinx seed:create UserSeeder $ vendor/bin/phinx seed:run -e development
  34. 34. Real World Use Case
  35. 35. Let’s pretend our Customer wants us to build a new web application
  36. 36. The Customer • He wants a competitor to Wordpress • Needs it tomorrow • Willing to pay alot some money
  37. 37. Phinx can help!
 (but not do everything)
  38. 38. But first we must install it…
  39. 39. Installing via Composer
  40. 40. # first require Phinx $ php composer.phar require robmorgan/phinx # then install it including the dependencies $ php composer.phar install
  41. 41. Creating a Migration
  42. 42. What’s coming in Phinx 0.6.0?
  43. 43. Docker Support?
  44. 44. # setup your project $ docker run --rm -v $(pwd):/app robmorgan/ phinx init # create a migration $ docker run --rm -v $(pwd):/app robmorgan/ phinx create MyFirstMigration # migrate your db $ docker run --rm -v $(pwd):/app --link db:db robmorgan/phinx migrate -e development
  45. 45. Lightweight ORM
  46. 46. API Freeze towards 1.0
  47. 47. What about the future?
  48. 48. Multiple Database Support
  49. 49. Migration Generator
  50. 50. Data Transformation
  51. 51. Documentation
  52. 52. Please Read before opening an issue!
  53. 53. Contributing • Before you open an issue, search the existing ones! • Fixing the documentation is a great place to start • Read the CONTRIBUTING.md file on Github • At the end of the day, nobody bites and its only PHP!
  54. 54. Cheers! • Rob Morgan (@_rjm_) • https://phinx.org • https://robmorgan.id.au Rob Morgan @_rjm_ #phinx #php #phptour

×