diff --git a/src/Db/Adapter/MysqlAdapter.php b/src/Db/Adapter/MysqlAdapter.php index 6f69b365..b057b635 100644 --- a/src/Db/Adapter/MysqlAdapter.php +++ b/src/Db/Adapter/MysqlAdapter.php @@ -16,7 +16,6 @@ use Migrations\Db\Table\ForeignKey; use Migrations\Db\Table\Index; use Migrations\Db\Table\Table; -use Phinx\Config\FeatureFlags; /** * Phinx MySQL Adapter. @@ -232,12 +231,13 @@ public function createTable(Table $table, array $columns = [], array $indexes = } if (isset($options['id']) && is_string($options['id'])) { + $useUnsigned = (bool)Configure::read('Migrations.unsigned_primary_keys'); // Handle id => "field_name" to support AUTO_INCREMENT $column = new Column(); $column->setName($options['id']) ->setType('integer') ->setOptions([ - 'signed' => $options['signed'] ?? !FeatureFlags::$unsignedPrimaryKeys, + 'signed' => $options['signed'] ?? !$useUnsigned, 'identity' => true, ]); diff --git a/src/Db/Table/Column.php b/src/Db/Table/Column.php index a09790b7..d740e0d0 100644 --- a/src/Db/Table/Column.php +++ b/src/Db/Table/Column.php @@ -8,8 +8,8 @@ namespace Migrations\Db\Table; +use Cake\Core\Configure; use Migrations\Db\Literal; -use Phinx\Config\FeatureFlags; use Phinx\Db\Adapter\AdapterInterface; use Phinx\Db\Adapter\PostgresAdapter; use RuntimeException; @@ -166,7 +166,7 @@ class Column */ public function __construct() { - $this->null = FeatureFlags::$columnNullDefault; + $this->null = (bool)Configure::read('Migrations.column_null_default'); } /** diff --git a/src/Migration/BuiltinBackend.php b/src/Migration/BuiltinBackend.php index 470621bc..ff6d798c 100644 --- a/src/Migration/BuiltinBackend.php +++ b/src/Migration/BuiltinBackend.php @@ -19,6 +19,7 @@ use Cake\Console\TestSuite\StubConsoleOutput; use DateTime; use InvalidArgumentException; +use Migrations\Config\ConfigInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; @@ -218,7 +219,9 @@ public function markMigrated(int|string|null $version = null, array $options = [ */ public function seed(array $options = []): bool { + $options['source'] ??= ConfigInterface::DEFAULT_SEED_FOLDER; $seed = $options['seed'] ?? null; + $manager = $this->getManager($options); $manager->seed($seed); @@ -237,7 +240,7 @@ public function getManager(array $options): Manager $factory = new ManagerFactory([ 'plugin' => $options['plugin'] ?? null, - 'source' => $options['source'] ?? null, + 'source' => $options['source'] ?? ConfigInterface::DEFAULT_MIGRATION_FOLDER, 'connection' => $options['connection'] ?? 'default', ]); $io = new ConsoleIo( diff --git a/src/Migration/ManagerFactory.php b/src/Migration/ManagerFactory.php index 0d996e9b..d7bca990 100644 --- a/src/Migration/ManagerFactory.php +++ b/src/Migration/ManagerFactory.php @@ -14,6 +14,7 @@ namespace Migrations\Migration; use Cake\Console\ConsoleIo; +use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Datasource\ConnectionManager; use Cake\Utility\Inflector; @@ -120,6 +121,10 @@ public function createConfig(): ConfigInterface 'environment' => $adapterConfig, 'plugin' => $plugin, 'source' => (string)$this->getOption('source'), + 'feature_flags' => [ + 'unsigned_primary_keys' => Configure::read('Migrations.unsigned_primary_keys'), + 'column_null_default' => Configure::read('Migrations.column_null_default'), + ], // TODO do we want to support the DI container in migrations? ]; diff --git a/src/View/Helper/MigrationHelper.php b/src/View/Helper/MigrationHelper.php index 9ba144b5..d0228e32 100644 --- a/src/View/Helper/MigrationHelper.php +++ b/src/View/Helper/MigrationHelper.php @@ -309,10 +309,7 @@ public function hasAutoIdIncompatiblePrimaryKey(array $tables): bool return false; } - $useUnsignedPrimaryKes = Configure::read( - 'Migrations.unsigned_primary_keys', - FeatureFlags::$unsignedPrimaryKeys - ); + $useUnsignedPrimaryKes = (bool)Configure::read('Migrations.unsigned_primary_keys'); foreach ($tables as $table) { $schema = $table; diff --git a/tests/TestCase/Db/Adapter/MysqlAdapterTest.php b/tests/TestCase/Db/Adapter/MysqlAdapterTest.php index 2f9c3172..d239f90f 100644 --- a/tests/TestCase/Db/Adapter/MysqlAdapterTest.php +++ b/tests/TestCase/Db/Adapter/MysqlAdapterTest.php @@ -6,6 +6,7 @@ use Cake\Console\ConsoleIo; use Cake\Console\TestSuite\StubConsoleInput; use Cake\Console\TestSuite\StubConsoleOutput; +use Cake\Core\Configure; use Cake\Database\Connection; use Cake\Database\Query; use Cake\Datasource\ConnectionManager; @@ -17,7 +18,6 @@ use Migrations\Db\Table\Column; use PDO; use PDOException; -use Phinx\Config\FeatureFlags; use PHPUnit\Framework\TestCase; use ReflectionClass; @@ -465,7 +465,7 @@ public function testUnsignedPksFeatureFlag() { $this->adapter->connect(); - FeatureFlags::$unsignedPrimaryKeys = false; + Configure::write('Migrations.unsigned_primary_keys', false); $table = new Table('table1', [], $this->adapter); $table->create(); diff --git a/tests/TestCase/Db/Table/ColumnTest.php b/tests/TestCase/Db/Table/ColumnTest.php index 6580636f..7c985984 100644 --- a/tests/TestCase/Db/Table/ColumnTest.php +++ b/tests/TestCase/Db/Table/ColumnTest.php @@ -3,8 +3,8 @@ namespace Migrations\Test\TestCase\Db\Table; +use Cake\Core\Configure; use Migrations\Db\Table\Column; -use Phinx\Config\FeatureFlags; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -39,7 +39,7 @@ public function testColumnNullFeatureFlag() $column = new Column(); $this->assertTrue($column->isNull()); - FeatureFlags::$columnNullDefault = false; + Configure::write('Migrations.column_null_default', false); $column = new Column(); $this->assertFalse($column->isNull()); } diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index 3fc57022..b2098c74 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -21,7 +21,6 @@ use Exception; use InvalidArgumentException; use Migrations\Migrations; -use Phinx\Config\FeatureFlags; use Phinx\Db\Adapter\WrapperInterface; use function Cake\Core\env; @@ -118,8 +117,6 @@ public function tearDown(): void unlink($file); } } - - FeatureFlags::setFlagsFromConfig(Configure::read('Migrations')); } public static function backendProvider(): array diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index 85f79312..feedef1d 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -21,7 +21,6 @@ use Cake\Routing\Router; use Cake\TestSuite\StringCompareTrait; use Cake\TestSuite\TestCase as BaseTestCase; -use Phinx\Config\FeatureFlags; abstract class TestCase extends BaseTestCase { @@ -63,8 +62,6 @@ public function tearDown(): void } $this->generatedFiles = []; } - - FeatureFlags::setFlagsFromConfig(Configure::read('Migrations')); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 49f3ea3b..a6b64b40 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,7 +20,6 @@ use Cake\Routing\Router; use Cake\TestSuite\Fixture\SchemaLoader; use Migrations\MigrationsPlugin; -use Phinx\Config\FeatureFlags; use SimpleSnapshot\Plugin as SimpleSnapshotPlugin; use TestBlog\Plugin as TestBlogPlugin; use function Cake\Core\env; @@ -69,8 +68,8 @@ ]); Configure::write('Migrations', [ - 'unsigned_primary_keys' => FeatureFlags::$unsignedPrimaryKeys, - 'column_null_default' => FeatureFlags::$columnNullDefault, + 'unsigned_primary_keys' => true, + 'column_null_default' => true, ]); Cache::setConfig([