cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.46k stars 889 forks source link

Could not get "migration_base_class" to work #2172

Closed CoreVisional closed 1 year ago

CoreVisional commented 1 year ago

Hi, I have been trying to get new migrations to extend my own class instead of "AbstractMigration", and according to 0.13v documentation, it states that I can do so by specifying it like migration_base_class: BaseMigration. I specified it under the "development" environment in my phinx.php and configured my autoloading yet no matter what, it still extends "AbstractMigration".

phinx.php:

'development' => [
    'adapter' => 'mysql',
    'host' => 'localhost',
    'name' => 'TEST',
    'user' => '',
    'pass' => '',
    'port' => '3306',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'migration_base_class' => 'db/common/BaseMigration',
],

composer.json:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Db\\Common\\": "db/common/"
    },

My "BaseMigration.php" is located in db/common/BaseMigration.php where "db" is sitting at my root directory. Now, when I run a verbose migration command: php vendor/bin/phinx create Test -vvv, I can still see that it is using "AbstractMigration".

So, is this migration_base_class outdated or something?

CoreVisional commented 1 year ago

The issue is solved now. Apparently, the migration_base_class should be placed outside of environments, in its own section that is, and not inside the environment, like:

'paths' => [
    'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations',
    'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds'
],
'migration_base_class' => 'Db\Common\BaseMigration',