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 everyda...
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.
Size: 3.05 MB
Language: en
Added: May 24, 2016
Slides: 67 pages
Slide Content
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.”
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: [email protected]
•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
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 Phinx\Migration\AbstractMigration
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 Phinx\Migration\AbstractMigration
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
$ 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