| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\EventTickets\Migrations; |
| 4 |
|
| 5 |
use Give\Framework\Database\DB; |
| 6 |
use Give\Framework\Database\Exceptions\DatabaseQueryException; |
| 7 |
use Give\Framework\Migrations\Contracts\Migration; |
| 8 |
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; |
| 9 |
|
| 10 |
/** |
| 11 |
* @since 3.6.0 |
| 12 |
*/ |
| 13 |
class CreateEventTicketTypesTable extends Migration { |
| 14 |
/** |
| 15 |
* @inheritdoc |
| 16 |
*/ |
| 17 |
public static function id() { |
| 18 |
return 'give-events-create-events-ticket-types-table'; |
| 19 |
} |
| 20 |
|
| 21 |
public static function title() { |
| 22 |
return 'Create give_event_ticket_types table'; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* @inheritdoc |
| 27 |
*/ |
| 28 |
public static function timestamp() { |
| 29 |
return strtotime( '2022-01-29 01:00:00' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritdoc |
| 34 |
* @throws DatabaseMigrationException |
| 35 |
*/ |
| 36 |
public function run() { |
| 37 |
global $wpdb; |
| 38 |
|
| 39 |
$table = $wpdb->give_event_ticket_types; |
| 40 |
$charset = DB::get_charset_collate(); |
| 41 |
|
| 42 |
$sql = "CREATE TABLE $table ( |
| 43 |
id INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 44 |
event_id INT UNSIGNED NOT NULL, |
| 45 |
title TEXT NULL, |
| 46 |
description TEXT NULL, |
| 47 |
price INT UNSIGNED NOT NULL, |
| 48 |
capacity INT UNSIGNED NULL, |
| 49 |
created_at DATETIME NOT NULL, |
| 50 |
updated_at DATETIME NOT NULL, |
| 51 |
PRIMARY KEY (id) |
| 52 |
) $charset"; |
| 53 |
|
| 54 |
try { |
| 55 |
DB::delta( $sql ); |
| 56 |
} catch ( DatabaseQueryException $exception ) { |
| 57 |
throw new DatabaseMigrationException( "An error occurred while creating the $table table", 0, $exception ); |
| 58 |
} |
| 59 |
} |
| 60 |
}; |
| 61 |
|