Просмотр файла database/upgrades/20180420150713_edit_fields_in_posts.php

Размер файла: 878B
  1. <?php
  2.  
  3. use Phinx\Migration\AbstractMigration;
  4.  
  5. class EditFieldsInPosts extends AbstractMigration
  6. {
  7. /**
  8. * Migrate Up.
  9. */
  10. public function up()
  11. {
  12. $rows = $this->fetchAll('SELECT * FROM posts');
  13.  
  14. foreach($rows as $row) {
  15. if (empty($row['created_at'])) {
  16. $this->execute('UPDATE posts SET created_at="'.SITETIME.'" WHERE id="'.$row['id'].'" LIMIT 1;');
  17. }
  18. }
  19.  
  20. $table = $this->table('posts');
  21. $table
  22. ->changeColumn('topic_id', 'integer')
  23. ->changeColumn('rating', 'integer', ['default' => 0])
  24. ->changeColumn('created_at', 'integer')
  25. ->save();
  26.  
  27. $table
  28. ->removeIndex('user_id')
  29. ->addIndex('user_id')
  30. ->save();
  31. }
  32.  
  33. /**
  34. * Migrate Down.
  35. */
  36. public function down()
  37. {
  38.  
  39. }
  40. }