| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Config\Migrations; |
| 4 |
|
| 5 |
use Yoast\WP\Lib\Migrations\Migration; |
| 6 |
use Yoast\WP\Lib\Model; |
| 7 |
|
| 8 |
/** |
| 9 |
* Migration for the Primary Term. |
| 10 |
*/ |
| 11 |
class WpYoastPrimaryTerm extends Migration { |
| 12 |
|
| 13 |
/** |
| 14 |
* The plugin this migration belongs to. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
public static $plugin = 'free'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Migration up. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public function up() { |
| 26 |
$table_name = $this->get_table_name(); |
| 27 |
|
| 28 |
$indexable_table = $this->create_table( $table_name ); |
| 29 |
|
| 30 |
$indexable_table->column( |
| 31 |
'post_id', |
| 32 |
'integer', |
| 33 |
[ |
| 34 |
'unsigned' => true, |
| 35 |
'null' => false, |
| 36 |
'limit' => 11, |
| 37 |
], |
| 38 |
); |
| 39 |
$indexable_table->column( |
| 40 |
'term_id', |
| 41 |
'integer', |
| 42 |
[ |
| 43 |
'unsigned' => true, |
| 44 |
'null' => false, |
| 45 |
'limit' => 11, |
| 46 |
], |
| 47 |
); |
| 48 |
$indexable_table->column( |
| 49 |
'taxonomy', |
| 50 |
'string', |
| 51 |
[ |
| 52 |
'null' => false, |
| 53 |
'limit' => 32, |
| 54 |
], |
| 55 |
); |
| 56 |
|
| 57 |
// Executes the SQL to create the table. |
| 58 |
$indexable_table->finish(); |
| 59 |
|
| 60 |
$this->add_index( |
| 61 |
$table_name, |
| 62 |
[ |
| 63 |
'post_id', |
| 64 |
'taxonomy', |
| 65 |
], |
| 66 |
[ |
| 67 |
'name' => 'post_taxonomy', |
| 68 |
], |
| 69 |
); |
| 70 |
|
| 71 |
$this->add_index( |
| 72 |
$table_name, |
| 73 |
[ |
| 74 |
'post_id', |
| 75 |
'term_id', |
| 76 |
], |
| 77 |
[ |
| 78 |
'name' => 'post_term', |
| 79 |
], |
| 80 |
); |
| 81 |
|
| 82 |
$this->add_timestamps( $table_name ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Migration down. |
| 87 |
* |
| 88 |
* @return void |
| 89 |
*/ |
| 90 |
public function down() { |
| 91 |
$this->drop_table( $this->get_table_name() ); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Retrieves the table name to use. |
| 96 |
* |
| 97 |
* @return string Table name to use. |
| 98 |
*/ |
| 99 |
protected function get_table_name() { |
| 100 |
return Model::get_table_name( 'Primary_Term' ); |
| 101 |
} |
| 102 |
} |
| 103 |
|