$ show cakephp/phinx
Phinx is a PHP library and CLI tool for managing database migrations and seeding. It supports MySQL, PostgreSQL, SQLite, and SQL Server, providing a fluent API to define schema changes (tables, columns, indexes, foreign keys) and execute them across multiple environments. The architecture is built around database adapters implementing a common interface, a migration manager for orchestration, and a flexible configuration system (YAML/JSON/PHP). Key design patterns include Action objects for atomic database changes, a Plan/Intent system for conflict resolution, and decorator wrappers for cross-cutting concerns like table prefix/suffix and performance timing. The tool integrates with Symfony Console for CLI commands and can be embedded in web applications via a TextWrapper. The codebase demonstrates strong software engineering with extensive test suites, feature flags for backward compatibility, and support for reversible migrations via the `change()` method. While some adapter code is duplicated and Docker test images are outdated, the overall structure is clean and modular, making it a reliable choice for PHP database schema management.
The LLM identified 3 files worth highlighting for reuse:
Encapsulates the three phases of an ALTER TABLE operation (pre-steps, ALTER statements, post-steps). Used by all database adapters to standardize SQL output. It is a simple, isolated data container that can be extracted to any SQL generation system requiring ordered execution with side effects.
A registry for database adapters and wrappers, allowing dynamic instantiation by adapter name. Demonstrates the Factory pattern with support for decorating adapters via registered wrappers. Self-contained and independent of Phinx internals, it can be reused in any PHP project that needs to select and configure database connections by type.
One of several Action value objects (AddColumn, DropIndex, RenameTable, etc.) that represent atomic database modifications. Each Action is immutable, self-describing, and independent of execution logic. This pattern allows migrations to record changes and replay them in any context, making these classes extractable for other database tooling or event-sourcing systems.