Advertisement
Sdelkadrom

Untitled

Jan 30th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2.  
  3. use Phinx\Migration\AbstractMigration;
  4. use Phinx\Db\Adapter\MysqlAdapter;
  5.  
  6. class AreasMigration extends AbstractMigration
  7. {
  8. public function up()
  9. {
  10.  
  11. $area = $this->table(
  12. 'location_area',
  13. [
  14. 'engine' => 'InnoDB'
  15. ]
  16. );
  17.  
  18. $city = $this->table('location_city');
  19. $apartment = $this->table('apartment');
  20.  
  21. $area->addColumn(
  22. 'country_id',
  23. 'integer',
  24. [
  25. 'signed' => false,
  26. 'null' => true,
  27. ]
  28. );
  29.  
  30. $area->addColumn(
  31. 'region_id',
  32. 'integer',
  33. [
  34. 'signed' => false,
  35. 'null' => true,
  36. ]
  37. );
  38.  
  39. $langs = ['ru', 'en', 'de', 'es', 'ar'];
  40. foreach ($langs as $lang) {
  41. $area->addColumn(
  42. 'name_'.$lang,
  43. 'string',
  44. [
  45. 'limit' => 128,
  46. 'null' => false,
  47. 'default' => ''
  48. ]
  49. );
  50. }
  51.  
  52. $area->save();
  53.  
  54. $city->addColumn(
  55. 'area_id',
  56. 'integer',
  57. [
  58. 'null' => true,
  59. 'after' => 'region_id',
  60. 'signed' => false,
  61. ]
  62. );
  63.  
  64. $city->changeColumn(
  65. 'region_id',
  66. 'integer',
  67. [
  68. 'signed' => false,
  69. 'null' => true,
  70. ]
  71. );
  72.  
  73. $city->save();
  74.  
  75. $apartment->addColumn(
  76. 'loc_area',
  77. 'integer',
  78. [
  79. 'null' => true,
  80. 'after' => 'loc_region',
  81. 'signed' => false,
  82. ]
  83. );
  84.  
  85. $apartment->save();
  86. }
  87.  
  88. public function down()
  89. {
  90. $this->table('location_area')->drop()->save();
  91. $this->table('location_city')->removeColumn('area_id')->save();
  92. $this->table('apartment')->removeColumn('loc_area')->save();
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement