-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#564: Migration fix for program id missing
- Loading branch information
1 parent
a8ceb75
commit a075d08
Showing
2 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
src/migrations/m241216_081944_upsert_program_id_column.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,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; | ||
} | ||
} |