phinx cloudconf 2016 presentation

64
Rob Morgan @_rjm_ #phinx #php #cloudconf2016

Upload: rob-morgan

Post on 11-Apr-2017

413 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Phinx CloudConf 2016 Presentation

Rob Morgan @_rjm_ #phinx #php #cloudconf2016

Page 2: Phinx CloudConf 2016 Presentation

What is a Database or Schema Migration?

Page 3: Phinx CloudConf 2016 Presentation

“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.”

Page 4: Phinx CloudConf 2016 Presentation

source: https://en.wikipedia.org/wiki/Schema_migration

Page 5: Phinx CloudConf 2016 Presentation
Page 6: Phinx CloudConf 2016 Presentation

What is Phinx?

“Phinx is a tool that allows you to migrate your database schema over time”

Page 7: Phinx CloudConf 2016 Presentation

Rob Morgan

• Creator & Lead Developer of Phinx

• Writing PHP for almost 15 years

• Email: [email protected]

• http://robmorgan.id.au

@_rjm_

Page 8: Phinx CloudConf 2016 Presentation

asd

Australia

Page 9: Phinx CloudConf 2016 Presentation
Page 10: Phinx CloudConf 2016 Presentation

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)

Page 11: Phinx CloudConf 2016 Presentation

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

Page 12: Phinx CloudConf 2016 Presentation

Supported Databases

Page 13: Phinx CloudConf 2016 Presentation

Compatibility MatrixMySQL PostgreSQL SQLite SQL Server

PHP 5.4 ❌ ❌ ❌ ❌

PHP 5.5 ❌ ❌ ❌ ❌

PHP 5.6 ❌ ❌ ❌ ❌

PHP 7 ❌ ❌ ❌ ❌

HHVM ❌

Page 14: Phinx CloudConf 2016 Presentation

Why did I write Phinx?

Page 15: Phinx CloudConf 2016 Presentation
Page 16: Phinx CloudConf 2016 Presentation

We started to look for better solutions

Page 17: Phinx CloudConf 2016 Presentation

Phing with DbDeploy

Page 18: Phinx CloudConf 2016 Presentation

We developed on Mac & Linux, but deployed on

Windows

Page 19: Phinx CloudConf 2016 Presentation
Page 20: Phinx CloudConf 2016 Presentation

Why Should I Use Phinx?

Page 21: Phinx CloudConf 2016 Presentation

Phinx is Fast

Page 22: Phinx CloudConf 2016 Presentation

It requires PHP 5.4

Page 23: Phinx CloudConf 2016 Presentation

Production Ready

Page 24: Phinx CloudConf 2016 Presentation

How can I install Phinx?

• Pear

• Composer

• Build a Phar package (see Github)

Page 25: Phinx CloudConf 2016 Presentation

How can I install Phinx?

• Pear

• Composer

• Build a Phar package (see Github)

Page 26: Phinx CloudConf 2016 Presentation

It’s a command line application (although it does contain a web application)

Page 27: Phinx CloudConf 2016 Presentation

$ vendor/bin/phinx

Page 28: Phinx CloudConf 2016 Presentation
Page 29: Phinx CloudConf 2016 Presentation

Creating a migration

Page 30: Phinx CloudConf 2016 Presentation

$ vendor/bin/phinx create CreatePostsTable

Page 31: Phinx CloudConf 2016 Presentation

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

Page 32: Phinx CloudConf 2016 Presentation

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

Page 33: Phinx CloudConf 2016 Presentation

Reversible Migrations

Page 34: Phinx CloudConf 2016 Presentation
Page 35: Phinx CloudConf 2016 Presentation
Page 36: Phinx CloudConf 2016 Presentation

Only some methods can be reversed!

Page 37: Phinx CloudConf 2016 Presentation

createTable

renameTable

addColumn

renameColumn

addIndex

addForeignIndex

Page 38: Phinx CloudConf 2016 Presentation

Seed Command

Page 39: Phinx CloudConf 2016 Presentation
Page 40: Phinx CloudConf 2016 Presentation

Real World Use Case

Page 41: Phinx CloudConf 2016 Presentation

Let’s pretend our Customer wants us to build a new

web application

Page 42: Phinx CloudConf 2016 Presentation

The Customer

• He wants a competitor to Wordpress

• Needs it tomorrow

• Willing to pay alot some money

Page 43: Phinx CloudConf 2016 Presentation
Page 44: Phinx CloudConf 2016 Presentation

Phinx can help!(but not do everything)

Page 45: Phinx CloudConf 2016 Presentation

But first we must install it…

Page 46: Phinx CloudConf 2016 Presentation

Installing via Composer

Page 47: Phinx CloudConf 2016 Presentation

# first require Phinx $ php composer.phar require robmorgan/phinx

# then install it including the dependencies $ php composer.phar install

Page 48: Phinx CloudConf 2016 Presentation
Page 49: Phinx CloudConf 2016 Presentation

Creating a Migration

Page 50: Phinx CloudConf 2016 Presentation
Page 51: Phinx CloudConf 2016 Presentation
Page 52: Phinx CloudConf 2016 Presentation

What’s coming in Phinx 0.6.0?

Page 53: Phinx CloudConf 2016 Presentation

Lightweight ORM

Page 54: Phinx CloudConf 2016 Presentation

API Freeze towards 1.0

Page 55: Phinx CloudConf 2016 Presentation

What about the future?

Page 56: Phinx CloudConf 2016 Presentation

Multiple Database Support

Page 57: Phinx CloudConf 2016 Presentation

Migration Generator

Page 58: Phinx CloudConf 2016 Presentation

Data Transformation

Page 59: Phinx CloudConf 2016 Presentation

Documentation

Page 60: Phinx CloudConf 2016 Presentation
Page 61: Phinx CloudConf 2016 Presentation

Please Read before opening an issue!

Page 62: Phinx CloudConf 2016 Presentation

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!

Page 63: Phinx CloudConf 2016 Presentation

Rob Morgan @_rjm_ #phinx #php #cloudconf2016

ONE MILLION

DOWNLOADS

Page 64: Phinx CloudConf 2016 Presentation

Cheers!• Rob Morgan (@_rjm_)

• https://phinx.org

• http://robmorgan.id.au

Rob Morgan @_rjm_ #phinx #php #cloudconf2016