Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#564: Migration fix for program id missing #541

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}