@@ -1273,14 +1273,10 @@ public function up()
12731273 $this->addColumn('{{%fruits}}', 'col_6', $this->boolean()->null()->defaultValue(null));
12741274 $this->dropColumn('{{%fruits}}', 'size');
12751275 $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1276- $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
1277- $this->alterColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
12781276 }
12791277
12801278 public function down()
12811279 {
1282- $this->alterColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
1283- $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
12841280 $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
12851281 $this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null));
12861282 $this->dropColumn('{{%fruits}}', 'col_6');
@@ -1493,4 +1489,192 @@ public function down()
14931489//
14941490// $this->for58($schema, $expected, $columns);
14951491// }
1492+
1493+ public function test58MoveAColAndChangeItsDataType ()
1494+ {
1495+ $ columns = [
1496+ 'id ' => 'pk ' ,
1497+ 'name ' => 'bool null ' ,
1498+ 'description ' => 'bool null ' ,
1499+ 'colour ' => 'bool null ' ,
1500+ 'size ' => 'bool null ' ,
1501+ ];
1502+
1503+ $ schema = <<<YAML
1504+ openapi: 3.0.3
1505+ info:
1506+ title: 'test58MoveColumns'
1507+ version: 1.0.0
1508+ components:
1509+ schemas:
1510+ Fruit:
1511+ type: object
1512+ properties:
1513+ id:
1514+ type: integer
1515+ description:
1516+ type: boolean
1517+ colour:
1518+ type: integer
1519+ name:
1520+ type: boolean
1521+ size:
1522+ type: boolean
1523+ paths:
1524+ '/':
1525+ get:
1526+ responses:
1527+ '200':
1528+ description: OK
1529+ YAML ;
1530+
1531+ $ expected = <<<'PHP'
1532+ <?php
1533+
1534+ /**
1535+ * Table for Fruit
1536+ */
1537+ class m200000_000000_change_table_fruits extends \yii\db\Migration
1538+ {
1539+ public function up()
1540+ {
1541+ $this->alterColumn('{{%fruits}}', 'colour', $this->integer()->null()->defaultValue(null));
1542+ $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
1543+ }
1544+
1545+ public function down()
1546+ {
1547+ $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1548+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null));
1549+ }
1550+ }
1551+
1552+ PHP;
1553+
1554+ $ this ->for58 ($ schema , $ expected , $ columns );
1555+ }
1556+
1557+ public function test58MoveAColDownwards ()
1558+ {
1559+ $ columns = [
1560+ 'id ' => 'pk ' ,
1561+ 'name ' => 'bool null ' ,
1562+ 'description ' => 'bool null ' ,
1563+ 'colour ' => 'bool null ' ,
1564+ 'size ' => 'bool null ' ,
1565+ ];
1566+
1567+ $ schema = <<<YAML
1568+ openapi: 3.0.3
1569+ info:
1570+ title: 'test58MoveColumns'
1571+ version: 1.0.0
1572+ components:
1573+ schemas:
1574+ Fruit:
1575+ type: object
1576+ properties:
1577+ id:
1578+ type: integer
1579+ description:
1580+ type: boolean
1581+ colour:
1582+ type: boolean
1583+ name:
1584+ type: boolean
1585+ size:
1586+ type: boolean
1587+ paths:
1588+ '/':
1589+ get:
1590+ responses:
1591+ '200':
1592+ description: OK
1593+ YAML ;
1594+
1595+ $ expected = <<<'PHP'
1596+ <?php
1597+
1598+ /**
1599+ * Table for Fruit
1600+ */
1601+ class m200000_000000_change_table_fruits extends \yii\db\Migration
1602+ {
1603+ public function up()
1604+ {
1605+ $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
1606+ }
1607+
1608+ public function down()
1609+ {
1610+ $this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1611+ }
1612+ }
1613+
1614+ PHP;
1615+
1616+ $ this ->for58 ($ schema , $ expected , $ columns );
1617+ }
1618+
1619+ public function test58MoveAColUpwards ()
1620+ {
1621+ $ columns = [
1622+ 'id ' => 'pk ' ,
1623+ 'name ' => 'bool null ' ,
1624+ 'description ' => 'bool null ' ,
1625+ 'colour ' => 'bool null ' ,
1626+ 'size ' => 'bool null ' ,
1627+ ];
1628+
1629+ $ schema = <<<YAML
1630+ openapi: 3.0.3
1631+ info:
1632+ title: 'test58MoveColumns'
1633+ version: 1.0.0
1634+ components:
1635+ schemas:
1636+ Fruit:
1637+ type: object
1638+ properties:
1639+ id:
1640+ type: integer
1641+ colour:
1642+ type: boolean
1643+ name:
1644+ type: boolean
1645+ description:
1646+ type: boolean
1647+ size:
1648+ type: boolean
1649+ paths:
1650+ '/':
1651+ get:
1652+ responses:
1653+ '200':
1654+ description: OK
1655+ YAML ;
1656+
1657+ $ expected = <<<'PHP'
1658+ <?php
1659+
1660+ /**
1661+ * Table for Fruit
1662+ */
1663+ class m200000_000000_change_table_fruits extends \yii\db\Migration
1664+ {
1665+ public function up()
1666+ {
1667+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1668+ }
1669+
1670+ public function down()
1671+ {
1672+ $this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
1673+ }
1674+ }
1675+
1676+ PHP;
1677+
1678+ $ this ->for58 ($ schema , $ expected , $ columns );
1679+ }
14961680}
0 commit comments