SlideShare a Scribd company logo
1 of 67
Download to read offline
Rob Morgan
@_rjm_
#phinx #php #phptour
What is a Database or
Schema Migration?
“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.”
source: https://en.wikipedia.org/wiki/Schema_migration
What is Phinx?
“Phinx is a tool that allows you to migrate
your database schema over time”
Rob Morgan
• Creator & Lead Developer of Phinx
• Writing PHP for almost 15 years
• Email: robbym@gmail.com
• https://robmorgan.id.au
@_rjm_
asd
Australia
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)
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
Supported Databases
Test Matrix
MySQL PostgreSQL SQLite SQL Server
PHP 5.4 ❌ ❌ ❌ ❌
PHP 5.5 ❌ ❌ ❌ ❌
PHP 5.6 ❌ ❌ ❌ ❌
PHP 7 ❌ ❌ ❌ ❌
HHVM ❌
Why did I write Phinx?
We started to look for
better solutions
Phing with DbDeploy
We developed on Mac &
Linux, but deployed on
Windows
Why Should I Use
Phinx?
Phinx is Fast
It requires PHP 5.4
Production Ready
How can I install Phinx?
• Pear
• Composer
• Build a Phar package (see Github)
How can I install Phinx?
• Pear
• Composer
• Build a Phar package (see Github)
It’s a command line
application (although it does
contain a web application)
$ vendor/bin/phinx
Creating a migration
$ vendor/bin/phinx create CreatePostsTable
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
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
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
Reversible Migrations
Only some methods
can be reversed!
createTable
renameTable
addColumn
renameColumn
addIndex
addForeignIndex
Seed Command
$ vendor/bin/phinx seed:create UserSeeder
$ vendor/bin/phinx seed:run -e development
Real World Use Case
Let’s pretend our Customer
wants us to build a new
web application
The Customer
• He wants a competitor to Wordpress
• Needs it tomorrow
• Willing to pay alot some money
Phinx can help!

(but not do everything)
But first we must
install it…
Installing via
Composer
# first require Phinx
$ php composer.phar require robmorgan/phinx
# then install it including the dependencies
$ php composer.phar install
Creating a Migration
What’s coming in
Phinx 0.6.0?
Docker Support?
# 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
Lightweight ORM
API Freeze towards
1.0
What about the future?
Multiple Database
Support
Migration Generator
Data Transformation
Documentation
Please Read before
opening an issue!
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!
Cheers!
• Rob Morgan (@_rjm_)
• https://phinx.org
• https://robmorgan.id.au
Rob Morgan
@_rjm_
#phinx #php #phptour

More Related Content

What's hot

'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 'MICROFRONTENDS WITH REACT' by Liliia Karpenko 'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
OdessaJS Conf
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
OdessaJS Conf
 

What's hot (20)

Indexing BackPAN
Indexing BackPANIndexing BackPAN
Indexing BackPAN
 
Rapid Web Development with Python for Absolute Beginners
Rapid Web Development with Python for Absolute BeginnersRapid Web Development with Python for Absolute Beginners
Rapid Web Development with Python for Absolute Beginners
 
Failing at Scale - PNWPHP 2016
Failing at Scale - PNWPHP 2016Failing at Scale - PNWPHP 2016
Failing at Scale - PNWPHP 2016
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 Workshop
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
Engage 2020: Hello are you listening, There is stream for everything
Engage 2020: Hello are you listening, There is stream for everythingEngage 2020: Hello are you listening, There is stream for everything
Engage 2020: Hello are you listening, There is stream for everything
 
10 less-known Laravel Packages: April 2016
10 less-known Laravel Packages: April 201610 less-known Laravel Packages: April 2016
10 less-known Laravel Packages: April 2016
 
Composer
ComposerComposer
Composer
 
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
 
Pharo JS
Pharo JSPharo JS
Pharo JS
 
10 less-known Laravel Packages: May 2016
10 less-known Laravel Packages: May 201610 less-known Laravel Packages: May 2016
10 less-known Laravel Packages: May 2016
 
.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
Orchard 2... and why you should care
Orchard 2... and why you should careOrchard 2... and why you should care
Orchard 2... and why you should care
 
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 'MICROFRONTENDS WITH REACT' by Liliia Karpenko 'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 
composer_talk_20160209
composer_talk_20160209composer_talk_20160209
composer_talk_20160209
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
 
C#: Past, Present and Future
C#: Past, Present and FutureC#: Past, Present and Future
C#: Past, Present and Future
 
.Net Core
.Net Core.Net Core
.Net Core
 
