TestMigratioonController.php 932 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace console\controllers;
  3. use console\models\MigrationDb;
  4. use Yii;
  5. use yii\console\Controller;
  6. class TestMigratioonController extends Controller
  7. {
  8. public function actionMigrationdb()
  9. {
  10. $Migrate = new MigrationDb();
  11. // 获取迁移目录路径 console/migrations/
  12. $dirName = Yii::getAlias('@console') . '/migrations';
  13. // 先删除该路径下已生成的所有文件
  14. $Migrate->deleteFile($dirName);
  15. // 获取所有表名 开始循环获取表字段信息,创建迁移
  16. $db = Yii::$app->getDb();
  17. $tablesName = $db->getSchema()->getTableNames();
  18. foreach($tablesName as $key => $value) {
  19. $tablesInfo = $db->getSchema()->getTableSchema($value);
  20. echo "php yii migrate/create create_".$value;
  21. exit;
  22. exec("php yii migrate/create create_".$value, $info);
  23. exit;
  24. }
  25. }
  26. }