addColumnMigration.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * This view is used by console/controllers/MigrateController.php.
  4. *
  5. * The following variables are available in this view:
  6. */
  7. /* @var $className string the new migration class name without namespace */
  8. /* @var $namespace string the new migration class namespace */
  9. /* @var $table string the name table */
  10. /* @var $fields array the fields */
  11. echo "<?php\n";
  12. if (!empty($namespace)) {
  13. echo "\nnamespace {$namespace};\n";
  14. }
  15. ?>
  16. use yii\db\Migration;
  17. /**
  18. * Handles adding columns to table `<?= $table ?>`.
  19. <?= $this->render('_foreignTables', [
  20. 'foreignKeys' => $foreignKeys,
  21. ]) ?>
  22. */
  23. class <?= $className ?> extends Migration
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function safeUp()
  29. {
  30. <?= $this->render('_addColumns', [
  31. 'table' => $table,
  32. 'fields' => $fields,
  33. 'foreignKeys' => $foreignKeys,
  34. ])
  35. ?>
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function safeDown()
  41. {
  42. <?= $this->render('_dropColumns', [
  43. 'table' => $table,
  44. 'fields' => $fields,
  45. 'foreignKeys' => $foreignKeys,
  46. ])
  47. ?>
  48. }
  49. }