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

PDF
Phinx CloudConf 2016 Presentation
PPTX
Web development with Python
PDF
Automated deployments using envoy by John Blackmore
PPTX
Phalcon - Giant Killer
PDF
perlcc made easy or, how to make a CGI Moose app
PDF
WordPress 4.4 and Beyond
PDF
Phalcon Framework: San Antonio Web Developers Group
PDF
Pharo Arm Status
Phinx CloudConf 2016 Presentation
Web development with Python
Automated deployments using envoy by John Blackmore
Phalcon - Giant Killer
perlcc made easy or, how to make a CGI Moose app
WordPress 4.4 and Beyond
Phalcon Framework: San Antonio Web Developers Group
Pharo Arm Status

What's hot (20)

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

Viewers also liked (20)

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

Similar to PHP Tour 2016 Phinx Presentation (20)

PDF
Schema migration (DB migration) with Phinx
PDF
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
PDF
Migrate for Site Builders from MidCamp 2016
PPT
A pain free migraine
PPTX
Using Doctrine Migrations to Synchronize Databases
KEY
symfony Live 2010 - Using Doctrine Migrations
 
PDF
Are we there Yet?? (The long journey of Migrating from close source to opens...
PDF
Learning Mysql Seyed Mm Saied Tahaghoghi Hugh Williams
PDF
Migración desde BBDD propietarias a MariaDB
PDF
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
PDF
php_mysql_tutorial
PDF
php_mysql_tutorial
PDF
Migration Concepts For Enterprise PHP Applications
PPTX
Migrate in Drupal 8
ODP
MySQL And Search At Craigslist
PDF
Migrating data to Drupal 8
PDF
Replacing Oracle Database at an International Bank
PPT
Migrating from PHP 4 to PHP 5
PDF
🐬 The future of MySQL is Postgres 🐘
PDF
Php mysql-tutorial-en
Schema migration (DB migration) with Phinx
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Migrate for Site Builders from MidCamp 2016
A pain free migraine
Using Doctrine Migrations to Synchronize Databases
symfony Live 2010 - Using Doctrine Migrations
 
Are we there Yet?? (The long journey of Migrating from close source to opens...
Learning Mysql Seyed Mm Saied Tahaghoghi Hugh Williams
Migración desde BBDD propietarias a MariaDB
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
php_mysql_tutorial
php_mysql_tutorial
Migration Concepts For Enterprise PHP Applications
Migrate in Drupal 8
MySQL And Search At Craigslist
Migrating data to Drupal 8
Replacing Oracle Database at an International Bank
Migrating from PHP 4 to PHP 5
🐬 The future of MySQL is Postgres 🐘
Php mysql-tutorial-en

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Cloud computing and distributed systems.
PPTX
Spectroscopy.pptx food analysis technology
PDF
KodekX | Application Modernization Development
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Unlocking AI with Model Context Protocol (MCP)
Cloud computing and distributed systems.
Spectroscopy.pptx food analysis technology
KodekX | Application Modernization Development
Mobile App Security Testing_ A Comprehensive Guide.pdf

PHP Tour 2016 Phinx Presentation