8000 [Messenger] Expose the Doctrine Schema to help with migrations · symfony/symfony@77f8d48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77f8d48

Browse files
committed
[Messenger] Expose the Doctrine Schema to help with migrations
1 parent b2d1ec5 commit 77f8d48

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ public function setup(): void
243243
$this->driverConnection->getConfiguration()->setFilterSchemaAssetsExpression(null);
244244
}
245245

246-
$this->schemaSynchronizer->updateSchema($this->getSchema(), true);
246+
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
247+
Migration::create($schema, $this->configuration['table_name']);
248+
249+
$this->schemaSynchronizer->updateSchema($schema, true);
247250

248251
if ($hasFilterCallback) {
249252
$this->driverConnection->getConfiguration()->setSchemaAssetsFilter($assetFilter);
@@ -337,33 +340,6 @@ private function executeQuery(string $sql, array $parameters = [], array $types
337340
return $stmt;
338341
}
339342

340-
private function getSchema(): Schema
341-
{
342-
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
343-
$table = $schema->createTable($this->configuration['table_name']);
344-
$table->addColumn('id', self::$useDeprecatedConstants ? Type::BIGINT : Types::BIGINT)
345-
->setAutoincrement(true)
346-
->setNotnull(true);
347-
$table->addColumn('body', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
348-
->setNotnull(true);
349-
$table->addColumn('headers', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
350-
->setNotnull(true);
351-
$table->addColumn('queue_name', self::$useDeprecatedConstants ? Type::STRING : Types::STRING)
352-
->setNotnull(true);
353-
$table->addColumn('created_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
354-
->setNotnull(true);
355-
$table->addColumn('available_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
356-
->setNotnull(true);
357-
$table->addColumn('delivered_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
358-
->setNotnull(false);
359-
$table->setPrimaryKey(['id']);
360-
$table->addIndex(['queue_name']);
361-
$table->addIndex(['available_at']);
362-
$table->addIndex(['delivered_at']);
363-
364-
return $schema;
365-
}
366-
367343
private function decodeEnvelopeHeaders(array $doctrineEnvelope): array
368344
{
369345
$doctrineEnvelope['headers'] = json_decode($doctrineEnvelope['headers'], true);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Bridge\Doctrine\Transport;
13+
14+
use Doctrine\DBAL\Schema\Schema;
15+
use Doctrine\DBAL\Types\Type;
16+
use Doctrine\DBAL\Types\Types;
17+
18+
final class Migration
19+
{
20+
public static function up(Schema $schema, string $tableName = 'messenger_messages'): void
21+
{
22+
$useDeprecatedConstants = !class_exists(Types::class);
23+
24+
$table = $schema->createTable($tableName);
25+
$table->addColumn('id', $useDeprecatedConstants ? Type::BIGINT : Types::BIGINT)
26+
->setAutoincrement(true)
27+
->setNotnull(true);
28+
$table->addColumn('body', $useDeprecatedConstants ? Type::TEXT : Types::TEXT)
29+
->setNotnull(true);
30+
$table->addColumn('headers', $useDeprecatedConstants ? Type::TEXT : Types::TEXT)
31+
->setNotnull(true);
32+
$table->addColumn('queue_name', $useDeprecatedConstants ? Type::STRING : Types::STRING)
33+
->setNotnull(true);
34+
$table->addColumn('created_at', $useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
35+
->setNotnull(true);
36+
$table->addColumn('available_at', $useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
37+
->setNotnull(true);
38+
$table->addColumn('delivered_at', $useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
39+
->setNotnull(false);
40+
$table->setPrimaryKey(['id']);
41+
$table->addIndex(['queue_name']);
42+
$table->addIndex(['available_at']);
43+
$table->addIndex(['delivered_at']);
44+
}
45+
}

0 commit comments

Comments
 (0)
0