Skip to content

Commit

Permalink
bug #40336 [Messenger] Doctrine setup with migrations (Nyholm)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 5.2 branch.

Discussion
----------

[Messenger] Doctrine setup with migrations

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  |
| Deprecations? | no
| Tickets       | Fix #40130
| License       | MIT
| Doc PR        |

This PR reverts parts of #40055.

When running these commands, You do need to be in a transaction:
- `doctrine:schema:create`
- `messenger:setup-transports`
- `doctrine:migrations:diff` and `doctrine:migrations:migrate`

Commits
-------

3371e1c [Messenger] Doctrine setup with migrations
  • Loading branch information
fabpot committed Mar 4, 2021
2 parents 5fea563 + 3371e1c commit 0940043
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ public function testGetExtraSetupSql()

$table = new Table('queue_table');
$table->addOption('_symfony_messenger_table_name', 'queue_table');
$this->assertStringContainsString('CREATE TRIGGER', implode("\n", $connection->getExtraSetupSqlForTable($table)));
$sql = implode("\n", $connection->getExtraSetupSqlForTable($table));

/*
* We need to start a transaction for the following commands to work properly:
* doctrine:schema:create
* messenger:setup-transports
* doctrine:migrations:diff and doctrine:migrations:migrate
*/
$this->assertStringContainsString('BEGIN;', $sql);
$this->assertStringContainsString('CREATE TRIGGER', $sql);

// We MUST NOT commit, that will mess with the PDO in PHP 8
$this->assertStringNotContainsString('COMMIT;', $sql);
}

public function testGetExtraSetupSqlWrongTable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function setup(): void
{
parent::setup();

$this->executeStatement('BEGIN;'.implode("\n", $this->getTriggerSql()).'COMMIT;');
$this->executeStatement(implode("\n", $this->getTriggerSql()));
}

/**
Expand All @@ -109,6 +109,7 @@ public function getExtraSetupSqlForTable(Table $createdTable): array
private function getTriggerSql(): array
{
return [
'BEGIN;',
sprintf('LOCK TABLE %s;', $this->configuration['table_name']),
// create trigger function
sprintf(<<<'SQL'
Expand Down

0 comments on commit 0940043

Please sign in to comment.