CreateRevenueTable.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Revenue\Migrations; |
| 4 | |
| 5 | use Give\Framework\Migrations\Contracts\Migration; |
| 6 | use Give\Helpers\Table; |
| 7 | |
| 8 | class CreateRevenueTable extends Migration { |
| 9 | /** |
| 10 | * @inheritDoc |
| 11 | * |
| 12 | * @since 2.9.0 |
| 13 | */ |
| 14 | public static function id() { |
| 15 | return 'create_revenue_table'; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * @inheritDoc |
| 20 | * |
| 21 | * @since 2.9.0 |
| 22 | */ |
| 23 | public static function timestamp() { |
| 24 | return strtotime( '2019-09-16' ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @inheritDoc |
| 29 | * |
| 30 | * @since 2.9.0 |
| 31 | */ |
| 32 | public function run() { |
| 33 | global $wpdb; |
| 34 | |
| 35 | $charset_collate = $wpdb->get_charset_collate(); |
| 36 | $tableName = "{$wpdb->prefix}give_revenue"; |
| 37 | $referencedTableName = "{$wpdb->prefix}posts"; |
| 38 | |
| 39 | $sql = "CREATE TABLE {$tableName} ( |
| 40 | id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 41 | donation_id bigint(20) UNSIGNED NOT NULL, |
| 42 | form_id bigint(20) UNSIGNED NOT NULL, |
| 43 | amount int UNSIGNED NOT NULL, |
| 44 | PRIMARY KEY (id), |
| 45 | FOREIGN KEY (donation_id) REFERENCES {$referencedTableName}(ID) ON DELETE CASCADE, |
| 46 | FOREIGN KEY (form_id) REFERENCES {$referencedTableName}(ID) |
| 47 | ) {$charset_collate};"; |
| 48 | |
| 49 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 50 | dbDelta( $sql ); |
| 51 | } |
| 52 | } |
| 53 |