@@ -713,11 +713,11 @@ public function test58DeleteLast4Col()
713
713
{
714
714
$ columns = [
715
715
'id ' => 'pk ' ,
716
- 'name ' => 'text null ' ,
717
- 'description ' => 'text null ' ,
718
- 'colour ' => 'text null ' ,
719
- 'size ' => 'text null ' ,
720
- 'col_6 ' => 'text null ' ,
716
+ 'name ' => 'bool null ' ,
717
+ 'description ' => 'bool null ' ,
718
+ 'colour ' => 'bool null ' ,
719
+ 'size ' => 'bool null ' ,
720
+ 'col_6 ' => 'bool null ' ,
721
721
];
722
722
723
723
$ schema = <<<YAML
@@ -733,7 +733,7 @@ public function test58DeleteLast4Col()
733
733
id:
734
734
type: integer
735
735
name:
736
- type: string
736
+ type: boolean
737
737
paths:
738
738
'/':
739
739
get:
@@ -760,16 +760,79 @@ public function up()
760
760
761
761
public function down()
762
762
{
763
- $this->addColumn('{{%fruits}}', 'description', $this->text( )->null());
764
- $this->addColumn('{{%fruits}}', 'colour', $this->text( )->null()->after('description'));
765
- $this->addColumn('{{%fruits}}', 'size', $this->text( )->null()->after('colour'));
766
- $this->addColumn('{{%fruits}}', 'col_6', $this->text( )->null());
763
+ $this->addColumn('{{%fruits}}', 'description', $this->tinyInteger(1 )->null()->defaultValue(null ));
764
+ $this->addColumn('{{%fruits}}', 'colour', $this->tinyInteger(1 )->null()->defaultValue(null )->after('description'));
765
+ $this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1 )->null()->defaultValue(null )->after('colour'));
766
+ $this->addColumn('{{%fruits}}', 'col_6', $this->tinyInteger(1 )->null()->defaultValue(null ));
767
767
}
768
768
}
769
769
770
770
PHP;
771
771
772
- $ this ->for58 ($ schema , $ expected , $ columns , ['Mysql ' ]);
772
+ $ this ->for58 ($ schema , $ expected , $ columns/*, ['Mysql']*/ );
773
+ }
774
+
775
+ public function test58DeleteFirst4Col ()
776
+ {
777
+ $ columns = [
778
+ 'name ' => 'boolean null ' ,
779
+ 'description ' => 'boolean null ' ,
780
+ 'colour ' => 'boolean null ' ,
781
+ 'size ' => 'boolean null ' ,
782
+ 'col_6 ' => 'boolean null ' ,
783
+ 'col_7 ' => 'boolean null ' ,
784
+ ];
785
+
786
+ $ schema = <<<YAML
787
+ openapi: 3.0.3
788
+ info:
789
+ title: 'test58MoveColumns'
790
+ version: 1.0.0
791
+ components:
792
+ schemas:
793
+ Fruit:
794
+ type: object
795
+ properties:
796
+ col_6:
797
+ type: boolean
798
+ col_7:
799
+ type: boolean
800
+ paths:
801
+ '/':
802
+ get:
803
+ responses:
804
+ '200':
805
+ description: OK
806
+ YAML ;
807
+
808
+ $ expected = <<<'PHP'
809
+ <?php
810
+
811
+ /**
812
+ * Table for Fruit
813
+ */
814
+ class m200000_000000_change_table_fruits extends \yii\db\Migration
815
+ {
816
+ public function up()
817
+ {
818
+ $this->dropColumn('{{%fruits}}', 'size');
819
+ $this->dropColumn('{{%fruits}}', 'colour');
820
+ $this->dropColumn('{{%fruits}}', 'description');
821
+ $this->dropColumn('{{%fruits}}', 'name');
822
+ }
823
+
824
+ public function down()
825
+ {
826
+ $this->addColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->first());
827
+ $this->addColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
828
+ $this->addColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
829
+ $this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
830
+ }
831
+ }
832
+
833
+ PHP;
834
+
835
+ $ this ->for58 ($ schema , $ expected , $ columns/*, ['Mysql']*/ );
773
836
}
774
837
775
838
// ------------ Add
@@ -1099,10 +1162,10 @@ public function test58MoveLast2Col2PosUp()
1099
1162
{
1100
1163
$ columns = [
1101
1164
'id ' => 'pk ' ,
1102
- 'name ' => 'text null ' ,
1103
- 'description ' => 'text null ' ,
1104
- 'colour ' => 'text null ' ,
1105
- 'size ' => 'text null ' ,
1165
+ 'name ' => 'bool null ' ,
1166
+ 'description ' => 'bool null ' ,
1167
+ 'colour ' => 'bool null ' ,
1168
+ 'size ' => 'bool null ' ,
1106
1169
];
1107
1170
1108
1171
$ schema = <<<YAML
@@ -1118,13 +1181,13 @@ public function test58MoveLast2Col2PosUp()
1118
1181
id:
1119
1182
type: integer
1120
1183
colour:
1121
- type: string
1184
+ type: boolean
1122
1185
size:
1123
- type: string
1186
+ type: boolean
1124
1187
name:
1125
- type: string
1188
+ type: boolean
1126
1189
description:
1127
- type: string
1190
+ type: boolean
1128
1191
paths:
1129
1192
'/':
1130
1193
get:
@@ -1143,31 +1206,31 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
1143
1206
{
1144
1207
public function up()
1145
1208
{
1146
- $this->alterColumn('{{%fruits}}', 'colour', $this->text( )->null()->after('id'));
1147
- $this->alterColumn('{{%fruits}}', 'size', $this->text( )->null()->after('colour'));
1209
+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1 )->null()->defaultValue(null )->after('id'));
1210
+ $this->alterColumn('{{%fruits}}', 'size', $this->tinyInteger(1 )->null()->defaultValue(null )->after('colour'));
1148
1211
}
1149
1212
1150
1213
public function down()
1151
1214
{
1152
- $this->alterColumn('{{%fruits}}', 'size', $this->text( )->null()->after('colour'));
1153
- $this->alterColumn('{{%fruits}}', 'colour', $this->text( )->null()->after('description'));
1215
+ $this->alterColumn('{{%fruits}}', 'size', $this->tinyInteger(1 )->null()->defaultValue(null )->after('colour'));
1216
+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1 )->null()->defaultValue(null )->after('description'));
1154
1217
}
1155
1218
}
1156
1219
1157
1220
PHP;
1158
1221
1159
- $ this ->for58 ($ schema , $ expected , $ columns , ['Mysql ' ]);
1222
+ $ this ->for58 ($ schema , $ expected , $ columns/* , ['Mysql']*/ );
1160
1223
}
1161
1224
1162
- // -----------
1225
+ // ----------- Miscellaneous
1163
1226
public function test58Move1Add1Del1Col ()
1164
1227
{
1165
1228
$ columns = [
1166
1229
'id ' => 'pk ' ,
1167
- 'name ' => 'text null ' ,
1168
- 'description ' => 'text null ' ,
1169
- 'colour ' => 'text null ' ,
1170
- 'size ' => 'text null ' ,
1230
+ 'name ' => 'boolean null ' ,
1231
+ 'description ' => 'boolean null ' ,
1232
+ 'colour ' => 'boolean null ' ,
1233
+ 'size ' => 'boolean null ' ,
1171
1234
];
1172
1235
1173
1236
$ schema = <<<YAML
@@ -1183,13 +1246,13 @@ public function test58Move1Add1Del1Col()
1183
1246
id:
1184
1247
type: integer
1185
1248
colour:
1186
- type: string
1249
+ type: boolean
1187
1250
name:
1188
- type: string
1251
+ type: boolean
1189
1252
description:
1190
- type: string
1253
+ type: boolean
1191
1254
col_6:
1192
- type: string
1255
+ type: boolean
1193
1256
paths:
1194
1257
'/':
1195
1258
get:
@@ -1208,28 +1271,93 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
1208
1271
{
1209
1272
public function up()
1210
1273
{
1211
- $this->addColumn('{{%fruits}}', 'col_6', $this->text ()->null());
1274
+ $this->addColumn('{{%fruits}}', 'col_6', $this->boolean ()->null()->defaultValue(null ));
1212
1275
$this->dropColumn('{{%fruits}}', 'size');
1213
- $this->alterColumn('{{%fruits}}', 'colour', $this->text( )->null()->after('id'));
1214
- $this->alterColumn('{{%fruits}}', 'name', $this->text( )->null()->after('colour'));
1215
- $this->alterColumn('{{%fruits}}', 'description', $this->text( )->null()->after('name'));
1276
+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1 )->null()->defaultValue(null )->after('id'));
1277
+ $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1 )->null()->defaultValue(null )->after('colour'));
1278
+ $this->alterColumn('{{%fruits}}', 'description', $this->tinyInteger(1 )->null()->defaultValue(null )->after('name'));
1216
1279
}
1217
1280
1218
1281
public function down()
1219
1282
{
1220
- $this->alterColumn('{{%fruits}}', 'description', $this->text( )->null()->after('name'));
1221
- $this->alterColumn('{{%fruits}}', 'name', $this->text( )->null()->after('id'));
1222
- $this->alterColumn('{{%fruits}}', 'colour', $this->text( )->null()->after('description'));
1223
- $this->addColumn('{{%fruits}}', 'size', $this->text( )->null());
1283
+ $this->alterColumn('{{%fruits}}', 'description', $this->tinyInteger(1 )->null()->defaultValue(null )->after('name'));
1284
+ $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1 )->null()->defaultValue(null )->after('id'));
1285
+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1 )->null()->defaultValue(null )->after('description'));
1286
+ $this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1 )->null()->defaultValue(null ));
1224
1287
$this->dropColumn('{{%fruits}}', 'col_6');
1225
1288
}
1226
1289
}
1227
1290
1228
1291
PHP;
1229
1292
1230
- $ this ->for58 ($ schema , $ expected , $ columns , ['Mysql ' ]);
1293
+ $ this ->for58 ($ schema , $ expected , $ columns/*, ['Mysql']*/ );
1294
+ }
1295
+
1296
+ public function test58Add1Del1ColAtSamePosition ()
1297
+ {
1298
+ $ columns = [
1299
+ 'id ' => 'pk ' ,
1300
+ 'name ' => 'bool null ' ,
1301
+ 'description ' => 'bool null ' ,
1302
+ 'colour ' => 'bool null ' ,
1303
+ 'size ' => 'bool null ' ,
1304
+ ];
1305
+
1306
+ $ schema = <<<YAML
1307
+ openapi: 3.0.3
1308
+ info:
1309
+ title: 'test58MoveColumns'
1310
+ version: 1.0.0
1311
+ components:
1312
+ schemas:
1313
+ Fruit:
1314
+ type: object
1315
+ properties:
1316
+ id:
1317
+ type: integer
1318
+ name:
1319
+ type: boolean
1320
+ description_new:
1321
+ type: boolean
1322
+ colour:
1323
+ type: boolean
1324
+ size:
1325
+ type: boolean
1326
+ paths:
1327
+ '/':
1328
+ get:
1329
+ responses:
1330
+ '200':
1331
+ description: OK
1332
+ YAML ;
1333
+
1334
+ $ expected = <<<'PHP'
1335
+ <?php
1336
+
1337
+ /**
1338
+ * Table for Fruit
1339
+ */
1340
+ class m200000_000000_change_table_fruits extends \yii\db\Migration
1341
+ {
1342
+ public function up()
1343
+ {
1344
+ $this->addColumn('{{%fruits}}', 'description_new', $this->boolean()->null()->defaultValue(null)->after('name'));
1345
+ $this->dropColumn('{{%fruits}}', 'description');
1346
+ }
1347
+
1348
+ public function down()
1349
+ {
1350
+ $this->addColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
1351
+ $this->dropColumn('{{%fruits}}', 'description_new');
1352
+ }
1353
+ }
1354
+
1355
+ PHP;
1356
+
1357
+ $ this ->for58 ($ schema , $ expected , $ columns );
1231
1358
}
1232
1359
1233
- // add 1 and del 1 col at same position
1360
+ // TODO add tests cases:
1234
1361
// add 1 and del 1 col at different position
1362
+ // add 2 and del 1 col at different positions
1235
1363
}
0 commit comments