AddPastDonationsToRevenueTable.php
5 years ago
CreateRevenueTable.php
5 years ago
RemoveRevenueForeignKeys.php
5 years ago
CreateRevenueTable.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Revenue\Migrations; |
| 4 | |
| 5 | use Give\Framework\Database\Exceptions\DatabaseQueryException; |
| 6 | use Give\Framework\Migrations\Contracts\Migration; |
| 7 | use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; |
| 8 | use Give\Framework\Database\DB; |
| 9 | use Give\Helpers\Table; |
| 10 | |
| 11 | class CreateRevenueTable extends Migration { |
| 12 | /** |
| 13 | * @inheritDoc |
| 14 | * |
| 15 | * @since 2.9.0 |
| 16 | */ |
| 17 | public static function id() { |
| 18 | return 'create_revenue_table'; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | * |
| 24 | * @since 2.9.0 |
| 25 | */ |
| 26 | public static function timestamp() { |
| 27 | return strtotime( '2019-09-16' ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @inheritDoc |
| 32 | * |
| 33 | * @since 2.9.0 |
| 34 | * @since 2.9.2 throw an exception if there is a SQL error and add log |
| 35 | * |
| 36 | * @throws DatabaseMigrationException |
| 37 | */ |
| 38 | public function run() { |
| 39 | global $wpdb; |
| 40 | |
| 41 | $charset_collate = $wpdb->get_charset_collate(); |
| 42 | $tableName = "{$wpdb->prefix}give_revenue"; |
| 43 | |
| 44 | $sql = "CREATE TABLE {$tableName} ( |
| 45 | id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 46 | donation_id bigint UNSIGNED NOT NULL, |
| 47 | form_id bigint UNSIGNED NOT NULL, |
| 48 | amount int UNSIGNED NOT NULL, |
| 49 | PRIMARY KEY (id) |
| 50 | ) {$charset_collate};"; |
| 51 | |
| 52 | try { |
| 53 | DB::delta( $sql ); |
| 54 | } catch ( DatabaseQueryException $exception ) { |
| 55 | throw new DatabaseMigrationException( 'An error occurred creating the revenue table: ' . print_r( $exception->getQueryErrors(), true ) ); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 |