Tiger_Db_Migrator

@api

Tiger_Db_Migrator — a tiny, dependency-free schema migration runner.

WHY hand-rolled (not Doctrine/Phinx/etc.): ZF1 has no migration tool, and pulling a heavyweight one in would drag a large dependency into every Tiger app. Migrations are simple enough — ordered, idempotent, tracked — to own directly, and owning them keeps the "zero unnecessary plumbing" promise.

HOW IT WORKS:

  • A migration is a file named NNNN_snake_name.php returning ['up' => [...sql], 'down' => [...sql]]. NNNN is the version (sort key).
  • Migrations are discovered across MULTIPLE paths — core ships them in tiger-core/migrations; an app in application/migrations; a module in modules//migrations — and merged into one ascending-by-version sequence.
  • Applied versions are recorded in tiger_migration, so migrate() only ever runs what's pending, and is safe to run repeatedly.

CAVEAT (MySQL/MariaDB): DDL statements auto-commit — a CREATE/ALTER can't be rolled back inside a transaction. So keep each migration to ONE logical change; if a migration half-applies, fix forward. We record a migration as applied only after ALL its statements succeed, so a failure leaves it un-recorded and it will be retried on the next run.

Methods

__construct()

__construct(Zend_Db_Adapter_Abstract $db, array $paths)

Construct the migrator over a DB adapter and a set of migration directories.

  • $db Zend_Db_Adapter_Abstract
  • $paths array — migration directories (existing ones; missing are ignored)

migrate()

migrate($log = null)

Apply all pending migrations in version order.

  • $log callable|null — optional fn(string $message) for progress output

Returns array — [version => name] of migrations applied this run