What's New in ASP.NET Core 2.0
What's New in ASP.NET Core 2.0What's New in ASP.NET Core 2.0
What's New in ASP.NET Core 2.0
 

Viewers also liked

PHP
PHPPHP

Viewers also liked (20)

Phinx talk
Phinx talkPhinx talk
Phinx talk
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
PHP
PHPPHP
PHP
 
Threads in PHP - Presentation
Threads in PHP - Presentation Threads in PHP - Presentation
Threads in PHP - Presentation
 
PHP in one presentation
PHP in one presentationPHP in one presentation
PHP in one presentation
 
Php
PhpPhp
Php
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
 
PHP presentation - Com 585
PHP presentation - Com 585PHP presentation - Com 585
PHP presentation - Com 585
 
Devise | Presentation for Alpharetta PHP / Laravel Group
Devise | Presentation for Alpharetta PHP / Laravel GroupDevise | Presentation for Alpharetta PHP / Laravel Group
Devise | Presentation for Alpharetta PHP / Laravel Group
 
PHP presentation
PHP presentationPHP presentation
PHP presentation
 
Internationalisation with PHP and Intl
Internationalisation with PHP and IntlInternationalisation with PHP and Intl
Internationalisation with PHP and Intl
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Php string function
Php string function Php string function
Php string function
 
PHP WEB 应用组织与结构
PHP WEB 应用组织与结构PHP WEB 应用组织与结构
PHP WEB 应用组织与结构
 
教學課程Pdf備份
教學課程Pdf備份教學課程Pdf備份
教學課程Pdf備份
 
Opensource 是人生的好朋友 2016-07-21
Opensource 是人生的好朋友 2016-07-21Opensource 是人生的好朋友 2016-07-21
Opensource 是人生的好朋友 2016-07-21
 
Grpc go-in-php
Grpc go-in-phpGrpc go-in-php
Grpc go-in-php
 
TrainingProgramAtMobileDevTW
TrainingProgramAtMobileDevTWTrainingProgramAtMobileDevTW
TrainingProgramAtMobileDevTW
 
從 Php unit 到 ci 持續整合
從 Php unit 到 ci 持續整合從 Php unit 到 ci 持續整合
從 Php unit 到 ci 持續整合
 

Similar to PHP Tour 2016 Phinx Presentation

Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
Bachkoutou Toutou
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
MongoDB
 
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
OdessaJS Conf
 
[ThoughtWorks] Perforce for Release Engineers
[ThoughtWorks] Perforce for Release Engineers[ThoughtWorks] Perforce for Release Engineers
[ThoughtWorks] Perforce for Release Engineers
Perforce
 
Dd13.2013.milano.open ntf
Dd13.2013.milano.open ntfDd13.2013.milano.open ntf
Dd13.2013.milano.open ntf
Ulrich Krause
 

Similar to PHP Tour 2016 Phinx Presentation (20)

TYPO3 Performance (T3DD18)
TYPO3 Performance (T3DD18)TYPO3 Performance (T3DD18)
TYPO3 Performance (T3DD18)
 
2018 - CertiFUNcation - Marcus Schwemer: TYPO3 Performance
2018 - CertiFUNcation - Marcus Schwemer: TYPO3 Performance2018 - CertiFUNcation - Marcus Schwemer: TYPO3 Performance
2018 - CertiFUNcation - Marcus Schwemer: TYPO3 Performance
 
Schema migration (DB migration) with Phinx
Schema migration (DB migration) with PhinxSchema migration (DB migration) with Phinx
Schema migration (DB migration) with Phinx
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
PHP - Programming language war, does it matter
PHP - Programming language war, does it matterPHP - Programming language war, does it matter
PHP - Programming language war, does it matter
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
Intro to CakePHP
Intro to CakePHPIntro to CakePHP
Intro to CakePHP
 
Create a PHP Library the right way
Create a PHP Library the right wayCreate a PHP Library the right way
Create a PHP Library the right way
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
 
From monolith web app to micro-frontends
From monolith web app to micro-frontendsFrom monolith web app to micro-frontends
From monolith web app to micro-frontends
 
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
Rustam Aliyev and Ivan Martynov - From monolith web app to micro-frontends – ...
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...
 
Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovsky
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
[ThoughtWorks] Perforce for Release Engineers
[ThoughtWorks] Perforce for Release Engineers[ThoughtWorks] Perforce for Release Engineers
[ThoughtWorks] Perforce for Release Engineers
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDB
 
Dd13.2013.milano.open ntf
Dd13.2013.milano.open ntfDd13.2013.milano.open ntf
Dd13.2013.milano.open ntf
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

PHP Tour 2016 Phinx Presentation