createTableMigration.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 $tableComment string the comment table */
  11. /* @var $fields array the fields */
  12. /* @var $foreignKeys array the foreign keys */
  13. echo "<?php\n";
  14. if (!empty($namespace)) {
  15. echo "\nnamespace {$namespace};\n";
  16. }
  17. ?>
  18. use yii\db\Migration;
  19. /**
  20. * Handles the creation of 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('_createTable', [
  33. 'table' => $table,
  34. 'fields' => $fields,
  35. 'foreignKeys' => $foreignKeys,
  36. ])
  37. ?>
  38. <?php if (!empty($tableComment)) {
  39. echo $this->render('_addComments', [
  40. 'table' => $table,
  41. 'tableComment' => $tableComment,
  42. ]);
  43. }
  44. ?>
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function safeDown()
  50. {
  51. <?= $this->render('_dropTable', [
  52. 'table' => $table,
  53. 'foreignKeys' => $foreignKeys,
  54. ])
  55. ?>
  56. }
  57. }