Skip to content

Commit

Permalink
#564: Migration fix for program id missing
Browse files Browse the repository at this point in the history
  • Loading branch information
sharmarishabh1 authored and bhupeshappfoster committed Dec 17, 2024
1 parent a8ceb75 commit a075d08
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/migrations/m240808_084903_add_program_id_to_orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace acclaro\translations\migrations;

use acclaro\translations\Constants;
use Craft;
use craft\db\Migration;

/**
Expand All @@ -27,9 +28,14 @@ public function safeUp(): bool
*/
public function safeDown(): bool
{
echo "Dropping translations_orders programId column...\n";
$this->dropColumn(Constants::TABLE_ORDERS, 'programId');
echo "Done dropping translations_orders programId column...\n";
$tableName = Constants::TABLE_ORDERS;
$columnName = 'programId';

// Remove the column if it exists
if ($this->db->columnExists($tableName, $columnName)) {
$this->dropColumn($tableName, $columnName);
Craft::info("Dropped column '{$columnName}' from table '{$tableName}'", __METHOD__);
}

return true;
}
Expand Down
51 changes: 51 additions & 0 deletions src/migrations/m241216_081944_upsert_program_id_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace acclaro\translations\migrations;

use acclaro\translations\Constants;
use Craft;
use craft\db\Migration;

/**
* m241216_081944_upsert_program_id_column migration.
*/
class m241216_081944_upsert_program_id_column extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
$tableName = Constants::TABLE_ORDERS;
$columnName = 'programId';

// Check if the column exists
if (!$this->db->columnExists($tableName, $columnName)) {

$this->addColumn($tableName, $columnName, $this->integer()->null()->after('ownerId'));

Craft::info("Added column '{$columnName}' to table '{$tableName}'", __METHOD__);
} else {
Craft::info("Column '{$columnName}' already exists in table '{$tableName}'", __METHOD__);
}

return true;
}

/**
* @inheritdoc
*/
public function safeDown(): bool
{
$tableName = Constants::TABLE_ORDERS;
$columnName = 'programId';

// Remove the column if it exists
if ($this->db->columnExists($tableName, $columnName)) {
$this->dropColumn($tableName, $columnName);
Craft::info("Dropped column '{$columnName}' from table '{$tableName}'", __METHOD__);
}

return true;
}
}

0 comments on commit a075d08

Please sign in to comment.