Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert FeatureFlags to Configure operations #707

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Migrations\Db\Adapter;

use Cake\Core\Configure;
use Cake\Database\Connection;
use InvalidArgumentException;
use Migrations\Db\AlterInstructions;
Expand All @@ -16,7 +17,6 @@
use Migrations\Db\Table\ForeignKey;
use Migrations\Db\Table\Index;
use Migrations\Db\Table\Table;
use Phinx\Config\FeatureFlags;

/**
* Phinx MySQL Adapter.
Expand Down Expand Up @@ -232,12 +232,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,
]);

Expand Down
4 changes: 2 additions & 2 deletions src/Db/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,7 +166,7 @@ class Column
*/
public function __construct()
{
$this->null = FeatureFlags::$columnNullDefault;
$this->null = (bool)Configure::read('Migrations.column_null_default');
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Migration/BuiltinBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions src/Migration/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?
];

Expand Down
6 changes: 1 addition & 5 deletions src/View/Helper/MigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\View;
use Phinx\Config\FeatureFlags;

/**
* Migration Helper class for output of field data in migration files.
Expand Down Expand Up @@ -309,10 +308,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;
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +18,6 @@
use Migrations\Db\Table\Column;
use PDO;
use PDOException;
use Phinx\Config\FeatureFlags;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Db/Table/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
3 changes: 0 additions & 3 deletions tests/TestCase/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -118,8 +117,6 @@ public function tearDown(): void
unlink($file);
}
}

FeatureFlags::setFlagsFromConfig(Configure::read('Migrations'));
}

public static function backendProvider(): array
Expand Down
4 changes: 0 additions & 4 deletions tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
namespace Migrations\Test\TestCase;

use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\Core\Configure;
use Cake\Routing\Router;
use Cake\TestSuite\StringCompareTrait;
use Cake\TestSuite\TestCase as BaseTestCase;
use Phinx\Config\FeatureFlags;

abstract class TestCase extends BaseTestCase
{
Expand Down Expand Up @@ -63,8 +61,6 @@ public function tearDown(): void
}
$this->generatedFiles = [];
}

FeatureFlags::setFlagsFromConfig(Configure::read('Migrations'));
}

/**
Expand Down
5 changes: 2 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down
Loading