addColumnMigration.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. preg_match('/^add_(.+)_columns?_to_(.+)_table$/', $name, $matches);
  12. $columns = $matches[1];
  13. echo "<?php\n";
  14. if (!empty($namespace)) {
  15. echo "\nnamespace {$namespace};\n";
  16. }
  17. ?>
  18. use yii\db\Migration;
  19. /**
  20. * Handles adding <?= $columns ?> to table `<?= $table ?>`.
  21. <?= $this->render('_foreignTables', [
  22. 'foreignKeys' => $foreignKeys,
  23. ]) ?>
  24. */
  25. class <?= $className ?> extends Migration
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function safeUp()
  31. {
  32. <?= $this->render('_addColumns', [
  33. 'table' => $table,
  34. 'fields' => $fields,
  35. 'foreignKeys' => $foreignKeys,
  36. ])
  37. ?>
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function safeDown()
  43. {
  44. <?= $this->render('_dropColumns', [
  45. 'table' => $table,
  46. 'fields' => $fields,
  47. 'foreignKeys' => $foreignKeys,
  48. ])
  49. ?>
  50. }
  51. }