-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#39] - Adds a data patch to handle the data migration from run_as_ro…
…ot_message to run_as_root_queue_error_message database table
- Loading branch information
1 parent
9b3aa7d
commit f4abcea
Showing
3 changed files
with
57 additions
and
22 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/Setup/Patch/Data/HandleMigrationFromMessageTablePatch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RunAsRoot\MessageQueueRetry\Setup\Patch\Data; | ||
|
||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
|
||
/** | ||
* The reason for this class is to handle the migration from the old message table to the new one. | ||
* This is necessary because errors are being generated during integration testes while using | ||
* the onCreate="migrateDataFromAnotherTable('old_table')" in the db_schema.xml | ||
*/ | ||
class HandleMigrationFromMessageTablePatch implements DataPatchInterface | ||
{ | ||
public function __construct( | ||
private readonly ModuleDataSetupInterface $moduleDataSetup, | ||
) { | ||
} | ||
|
||
public function getAliases(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function apply(): self | ||
{ | ||
$this->moduleDataSetup->startSetup(); | ||
|
||
$connection = $this->moduleDataSetup->getConnection(); | ||
$oldMessageTable = $this->moduleDataSetup->getTable('run_as_root_message'); | ||
$newMessageTable = $this->moduleDataSetup->getTable('run_as_root_queue_error_message'); | ||
|
||
if (!$connection->isTableExists($oldMessageTable) || !$connection->isTableExists($newMessageTable)) { | ||
$this->moduleDataSetup->endSetup(); | ||
return $this; | ||
} | ||
|
||
$select = $connection->select()->from($oldMessageTable); | ||
|
||
$connection->query($connection->insertFromSelect($select, $newMessageTable)); | ||
|
||
$connection->dropTable($oldMessageTable); | ||
|
||
$this->moduleDataSetup->endSetup(); | ||
|
||
return $this; | ||
} | ||
|
||
public static function getDependencies(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters