From 986cfe14895a177431734823a8b4d121549cb676 Mon Sep 17 00:00:00 2001 From: alaca Date: Tue, 27 Aug 2024 13:05:30 +0200 Subject: [PATCH] feature: register migration for setting up the campaign type for existing campaigns (p2p) --- .../Tables/AddCampaignTypeColumn.php | 55 +++++++++++++++++++ .../Tables/CreateCampaignsTable.php | 3 +- src/Campaigns/ServiceProvider.php | 2 + 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/Campaigns/Migrations/Tables/AddCampaignTypeColumn.php diff --git a/src/Campaigns/Migrations/Tables/AddCampaignTypeColumn.php b/src/Campaigns/Migrations/Tables/AddCampaignTypeColumn.php new file mode 100644 index 0000000000..d54b13d12f --- /dev/null +++ b/src/Campaigns/Migrations/Tables/AddCampaignTypeColumn.php @@ -0,0 +1,55 @@ +give_campaigns} ADD COLUMN `campaign_type` VARCHAR(12) NOT NULL DEFAULT ''"); + } catch (DatabaseQueryException $exception) { + throw new DatabaseMigrationException("An error occurred while updating the {$wpdb->give_campaigns} table", 0, $exception); + } + } +} diff --git a/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php b/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php index 8bd6b2dec8..b028eed261 100644 --- a/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php +++ b/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php @@ -18,7 +18,7 @@ class CreateCampaignsTable extends Migration */ public static function id(): string { - return 'give-campaigns-create-give-core-campaigns-table'; + return 'give-campaigns-create-give-campaigns-table'; } /** @@ -51,7 +51,6 @@ public function run() $sql = "CREATE TABLE $table ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, form_id INT NOT NULL, - campaign_type VARCHAR(12) NOT NULL DEFAULT '', campaign_title TEXT NOT NULL, campaign_url TEXT NOT NULL, short_desc TEXT NOT NULL, diff --git a/src/Campaigns/ServiceProvider.php b/src/Campaigns/ServiceProvider.php index 8e8935f337..4d2169c748 100644 --- a/src/Campaigns/ServiceProvider.php +++ b/src/Campaigns/ServiceProvider.php @@ -2,6 +2,7 @@ namespace Give\Campaigns; +use Give\Campaigns\Migrations\Tables\AddCampaignTypeColumn; use Give\Campaigns\Migrations\Tables\CreateCampaignFormsTable; use Give\Campaigns\Migrations\Tables\CreateCampaignsTable; use Give\Framework\Migrations\MigrationsRegister; @@ -44,6 +45,7 @@ private function registerMigrations(): void give(MigrationsRegister::class)->addMigrations( [ CreateCampaignsTable::class, + AddCampaignTypeColumn::class, CreateCampaignFormsTable::class, ] );