20171228151841_WpYoastPrimaryTerm.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Yoast SEO Plugin File.
  4. *
  5. * @package WPSEO\Migrations
  6. */
  7. use Yoast\WP\Free\ORM\Yoast_Model;
  8. use YoastSEO_Vendor\Ruckusing_Migration_Base;
  9. /**
  10. * Migration for the Primary Term.
  11. */
  12. class WpYoastPrimaryTerm extends Ruckusing_Migration_Base {
  13. /**
  14. * Migration up.
  15. *
  16. * @return void
  17. */
  18. public function up() {
  19. $table_name = $this->get_table_name();
  20. $indexable_table = $this->create_table( $table_name );
  21. $indexable_table->column(
  22. 'post_id',
  23. 'integer',
  24. [
  25. 'unsigned' => true,
  26. 'null' => false,
  27. 'limit' => 11,
  28. ]
  29. );
  30. $indexable_table->column(
  31. 'term_id',
  32. 'integer',
  33. [
  34. 'unsigned' => true,
  35. 'null' => false,
  36. 'limit' => 11,
  37. ]
  38. );
  39. $indexable_table->column(
  40. 'taxonomy',
  41. 'string',
  42. [
  43. 'null' => false,
  44. 'limit' => 191,
  45. ]
  46. );
  47. // Executes the SQL to create the table.
  48. $indexable_table->finish();
  49. $this->add_index(
  50. $table_name,
  51. [
  52. 'post_id',
  53. 'taxonomy',
  54. ],
  55. [
  56. 'name' => 'post_taxonomy',
  57. ]
  58. );
  59. $this->add_index(
  60. $table_name,
  61. [
  62. 'post_id',
  63. 'term_id',
  64. ],
  65. [
  66. 'name' => 'post_term',
  67. ]
  68. );
  69. $this->add_timestamps( $table_name );
  70. }
  71. /**
  72. * Migration down.
  73. */
  74. public function down() {
  75. $this->drop_table( $this->get_table_name() );
  76. }
  77. /**
  78. * Retrieves the table name to use.
  79. *
  80. * @return string Table name to use.
  81. */
  82. protected function get_table_name() {
  83. return Yoast_Model::get_table_name( 'Primary_Term' );
  84. }
  85. }