Skip to content

Commit

Permalink
Drop support for DBAL 2
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Apr 1, 2022
1 parent f9b4c80 commit 49c1ed4
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 384 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,15 @@ jobs:

strategy:
matrix:
dbal-version:
- "^2.11"
- "^3.0"
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
dependencies:
- "highest"
include:
- deps: "lowest"
php-version: "7.2"
exclude:
- dbal-version: "^3.0"
php-version: "7.2"
php-version: "7.3"

steps:
- name: "Checkout"
Expand All @@ -59,10 +52,6 @@ jobs:
- name: "Download box"
run: "./download-box.sh"

- name: "Require the right DBAL version"
run: "composer require doctrine/dbal:${{ matrix.dbal-version }} --no-update"
if: "${{ matrix.dbal-version }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
Expand Down
19 changes: 3 additions & 16 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ jobs:

strategy:
matrix:
dbal-version:
- "^2.11"
- "^3.0"
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
exclude:
- dbal-version: "^3.0"
php-version: "7.2"

steps:
- name: "Checkout code"
Expand All @@ -38,17 +32,10 @@ jobs:
php-version: "${{ matrix.php-version }}"
extensions: "pdo_sqlite"

- name: "Require the right DBAL version"
run: "composer require doctrine/dbal:${{ matrix.dbal-version }} --no-update"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Run a static analysis with phpstan/phpstan (dbal v2)"
run: "vendor/bin/phpstan analyse -c phpstan-dbal-2.neon.dist"
if: "contains(matrix.dbal-version, '^2.')"
- name: "Run a static analysis with phpstan/phpstan (dbal v3)"
run: "vendor/bin/phpstan analyse -c phpstan-dbal-3.neon.dist"
if: "contains(matrix.dbal-version, '^3.')"
- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse -c phpstan.neon.dist"
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.3 || ^8.0",
"composer-runtime-api": "^2",
"doctrine/dbal": "^2.11 || ^3.0",
"doctrine/dbal": "^3.0",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.0",
"friendsofphp/proxy-manager-lts": "^1.0",
Expand Down
5 changes: 1 addition & 4 deletions lib/Doctrine/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\Migrations\Query\Query;
use Psr\Log\LoggerInterface;

use function method_exists;
use function sprintf;

/**
Expand All @@ -43,9 +42,7 @@ abstract class AbstractMigration
public function __construct(Connection $connection, LoggerInterface $logger)
{
$this->connection = $connection;
$this->sm = method_exists($this->connection, 'createSchemaManager')
? $this->connection->createSchemaManager()
: $this->connection->getSchemaManager();
$this->sm = $this->connection->createSchemaManager();
$this->platform = $this->connection->getDatabasePlatform();
$this->logger = $logger;
}
Expand Down
23 changes: 4 additions & 19 deletions lib/Doctrine/Migrations/DependencyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Doctrine\Migrations;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\Connection\ConnectionLoader;
use Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader;
Expand Down Expand Up @@ -53,7 +51,6 @@

use function array_key_exists;
use function call_user_func;
use function method_exists;
use function preg_quote;
use function sprintf;

Expand Down Expand Up @@ -234,30 +231,18 @@ public function getSchemaDumper(): SchemaDumper

return new SchemaDumper(
$this->getConnection()->getDatabasePlatform(),
$this->getSchemaManager($this->getConnection()),
$this->getConnection()->createSchemaManager(),
$this->getMigrationGenerator(),
$this->getMigrationSqlGenerator(),
$excludedTables
);
});
}

/**
* @return AbstractSchemaManager<AbstractPlatform>
*/
private function getSchemaManager(Connection $connection): AbstractSchemaManager
{
return method_exists($connection, 'createSchemaManager')
? $connection->createSchemaManager()
: $connection->getSchemaManager();
}

private function getEmptySchemaProvider(): SchemaProvider
{
return $this->getDependency(EmptySchemaProvider::class, function (): SchemaProvider {
return new EmptySchemaProvider(
$this->getSchemaManager($this->getConnection())
);
return new EmptySchemaProvider($this->connection->createSchemaManager());
});
}

