Skip to content

Commit

Permalink
feature: register migration for setting up the campaign type for exis…
Browse files Browse the repository at this point in the history
…ting campaigns (p2p)
  • Loading branch information
alaca committed Aug 27, 2024
1 parent 0516133 commit 986cfe1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
55 changes: 55 additions & 0 deletions src/Campaigns/Migrations/Tables/AddCampaignTypeColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Give\Campaigns\Migrations\Tables;

use Give\Framework\Database\DB;
use Give\Framework\Database\Exceptions\DatabaseQueryException;
use Give\Framework\Migrations\Contracts\Migration;
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException;

/**
* @unreleased
*
* Modifies the give_campaigns table by adding the campaign_type column
*/
class AddCampaignTypeColumn extends Migration
{
/**
* @inheritdoc
*/
public static function id(): string
{
return 'give-campaigns-add-campaign-type-column';
}

/**
* @inheritdoc
*/
public static function title(): string
{
return 'Add campaign_type column to give_campaigns table';
}

/**
* @inheritdoc
*/
public static function timestamp(): string
{
return strtotime('2024-08-26 00:00:01');
}

/**
* @inheritDoc
* @throws DatabaseMigrationException
*/
public function run()
{
global $wpdb;

try {
DB::query("ALTER TABLE {$wpdb->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);
}
}
}
3 changes: 1 addition & 2 deletions src/Campaigns/Migrations/Tables/CreateCampaignsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Campaigns/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@ private function registerMigrations(): void
give(MigrationsRegister::class)->addMigrations(
[
CreateCampaignsTable::class,
AddCampaignTypeColumn::class,
CreateCampaignFormsTable::class,
]
);
Expand Down

0 comments on commit 986cfe1

Please sign in to comment.