Phinx CloudConf 2016 Presentation
-
Upload
rob-morgan -
Category
Software
-
view
413 -
download
0
Transcript of Phinx CloudConf 2016 Presentation
![Page 1: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/1.jpg)
Rob Morgan @_rjm_ #phinx #php #cloudconf2016
![Page 2: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/2.jpg)
What is a Database or Schema Migration?
![Page 3: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/3.jpg)
“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.”
![Page 4: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/4.jpg)
source: https://en.wikipedia.org/wiki/Schema_migration
![Page 5: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/5.jpg)
![Page 6: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/6.jpg)
What is Phinx?
“Phinx is a tool that allows you to migrate your database schema over time”
![Page 7: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/7.jpg)
Rob Morgan
• Creator & Lead Developer of Phinx
• Writing PHP for almost 15 years
• Email: [email protected]
• http://robmorgan.id.au
@_rjm_
![Page 8: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/8.jpg)
asd
Australia
![Page 9: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/9.jpg)
![Page 10: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/10.jpg)
Brief History• Open Sourced in 2012 under the MIT License
• 37 Releases to Date
• 900k Downloads and 115+ Contributors
• Used in CakePHP 3.0.0
• Built on top of Symfony Components (and only 3)
![Page 11: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/11.jpg)
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
![Page 12: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/12.jpg)
Supported Databases
![Page 13: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/13.jpg)
Compatibility MatrixMySQL PostgreSQL SQLite SQL Server
PHP 5.4 ❌ ❌ ❌ ❌
PHP 5.5 ❌ ❌ ❌ ❌
PHP 5.6 ❌ ❌ ❌ ❌
PHP 7 ❌ ❌ ❌ ❌
HHVM ❌
![Page 14: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/14.jpg)
Why did I write Phinx?
![Page 15: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/15.jpg)
![Page 16: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/16.jpg)
We started to look for better solutions
![Page 17: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/17.jpg)
Phing with DbDeploy
![Page 18: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/18.jpg)
We developed on Mac & Linux, but deployed on
Windows
![Page 19: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/19.jpg)
![Page 20: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/20.jpg)
Why Should I Use Phinx?
![Page 21: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/21.jpg)
Phinx is Fast
![Page 22: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/22.jpg)
It requires PHP 5.4
![Page 23: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/23.jpg)
Production Ready
![Page 24: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/24.jpg)
How can I install Phinx?
• Pear
• Composer
• Build a Phar package (see Github)
![Page 25: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/25.jpg)
How can I install Phinx?
• Pear
• Composer
• Build a Phar package (see Github)
![Page 26: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/26.jpg)
It’s a command line application (although it does contain a web application)
![Page 27: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/27.jpg)
$ vendor/bin/phinx
![Page 28: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/28.jpg)
![Page 29: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/29.jpg)
Creating a migration
![Page 30: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/30.jpg)
$ vendor/bin/phinx create CreatePostsTable
![Page 31: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/31.jpg)
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 Phinx\Migration\AbstractMigration using default template created ./db/migrations/20160309162303_create_posts_table.php
![Page 32: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/32.jpg)
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 Phinx\Migration\AbstractMigration using default template created ./db/migrations/20160309162303_create_posts_table.php
![Page 33: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/33.jpg)
Reversible Migrations
![Page 34: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/34.jpg)
![Page 35: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/35.jpg)
![Page 36: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/36.jpg)
Only some methods can be reversed!
![Page 37: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/37.jpg)
createTable
renameTable
addColumn
renameColumn
addIndex
addForeignIndex
![Page 38: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/38.jpg)
Seed Command
![Page 39: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/39.jpg)
![Page 40: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/40.jpg)
Real World Use Case
![Page 41: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/41.jpg)
Let’s pretend our Customer wants us to build a new
web application
![Page 42: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/42.jpg)
The Customer
• He wants a competitor to Wordpress
• Needs it tomorrow
• Willing to pay alot some money
![Page 43: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/43.jpg)
![Page 44: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/44.jpg)
Phinx can help!(but not do everything)
![Page 45: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/45.jpg)
But first we must install it…
![Page 46: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/46.jpg)
Installing via Composer
![Page 47: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/47.jpg)
# first require Phinx $ php composer.phar require robmorgan/phinx
# then install it including the dependencies $ php composer.phar install
![Page 48: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/48.jpg)
![Page 49: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/49.jpg)
Creating a Migration
![Page 50: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/50.jpg)
![Page 51: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/51.jpg)
![Page 52: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/52.jpg)
What’s coming in Phinx 0.6.0?
![Page 53: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/53.jpg)
Lightweight ORM
![Page 54: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/54.jpg)
API Freeze towards 1.0
![Page 55: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/55.jpg)
What about the future?
![Page 56: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/56.jpg)
Multiple Database Support
![Page 57: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/57.jpg)
Migration Generator
![Page 58: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/58.jpg)
Data Transformation
![Page 59: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/59.jpg)
Documentation
![Page 60: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/60.jpg)
![Page 61: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/61.jpg)
Please Read before opening an issue!
![Page 62: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/62.jpg)
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!
![Page 63: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/63.jpg)
Rob Morgan @_rjm_ #phinx #php #cloudconf2016
ONE MILLION
DOWNLOADS
![Page 64: Phinx CloudConf 2016 Presentation](https://reader035.fdocuments.ec/reader035/viewer/2022062412/58ebbd571a28ab0e2b8b4657/html5/thumbnails/64.jpg)
Cheers!• Rob Morgan (@_rjm_)
• https://phinx.org
• http://robmorgan.id.au
Rob Morgan @_rjm_ #phinx #php #cloudconf2016