Files
thetool/db/migrations/20250604140000_preorder_notification_modify.php
2025-06-04 15:31:11 +02:00

86 lines
3.2 KiB
PHP

<?php /** @noinspection ALL */
declare(strict_types = 1);
use Phinx\Migration\AbstractMigration;
final class PreorderNotificationModify extends AbstractMigration {
public function up(): void {
if ($this->getEnvironment() == "thetool") {
$PreorderNotificationTable = $this->table("PreordercampaignStatusnotificationMailtemplate");
if ($PreorderNotificationTable->hasColumn("status_code")) {
$PreorderNotificationTable
->changeColumn("status_code", "integer", ["null" => true])
->update();
}
if (!$PreorderNotificationTable->hasColumn("notification_type")) {
$PreorderNotificationTable
->addColumn("notification_type", "enum", [
"values" => ["status", "logical"],
"default" => "status",
"null" => false,
"after" => "status_code"
])
->update();
}
if (!$PreorderNotificationTable->hasColumn("logical_config")) {
$PreorderNotificationTable
->addColumn("logical_config", "json", [
"null" => true,
"after" => "notification_type"
])
->update();
}
if (!$PreorderNotificationTable->hasIndex(["notification_type"])) {
$PreorderNotificationTable
->addIndex(["notification_type"], ["name" => "idx_notification_type"])
->update();
}
if (!$PreorderNotificationTable->hasIndex(["status_code"])) {
$PreorderNotificationTable
->addIndex(["status_code"], ["name" => "idx_status_code"])
->update();
}
}
}
public function down(): void {
if ($this->getEnvironment() == "thetool") {
$PreorderNotificationTable = $this->table("PreordercampaignStatusnotificationMailtemplate");
if ($PreorderNotificationTable->hasIndex(["notification_type"])) {
$PreorderNotificationTable
->removeIndex(["notification_type"])
->update();
}
if ($PreorderNotificationTable->hasIndex(["status_code"])) {
$PreorderNotificationTable
->removeIndex(["status_code"])
->update();
}
if ($PreorderNotificationTable->hasColumn("logical_config")) {
$PreorderNotificationTable
->removeColumn("logical_config")
->update();
}
if ($PreorderNotificationTable->hasColumn("notification_type")) {
$PreorderNotificationTable
->removeColumn("notification_type")
->update();
}
if ($PreorderNotificationTable->hasColumn("status_code")) {
$PreorderNotificationTable
->changeColumn("status_code", "integer", ["null" => false])
->update();
}
}
}
}