SlideShare a Scribd company logo
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
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
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?
PHP Tour 2016 Phinx Presentation
We started to look for
better solutions
Phing with DbDeploy
We developed on Mac &
Linux, but deployed on
Windows
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
Creating a Migration
PHP Tour 2016 Phinx Presentation
PHP Tour 2016 Phinx Presentation
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
PHP Tour 2016 Phinx Presentation
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 (20)

PDF
Indexing BackPAN
brian d foy
 
PDF
Rapid Web Development with Python for Absolute Beginners
Fatih Karatana
 
PPTX
Failing at Scale - PNWPHP 2016
Chris Tankersley
 
PPTX
Docker for Developers - PNWPHP 2016 Workshop
Chris Tankersley
 
PDF
Composer - The missing package manager for PHP
Tareq Hasan
 
PDF
Engage 2020: Hello are you listening, There is stream for everything
Frank van der Linden
 
PDF
10 less-known Laravel Packages: April 2016
Povilas Korop
 
PDF
Composer
Le Thanh Sang
 
PDF
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
Ortus Solutions, Corp
 
PDF
Pharo JS
Pharo
 
PDF
10 less-known Laravel Packages: May 2016
Povilas Korop
 
PDF
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt
 
PDF
Reverse Installing CPAN
brian d foy
 
PPTX
Orchard 2... and why you should care
Bertrand Le Roy
 
PPTX
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
OdessaJS Conf
 
PDF
composer_talk_20160209
Bradley Wogsland
 
PPTX
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
OdessaJS Conf
 
PPTX
C#: Past, Present and Future
Rodolfo Finochietti
 
PPTX
.Net Core
Bertrand Le Roy
 
PPTX
What's New in ASP.NET Core 2.0
Jon Galloway
 
Indexing BackPAN
brian d foy
 
Rapid Web Development with Python for Absolute Beginners
Fatih Karatana
 
Failing at Scale - PNWPHP 2016
Chris Tankersley
 
Docker for Developers - PNWPHP 2016 Workshop
Chris Tankersley
 
Composer - The missing package manager for PHP
Tareq Hasan
 
Engage 2020: Hello are you listening, There is stream for everything
Frank van der Linden
 
10 less-known Laravel Packages: April 2016
Povilas Korop
 
Composer
Le Thanh Sang
 
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
Ortus Solutions, Corp
 
Pharo JS
Pharo
 
10 less-known Laravel Packages: May 2016
Povilas Korop
 
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt
 
Reverse Installing CPAN
brian d foy
 
Orchard 2... and why you should care
Bertrand Le Roy
 
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
OdessaJS Conf
 
composer_talk_20160209
Bradley Wogsland
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
OdessaJS Conf
 
C#: Past, Present and Future
Rodolfo Finochietti
 
.Net Core
Bertrand Le Roy
 
What's New in ASP.NET Core 2.0
Jon Galloway
 

Viewers also liked (20)

PDF
Phinx talk
Michael Peacock
 
PPT
Core Php Component Presentation
John Coonen
 
PPTX
PHP
Jawhar Ali
 
PDF
Threads in PHP - Presentation
appserver.io
 
PPTX
PHP in one presentation
Milad Rahimi
 
PPTX
Php oop presentation
Mutinda Boniface
 
PPTX
PHP presentation - Com 585
jstout007
 
PDF
Devise | Presentation for Alpharetta PHP / Laravel Group
Gary Williams
 
PPTX
PHP presentation
Helen Pitlick
 
ODP
Internationalisation with PHP and Intl
Daniel_Rhodes
 
PDF
Lean Php Presentation
Alan Pinstein
 
ODP
Introduction of Html/css/js
Knoldus Inc.
 
PPTX
Php string function
Ravi Bhadauria
 
PPT
PHP WEB 应用组织与结构
HonestQiao
 
PDF
教學課程Pdf備份
楷霖 顏
 
PDF
Opensource 是人生的好朋友 2016-07-21
CQD
 
ODP
Grpc go-in-php
光照 刘
 
PDF
TrainingProgramAtMobileDevTW
Ryan Chung
 
PPT
從 Php unit 到 ci 持續整合
Joel Zhong
 
