macwinnie / wp-db-phinx-helper
Helper for WordPress plugins to be able to use [Phinx](https://phinx.org/) for DB migrations
Requires
- php: >=8.1
- composer/composer: ^2.7
- ramsey/uuid: ^4.9
- robmorgan/phinx: ^0.16.1
- symfony/console: ^7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.91
- mikey179/vfsstream: ^1.6
- mockery/mockery: ^1.6
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- squizlabs/php_codesniffer: ^4.0
- szepeviktor/phpstan-wordpress: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Shared CI
Start with the guided shared setup for the Composer/CI distinction, permissions, pilot rollout and troubleshooting.
The pipeline includes helper-executables' /pipeline/php-library.yml pinned by
group variable WP_PHP_CI_REF (reviewed full SHA). Push the producer first and allow
consumer job-token repository reads on producer project 163. Move this upstream into
wordpress/php-libraries before relying on that group's variables/allowlist; no remote
transfer is performed by these changes. Static checks, tests, 100% coverage and safe
archives gate reviewed release MRs/protected-tag Composer publication. Runtime PHP
is >=8.2 (Symfony Console 7); PHPUnit 12 tests run on PHP 8.3/8.4.
Consuming plugins/themes may declare extra.wp-distribution; this repository remains
a Composer library. See the
shared contract and rollout guide.
This helper allows you to use Phinx for defining Database migrations. The placed config file phinx.php will use the Wordpress Configured Database.
You can install this helper library by using composer:
composer require macwinnie/wp-db-phinx-helper
It is recommended to expand the Macwinnie\WpDbPhinxHelper\DBUtilisator class by your Plugin-Class:
class MyPlugin extends DBUtilisator { public static function plugin_activation_method () { parent::plugin_activation_method(); # ensures Phinx config placed and migrations run on install / activation / update } public static function plugin_uninstall_method () { parent::plugin_uninstall_method(); # ensures Phinx migrations rolled back in Database on Plugin uninstall } }
The static function static::basePath() can be used to get your Plugin absolute path on the webserver – and will also check if the Phinx config file is present in the base directory of your Plugin.
Folder structure
Your Database migrations shall reside within db/migrations, Database seeds within db/seeds as childpath of your WordPress plugin.
Phinx takes over creation of paths as you follow the official documentation. The phinx executable can be found in vendor/bin/phinx as you install this helper library via composer.