Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Database Migrations in PHP (Posobota #66)

Database Migrations in PHP (Posobota #66)

Vladimír Kriška

October 25, 2014
Tweet

More Decks by Vladimír Kriška

Other Decks in Programming

Transcript

  1. 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
  2. Pros • Exact version of schema with creation and application

    date • CLI interface (automation) • Easy rollback, going through history
  3. 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
  4. Other tools • Phinx • Sqitch (Perl) • Doctrine, Phalcon,

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

    up • yiic migrate down • And also: history, new, to, mark
  6. 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
  7. • 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