phinx cloudconf 2016 presentation

Post on 11-Apr-2017

413 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Rob Morgan @_rjm_ #phinx #php #cloudconf2016

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

• http://robmorgan.id.au

@_rjm_

asd

Australia

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)

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

Compatibility MatrixMySQL 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 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

Reversible Migrations

Only some methods can be reversed!

createTable

renameTable

addColumn

renameColumn

addIndex

addForeignIndex

Seed Command

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?

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!

Rob Morgan @_rjm_ #phinx #php #cloudconf2016

ONE MILLION

DOWNLOADS

Cheers!• Rob Morgan (@_rjm_)

• https://phinx.org

• http://robmorgan.id.au

Rob Morgan @_rjm_ #phinx #php #cloudconf2016

top related