8000 [Messenger] Preserve existing Doctrine schema by nicolas-grekas · Pull Request #50742 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Preserve existing Doctrine schema #50742

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

Merged
merged 1 commit into from
Jun 22, 2023
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
3 changes: 1 addition & 2 deletions src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
Expand Down Expand Up @@ -89,7 +88,7 @@ public function __construct($connOrDsn, string $namespace = '', int $defaultLife
$params = ['url' => $connOrDsn];
}

$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\SkippedTestSuiteError;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
Expand Down Expand Up @@ -160,7 +159,7 @@ private function createConnectionMock()

private function getDbalConfig()
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\SkippedTestSuiteError;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
Expand Down Expand Up @@ -176,7 +175,7 @@ private function createConnectionMock()

private function getDbalConfig(): Configuration
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Traits\RedisClusterProxy;
use Symfony\Component\Cache\Traits\RedisProxy;
Expand Down Expand Up @@ -77,7 +76,7 @@ public static function createHandler($connection): AbstractSessionHandler
}
$connection[3] = '-';
$params = class_exists(DsnParser::class) ? (new DsnParser())->parse($connection) : ['url' => $connection];
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
use Symfony\Component\Lock\BlockingStoreInterface;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function __construct($connOrUrl)
$params = ['url' => $this->filterDsn($connOrUrl)];
}

$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Lock/Store/DoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\InvalidTtlException;
use Symfony\Component\Lock\Exception\LockConflictedException;
Expand Down Expand Up @@ -88,7 +87,7 @@ public function __construct($connOrUrl, array $options = [], float $gcProbabilit
$params = ['url' => $connOrUrl];
}

$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\LockConflictedException;
use Symfony\Component\Lock\Key;
Expand Down Expand Up @@ -176,7 +175,7 @@ public function testWaitAndSaveReadAfterConflictReleasesLockFromInternalStore()
private static function getDbalConnection(string $dsn): Connection
{
$params = class_exists(DsnParser::class) ? (new DsnParser(['sqlite' => 'pdo_sqlite']))->parse($dsn) : ['url' => $dsn];
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\DoctrineDbalStore;
Expand All @@ -39,7 +38,7 @@ public static function setUpBeforeClass(): void
{
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_lock');

$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand All @@ -66,7 +65,7 @@ protected function getClockDelay()
*/
public function getStore(): PersistingStoreInterface
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
5 changes: 2 additions & 3 deletions src/Symfony/Component/Lock/Tests/Store/PdoDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\ORMSetup;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistingStoreInterface;
Expand All @@ -40,7 +39,7 @@ public static function setUpBeforeClass(): void
{
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_lock');

$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down Expand Up @@ -69,7 +68,7 @@ public function getStore(): PersistingStoreInterface
{
$this->expectDeprecation('Since symfony/lock 5.4: Usage of a DBAL Connection with "Symfony\Component\Lock\Store\PdoStore" is deprecated and will be removed in symfony 6.0. Use "Symfony\Component\Lock\Store\DoctrineDbalStore" instead.');

$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
Expand All @@ -37,7 +36,7 @@ protected function setUp(): void
{
$dsn = getenv('MESSENGER_DOCTRINE_DSN') ?: 'pdo-sqlite://:memory:';
$params = class_exists(DsnParser::class) ? (new DsnParser())->parse($dsn) : ['url' => $dsn];
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Tools\DsnParser;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;
Expand All @@ -42,7 +41,7 @@ protected function setUp(): void

$url = "pdo-pgsql://postgres:password@$host";
$params = class_exists(DsnParser::class) ? (new DsnParser())->parse($url) : ['url' => $url];
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration() : new Configuration();
$config = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,39 @@ private function updateSchema(): void
$comparator = $this->createComparator($schemaManager);
$schemaDiff = $this->compareSchemas($comparator, method_exists($schemaManager, 'introspectSchema') ? $schemaManager->introspectSchema() : $schemaManager->createSchema(), $this->getSchema());
$platform = $this->driverConnection->getDatabasePlatform();
$queries = method_exists($platform, 'getAlterSchemaSQL') ? $platform->getAlterSchemaSQL($schemaDiff) : $schemaDiff->toSaveSql($platform);
$exec = method_exists($this->driverConnection, 'executeStatement') ? 'executeStatement' : 'exec';

foreach ($queries as $sql) {
if (method_exists($this->driverConnection, 'executeStatement')) {
$this->driverConnection->executeStatement($sql);
} else {
$this->driverConnection->exec($sql);
if (!method_exists(SchemaDiff::class, 'getCreatedSchemas')) {
foreach ($schemaDiff->toSaveSql($platform) as $sql) {
$this->driverConnection->$exec($sql);
}

return;
}

if ($platform->supportsSchemas()) {
foreach ($schemaDiff->getCreatedSchemas() as $schema) {
$this->driverConnection->$exec($platform->getCreateSchemaSQL($schema));
}
}

if ($platform->supportsSequences()) {
foreach ($schemaDiff->getAlteredSequences() as $sequence) {
$this->driverConnection->$exec($platform->getAlterSequenceSQL($sequence));
}

foreach ($schemaDiff->getCreatedSequences() as $sequence) {
$this->driverConnection->$exec($platform->getCreateSequenceSQL($sequence));
}
}

foreach ($platform->getCreateTablesSQL($schemaDiff->getCreatedTables()) as $sql) {
$this->driverConnection->$exec($sql);
}

foreach ($schemaDiff->getAlteredTables() as $tableDiff) {
foreach ($platform->getAlterTableSQL($tableDiff) as $sql) {
$this->driverConnection->$exec($sql);
}
}
}
Expand Down
0