Skip to content

Commit 932cde8

Browse files
[#39] - Split patch data script to avoid database deadlocks
1 parent f8d2fd3 commit 932cde8

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

src/Setup/Patch/Data/HandleMigrationFromMessageTablePatch.php renamed to src/Setup/Patch/Data/CopyDataFromOldMessageTable.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
/**
1111
* The reason for this class is to handle the migration from the old message table to the new one.
1212
* This is necessary because errors are being generated during integration testes while using
13-
* the onCreate="migrateDataFromAnotherTable('old_table')" in the db_schema.xml
13+
* the onCreate="migrateDataFromAnotherTable('run_as_root_message')" in the db_schema.xml
1414
*/
15-
class HandleMigrationFromMessageTablePatch implements DataPatchInterface
15+
class CopyDataFromOldMessageTable implements DataPatchInterface
1616
{
1717
public function __construct(
1818
private readonly ModuleDataSetupInterface $moduleDataSetup,
@@ -38,11 +38,8 @@ public function apply(): self
3838
}
3939

4040
$select = $connection->select()->from($oldMessageTable);
41-
4241
$connection->query($connection->insertFromSelect($select, $newMessageTable));
4342

44-
$connection->dropTable($oldMessageTable);
45-
4643
$this->moduleDataSetup->endSetup();
4744

4845
return $this;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RunAsRoot\MessageQueueRetry\Setup\Patch\Data;
6+
7+
use Magento\Framework\Setup\ModuleDataSetupInterface;
8+
use Magento\Framework\Setup\Patch\DataPatchInterface;
9+
10+
/**
11+
* The reason for this class is to handle the migration from the old message table to the new one.
12+
* This is necessary because errors are being generated during integration testes while using
13+
* the onCreate="migrateDataFromAnotherTable('run_as_root_message')" in the db_schema.xml
14+
*/
15+
class DeleteOldMessageTable implements DataPatchInterface
16+
{
17+
public function __construct(
18+
private readonly ModuleDataSetupInterface $moduleDataSetup,
19+
) {
20+
}
21+
22+
public function getAliases(): array
23+
{
24+
return [];
25+
}
26+
27+
public function apply(): self
28+
{
29+
$this->moduleDataSetup->startSetup();
30+
31+
$connection = $this->moduleDataSetup->getConnection();
32+
$oldMessageTable = $this->moduleDataSetup->getTable('run_as_root_message');
33+
34+
if (!$connection->isTableExists($oldMessageTable)) {
35+
$this->moduleDataSetup->endSetup();
36+
return $this;
37+
}
38+
39+
$connection->dropTable($oldMessageTable);
40+
41+
$this->moduleDataSetup->endSetup();
42+
43+
return $this;
44+
}
45+
46+
public static function getDependencies(): array
47+
{
48+
return [CopyDataFromOldMessageTable::class];
49+
}
50+
}

0 commit comments

Comments
 (0)