2020 * Generates migration file based on the existing database table and previous migrations.
2121 *
2222 * @author Paweł Bizley Brzozowski
23- * @version 2.3.3
23+ * @version 2.3.4
2424 * @license Apache 2.0
2525 * https://github.com/bizley/yii2-migration
2626 */
2727class MigrationController extends Controller
2828{
29- protected $ version = '2.3.3 ' ;
29+ protected $ version = '2.3.4 ' ;
3030
3131 /**
3232 * @var string Default command action.
@@ -115,6 +115,27 @@ class MigrationController extends Controller
115115 */
116116 public $ skipMigrations = [];
117117
118+ /**
119+ * @var string|null String rendered in the create migration template to initialize table options.
120+ * By default it adds variable "$tableOptions" with optional collate configuration for MySQL DBMS to be used with
121+ * default $tableOptions.
122+ * Alias -O
123+ * @since 2.3.4
124+ */
125+ public $ tableOptionsInit = '$tableOptions = null;
126+ if ($this->db->driverName === \'mysql \') {
127+ $tableOptions = \'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB \';
128+ } ' ;
129+
130+ /**
131+ * @var string|null String rendered in the create migration template for table options.
132+ * By default it renders "$tableOptions" to indicate that options should be taken from variable
133+ * set in $tableOptionsInit property.
134+ * Alias -o
135+ * @since 2.3.4
136+ */
137+ public $ tableOptions = '$tableOptions ' ;
138+
118139 /**
119140 * @inheritdoc
120141 */
@@ -126,7 +147,7 @@ public function options($actionID)
126147 switch ($ actionID ) {
127148 case 'create ' :
128149 case 'create-all ' :
129- return array_merge ($ options , $ createOptions );
150+ return array_merge ($ options , $ createOptions, [ ' tableOptionsInit ' , ' tableOptions ' ] );
130151 case 'update ' :
131152 case 'update-all ' :
132153 return array_merge ($ options , $ createOptions , $ updateOptions );
@@ -150,6 +171,8 @@ public function optionAliases()
150171 'P ' => 'useTablePrefix ' ,
151172 'h ' => 'fixHistory ' ,
152173 's ' => 'showOnly ' ,
174+ 'O ' => 'tableOptionsInit ' ,
175+ 'o ' => 'tableOptions ' ,
153176 ]);
154177 }
155178
@@ -331,6 +354,8 @@ public function actionCreate($table)
331354 'className ' => $ className ,
332355 'namespace ' => $ this ->migrationNamespace ,
333356 'generalSchema ' => $ this ->generalSchema ,
357+ 'tableOptionsInit ' => $ this ->tableOptionsInit ,
358+ 'tableOptions ' => $ this ->tableOptions ,
334359 ]);
335360
336361 if ($ generator ->tableSchema === null ) {
0 commit comments