Expand Down Expand Up @@ -288,7 +273,7 @@ public function getDiffGenerator(): DiffGenerator
return $this->getDependency(DiffGenerator::class, function (): DiffGenerator {
return new DiffGenerator(
$this->getConnection()->getConfiguration(),
$this->getSchemaManager($this->getConnection()),
$this->getConnection()->createSchemaManager(),
$this->getSchemaProvider(),
$this->getConnection()->getDatabasePlatform(),
$this->getMigrationGenerator(),
Expand All @@ -303,7 +288,7 @@ public function getSchemaDiffProvider(): SchemaDiffProvider
return $this->getDependency(SchemaDiffProvider::class, function (): LazySchemaDiffProvider {
return LazySchemaDiffProvider::fromDefaultProxyFactoryConfiguration(
new DBALSchemaDiffProvider(
$this->getSchemaManager($this->getConnection()),
$this->getConnection()->createSchemaManager(),
$this->getConnection()->getDatabasePlatform()
)
);
Expand Down
13 changes: 3 additions & 10 deletions lib/Doctrine/Migrations/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\Migrations\Generator\Exception\NoChangesDetected;
use Doctrine\Migrations\Provider\SchemaProvider;

use function method_exists;
use function preg_match;
use function strpos;
use function substr;
Expand Down Expand Up @@ -96,13 +95,9 @@ static function ($assetName) use ($filterExpression) {

$toSchema = $this->createToSchema();

if (method_exists($this->schemaManager, 'createComparator')) {
$comparator = $this->schemaManager->createComparator();
}
$comparator = $this->schemaManager->createComparator();

$upSql = isset($comparator) ?
$comparator->compareSchemas($fromSchema, $toSchema)->toSql($this->platform) :
$fromSchema->getMigrateToSql($toSchema, $this->platform);
$upSql = $comparator->compareSchemas($fromSchema, $toSchema)->toSql($this->platform);

$up = $this->migrationSqlGenerator->generate(
$upSql,
Expand All @@ -111,9 +106,7 @@ static function ($assetName) use ($filterExpression) {
$checkDbPlatform
);

$downSql = isset($comparator) ?
$comparator->compareSchemas($toSchema, $fromSchema)->toSql($this->platform) :
$fromSchema->getMigrateFromSql($toSchema, $this->platform);
$downSql = $comparator->compareSchemas($toSchema, $fromSchema)->toSql($this->platform);

$down = $this->migrationSqlGenerator->generate(
$downSql,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Types;
Expand All @@ -26,7 +25,6 @@

use function array_change_key_case;
use function floatval;
use function method_exists;
use function round;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -70,7 +68,7 @@ public function __construct(
) {
$this->migrationRepository = $migrationRepository;
$this->connection = $connection;
$this->schemaManager = $connection->getSchemaManager();
$this->schemaManager = $connection->createSchemaManager();
$this->platform = $connection->getDatabasePlatform();

if ($configuration !== null && ! ($configuration instanceof TableMetadataStorageConfiguration)) {
Expand Down Expand Up @@ -185,11 +183,8 @@ private function needsUpdate(Table $expectedTable): ?TableDiff
return null;
}

$comparator = method_exists($this->schemaManager, 'createComparator') ?
$this->schemaManager->createComparator() :
new Comparator();
$currentTable = $this->schemaManager->listTableDetails($this->configuration->getTableName());
$diff = $comparator->diffTable($currentTable, $expectedTable);
$diff = $this->schemaManager->createComparator()->diffTable($currentTable, $expectedTable);

return $diff instanceof TableDiff ? $diff : null;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/Doctrine/Migrations/Provider/DBALSchemaDiffProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;

use function method_exists;

/**
* The SchemaDiffProvider class is responsible for providing a Doctrine\DBAL\Schema\Schema instance that
* represents the current state of your database. A clone of this Schema instance is passed to each of your migrations
Expand Down Expand Up @@ -50,10 +48,6 @@ public function createToSchema(Schema $fromSchema): Schema
/** @return string[] */
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema): array
{
if (! method_exists($this->schemaManager, 'createComparator')) {
return $fromSchema->getMigrateToSql($toSchema, $this->platform);
}

return $this->schemaManager->createComparator()->compareSchemas(
$fromSchema,
$toSchema
Expand Down
9 changes: 0 additions & 9 deletions lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Doctrine\Migrations\Tools\Console;

use Composer\InstalledVersions;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
use Doctrine\Migrations\Configuration\Migration\ConfigurationFileWithFallback;
use Doctrine\Migrations\DependencyFactory;
Expand Down Expand Up @@ -153,13 +151,6 @@ private static function checkLegacyConfiguration($dependencyFactory, string $con
);
}

if ($dependencyFactory->has('db') && $dependencyFactory->get('db') instanceof ConnectionHelper) {
return DependencyFactory::fromConnection(
$configurations,
new ExistingConnection($dependencyFactory->get('db')->getConnection())
);
}

throw new RuntimeException(sprintf(
'Configuration HelperSet returned by "%s" does not have a valid "em" or the "db" helper.',
$configurationFile
Expand Down
8 changes: 3 additions & 5 deletions lib/Doctrine/Migrations/Tools/TransactionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ private static function inTransaction(Connection $connection): bool
*/
private static function getInnerConnection(Connection $connection)
{
if (method_exists($connection, 'getNativeConnection')) {
try {
return $connection->getNativeConnection();
} catch (LogicException $e) {
}
try {
return $connection->getNativeConnection();
} catch (LogicException $e) {
}

$innermostConnection = $connection;
Expand Down
42 changes: 0 additions & 42 deletions phpstan-dbal-2.neon.dist

This file was deleted.

Loading

0 comments on commit 49c1ed4

Please sign in to comment.