Database Migrations in PHP (Posobota #66)

Database Migrations in PHP (Posobota #66)

1633975316e340c5f24414567a3f3679?s=128

Vladimír Kriška

October 25, 2014
Tweet

Transcript

  1. Database Migrations in PHP Posobota #66 Vladimír Kriška @ujovlado

  2. My experience • Paradox: first company I worked with was

    the closest to migrations • Then it went only worse • no migrations • single file migrations • Yii framework database migrations
  3. Pros • Exact version of schema with creation and application

    date • CLI interface (automation) • Easy rollback, going through history
  4. Cons • Need to regenerate/change model

  5. Other options/ideas • Generate migrations directly from model (no SQL

    writing) • With each change create DB dump with file per table, than version in Git
  6. Other tools • Phinx • Sqitch (Perl) • Doctrine, Phalcon,

    Propel, CakePHP • and many others …
  7. Migrations in Yii • Two main commands • yiic migrate

    up • yiic migrate down • And also: history, new, to, mark
  8. Example • let’s do some shit …

  9. Tips/tricks • DB schema has to be versioned - no

    matter how • If you don’t know how to do it, choose solution from some framework • Don’t write own tool for migrations • Start with migrations ASAP
  10. • Always write down migrations • Try to avoid shortcut

    methods (they disallow c&p from migration) • Don’t mix schema and data migrations • Write short migrations • Don’t change applied migrations
  11. THE END Thanks!