MigrationUtility.php 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace migration\models;
  3. use yii\base\Model;
  4. use yii\helpers\ArrayHelper;
  5. class MigrationUtility extends Model
  6. {
  7. public $migrationName = "migration";
  8. public $migrationPath;
  9. public $tableSchemas;
  10. public $tableDatas;
  11. /**
  12. * @var string
  13. */
  14. public $tableOption = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
  15. /**
  16. * @return array
  17. */
  18. function rules()
  19. {
  20. return [
  21. [["migrationName","migrationPath","tableSchemas","tableDatas","tableOption"],'safe']
  22. ];
  23. }
  24. public static function getTableNames()
  25. {
  26. $tables = \Yii::$app->db->getSchema()->getTableNames('', TRUE);
  27. $tables = array_combine($tables,$tables);
  28. // 移除migration表
  29. ArrayHelper::remove($tables, \Yii::$app->db->getSchema()->getRawTableName('{{%migration}}'));
  30. return $tables;
  31. }
  32. }