diff --git a/src/migrations/m240808_084903_add_program_id_to_orders.php b/src/migrations/m240808_084903_add_program_id_to_orders.php index 1e34cb3a..aaca7c70 100644 --- a/src/migrations/m240808_084903_add_program_id_to_orders.php +++ b/src/migrations/m240808_084903_add_program_id_to_orders.php @@ -3,6 +3,7 @@ namespace acclaro\translations\migrations; use acclaro\translations\Constants; +use Craft; use craft\db\Migration; /** @@ -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; } diff --git a/src/migrations/m241216_081944_upsert_program_id_column.php b/src/migrations/m241216_081944_upsert_program_id_column.php new file mode 100644 index 00000000..1cda6dbd --- /dev/null +++ b/src/migrations/m241216_081944_upsert_program_id_column.php @@ -0,0 +1,51 @@ +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; + } +}