| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace console\controllers;
- use console\models\MigrationDb;
- use Yii;
- use yii\console\Controller;
- class TestMigratioonController extends Controller
- {
- public function actionMigrationdb()
- {
- $Migrate = new MigrationDb();
- // 获取迁移目录路径 console/migrations/
- $dirName = Yii::getAlias('@console') . '/migrations';
- // 先删除该路径下已生成的所有文件
- $Migrate->deleteFile($dirName);
- // 获取所有表名 开始循环获取表字段信息,创建迁移
- $db = Yii::$app->getDb();
- $tablesName = $db->getSchema()->getTableNames();
- foreach($tablesName as $key => $value) {
- $tablesInfo = $db->getSchema()->getTableSchema($value);
- echo "php yii migrate/create create_".$value;
- exit;
- exec("php yii migrate/create create_".$value, $info);
- exit;
- }
- }
- }
|