Phinx talk
Michael Peacock
 
Core Php Component Presentation
John Coonen
 
Threads in PHP - Presentation
appserver.io
 
PHP in one presentation
Milad Rahimi
 
Php oop presentation
Mutinda Boniface
 
PHP presentation - Com 585
jstout007
 
Devise | Presentation for Alpharetta PHP / Laravel Group
Gary Williams
 
PHP presentation
Helen Pitlick
 
Internationalisation with PHP and Intl
Daniel_Rhodes
 
Lean Php Presentation
Alan Pinstein
 
Introduction of Html/css/js
Knoldus Inc.
 
Php string function
Ravi Bhadauria
 
PHP WEB 应用组织与结构
HonestQiao
 
教學課程Pdf備份
楷霖 顏
 
Opensource 是人生的好朋友 2016-07-21
CQD
 
Grpc go-in-php
光照 刘
 
TrainingProgramAtMobileDevTW
Ryan Chung
 
從 Php unit 到 ci 持續整合
Joel Zhong
 
Ad

Similar to PHP Tour 2016 Phinx Presentation (20)

PDF
Schema migration (DB migration) with Phinx
Hadi Ariawan
 
PDF
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Alan Pinstein
 
PDF
Migrate for Site Builders from MidCamp 2016
Suzanne Dergacheva
 
PPT
A pain free migraine
Dennis Solis
 
PPTX
Using Doctrine Migrations to Synchronize Databases
Bryce Embry
 
KEY
symfony Live 2010 - Using Doctrine Migrations
D
 
PDF
Are we there Yet?? (The long journey of Migrating from close source to opens...
Marco Tusa
 
PDF
Learning Mysql Seyed Mm Saied Tahaghoghi Hugh Williams
margasmst
 
PDF
Migración desde BBDD propietarias a MariaDB
MariaDB plc
 
PDF
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Acquia
 
PDF
php_mysql_tutorial
tutorialsruby
 
PDF
php_mysql_tutorial
tutorialsruby
 
PDF
Migration Concepts For Enterprise PHP Applications
Mayflower GmbH
 
PPTX
Migrate in Drupal 8
Alexei Gorobets
 
ODP
MySQL And Search At Craigslist
Jeremy Zawodny
 
PDF
Migrating data to Drupal 8
F.L. Jonathan Araña Cruz
 
PDF
Replacing Oracle Database at an International Bank
MariaDB plc
 
PPT
Migrating from PHP 4 to PHP 5
John Coggeshall
 
PDF
🐬 The future of MySQL is Postgres 🐘
RTylerCroy
 
PDF
Php mysql-tutorial-en
soft deal solution
 
Schema migration (DB migration) with Phinx
Hadi Ariawan
 
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Alan Pinstein
 
Migrate for Site Builders from MidCamp 2016
Suzanne Dergacheva
 
A pain free migraine
Dennis Solis
 
Using Doctrine Migrations to Synchronize Databases
Bryce Embry
 
symfony Live 2010 - Using Doctrine Migrations
D
 
Are we there Yet?? (The long journey of Migrating from close source to opens...
Marco Tusa
 
Learning Mysql Seyed Mm Saied Tahaghoghi Hugh Williams
margasmst
 
Migración desde BBDD propietarias a MariaDB
MariaDB plc
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Acquia
 
php_mysql_tutorial
tutorialsruby
 
php_mysql_tutorial
tutorialsruby
 
Migration Concepts For Enterprise PHP Applications
Mayflower GmbH
 
Migrate in Drupal 8
Alexei Gorobets
 
MySQL And Search At Craigslist
Jeremy Zawodny
 
Migrating data to Drupal 8
F.L. Jonathan Araña Cruz
 
Replacing Oracle Database at an International Bank
MariaDB plc
 
Migrating from PHP 4 to PHP 5
John Coggeshall
 
🐬 The future of MySQL is Postgres 🐘
RTylerCroy
 
Php mysql-tutorial-en
soft deal solution
 
Ad

Recently uploaded (20)

PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
July Patch Tuesday
Ivanti
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 

PHP Tour 2016 Phinx Presentation