2020 * Generates migration file based on the existing database table and previous migrations.
2121 *
2222 * @author Paweł Bizley Brzozowski
23- * @version 3.0.3
23+ * @version 3.0.4
2424 * @license Apache 2.0
2525 * https://github.com/bizley/yii2-migration
2626 */
@@ -29,7 +29,7 @@ class MigrationController extends Controller
2929 /**
3030 * @var string
3131 */
32- protected $ version = '3.0.3 ' ;
32+ protected $ version = '3.0.4 ' ;
3333
3434 /**
3535 * @var string Default command action.
@@ -118,6 +118,27 @@ class MigrationController extends Controller
118118 */
119119 public $ skipMigrations = [];
120120
121+ /**
122+ * @var string|null String rendered in the create migration template to initialize table options.
123+ * By default it adds variable "$tableOptions" with optional collate configuration for MySQL DBMS to be used with
124+ * default $tableOptions.
125+ * Alias -O
126+ * @since 3.0.4
127+ */
128+ public $ tableOptionsInit = '$tableOptions = null;
129+ if ($this->db->driverName === \'mysql \') {
130+ $tableOptions = \'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB \';
131+ } ' ;
132+
133+ /**
134+ * @var string|null String rendered in the create migration template for table options.
135+ * By default it renders "$tableOptions" to indicate that options should be taken from variable
136+ * set in $tableOptionsInit property.
137+ * Alias -o
138+ * @since 3.0.4
139+ */
140+ public $ tableOptions = '$tableOptions ' ;
141+
121142 /**
122143 * @inheritdoc
123144 */
@@ -129,7 +150,7 @@ public function options($actionID): array // BC declaration
129150 switch ($ actionID ) {
130151 case 'create ' :
131152 case 'create-all ' :
132- return array_merge ($ options , $ createOptions );
153+ return array_merge ($ options , $ createOptions, [ ' tableOptionsInit ' , ' tableOptions ' ] );
133154 case 'update ' :
134155 case 'update-all ' :
135156 return array_merge ($ options , $ createOptions , $ updateOptions );
@@ -153,6 +174,8 @@ public function optionAliases(): array
153174 'P ' => 'useTablePrefix ' ,
154175 'h ' => 'fixHistory ' ,
155176 's ' => 'showOnly ' ,
177+ 'O ' => 'tableOptionsInit ' ,
178+ 'o ' => 'tableOptions ' ,
156179 ]);
157180 }
158181
@@ -332,6 +355,8 @@ public function actionCreate(string $table): int
332355 'className ' => $ className ,
333356 'namespace ' => $ this ->migrationNamespace ,
334357 'generalSchema ' => $ this ->generalSchema ,
358+ 'tableOptionsInit ' => $ this ->tableOptionsInit ,
359+ 'tableOptions ' => $ this ->tableOptions ,
335360 ]);
336361
337362 if ($ generator ->tableSchema === null ) {
0 commit comments