Skip to content

Commit

Permalink
[Bug] Make migration idempotent (#441)
Browse files Browse the repository at this point in the history
* Make migration idempotent

* Apply php-cs-fixer changes

---------

Co-authored-by: mattamon <[email protected]>
  • Loading branch information
mattamon and mattamon authored Dec 2, 2024
1 parent d9c7d8a commit 6aaa082
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/Migrations/Version20240715160305.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,44 @@ class Version20240715160305 extends BundleAwareMigration
{
public function up(Schema $schema): void
{
if ($schema->hasTable(QueueService::QUEUE_TABLE_NAME)) {
$queueTable = $schema->getTable(QueueService::QUEUE_TABLE_NAME);
$queueTable->addColumn('userOwner', 'integer', ['notnull' => true, 'default' => 0])->setUnsigned(true);
$queueTable->addIndex(['userOwner'], 'bundle_index_queue_executiontype_userOwner');
if (!$schema->hasTable(QueueService::QUEUE_TABLE_NAME)) {
return;
}

$queueTable = $schema->getTable(QueueService::QUEUE_TABLE_NAME);

if ($queueTable->hasColumn('userOwner')) {
return;
}

$queueTable->addColumn('userOwner', 'integer', ['notnull' => true, 'default' => 0])->setUnsigned(true);

if ($queueTable->hasIndex('bundle_index_queue_executiontype_userOwner')) {
return;
}

$queueTable->addIndex(['userOwner'], 'bundle_index_queue_executiontype_userOwner');
}

public function down(Schema $schema): void
{
if ($schema->hasTable(QueueService::QUEUE_TABLE_NAME)) {
$queueTable = $schema->getTable(QueueService::QUEUE_TABLE_NAME);
$queueTable->dropColumn('userOwner');
$queueTable->dropIndex('bundle_index_queue_executiontype_userOwner');
if (!$schema->hasTable(QueueService::QUEUE_TABLE_NAME)) {
return;
}

$queueTable = $schema->getTable(QueueService::QUEUE_TABLE_NAME);

if (!$queueTable->hasColumn('userOwner')) {
return;
}

$queueTable->dropColumn('userOwner');

if (!$queueTable->hasIndex('bundle_index_queue_executiontype_userOwner')) {
return;
}

$queueTable->dropIndex('bundle_index_queue_executiontype_userOwner');
}

protected function getBundleName(): string
Expand Down

0 comments on commit 6aaa082

Please sign in to comment.