Skip to content

Commit 9abf721

Browse files
author
Bizley
authored
Merge pull request #164 from bizley/4.3.1
4.3.1
2 parents e6448c6 + 126d988 commit 9abf721

File tree

12 files changed

+203
-123
lines changed

12 files changed

+203
-123
lines changed

src/renderers/BlueprintRenderer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public function renderUp(
6161

6262
$renderedBlueprint = array_filter(
6363
[
64+
$this->renderIndexesToDrop($blueprint, $tableName, $indent),
6465
$this->renderPrimaryKeyToDrop($blueprint, $tableName, $indent, $schema),
65-
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema),
66+
$this->renderForeignKeysToDrop($blueprint, $tableName, $indent, $schema),
6667
$this->renderColumnsToDrop($blueprint, $tableName, $indent),
68+
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema),
6769
$this->renderColumnsToAdd($blueprint, $tableName, $indent, $schema, $engineVersion),
6870
$this->renderColumnsToAlter($blueprint, $tableName, $indent, $schema, $engineVersion),
69-
$this->renderForeignKeysToDrop($blueprint, $tableName, $indent, $schema),
7071
$this->renderForeignKeysToAdd($blueprint, $tableName, $indent, $schema, $usePrefix, $dbPrefix),
71-
$this->renderIndexesToDrop($blueprint, $tableName, $indent),
7272
$this->renderIndexesToAdd($blueprint, $tableName, $indent),
7373
]
7474
);
@@ -99,15 +99,15 @@ public function renderDown(
9999

100100
$renderedBlueprint = array_filter(
101101
[
102-
$this->renderPrimaryKeyToDrop($blueprint, $tableName, $indent, $schema, true),
103-
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema, true),
104102
$this->renderIndexesToDrop($blueprint, $tableName, $indent, true),
105-
$this->renderIndexesToAdd($blueprint, $tableName, $indent, true),
103+
$this->renderPrimaryKeyToDrop($blueprint, $tableName, $indent, $schema, true),
106104
$this->renderForeignKeysToDrop($blueprint, $tableName, $indent, $schema, true),
107-
$this->renderForeignKeysToAdd($blueprint, $tableName, $indent, $schema, $usePrefix, $dbPrefix, true),
108-
$this->renderColumnsToAlter($blueprint, $tableName, $indent, $schema, $engineVersion, true),
109105
$this->renderColumnsToDrop($blueprint, $tableName, $indent, true),
106+
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema, true),
110107
$this->renderColumnsToAdd($blueprint, $tableName, $indent, $schema, $engineVersion, true),
108+
$this->renderColumnsToAlter($blueprint, $tableName, $indent, $schema, $engineVersion, true),
109+
$this->renderIndexesToAdd($blueprint, $tableName, $indent, true),
110+
$this->renderForeignKeysToAdd($blueprint, $tableName, $indent, $schema, $usePrefix, $dbPrefix, true),
111111
]
112112
);
113113

src/views/migration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
class <?= $className ?> extends Migration
2525
{
26-
public function up()
26+
public function safeUp()
2727
{
2828
<?= $bodyUp ?>
2929

3030
}
3131

32-
public function down()
32+
public function safeDown()
3333
{
3434
<?= $bodyDown ?>
3535

tests/functional/GeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function shouldGenerateGeneralSchemaTableWithCommonColumns(): void
8686
self::assertStringContainsString(
8787
'_create_table_gs_columns extends Migration
8888
{
89-
public function up()
89+
public function safeUp()
9090
{
9191
$tableOptions = null;
9292
if ($this->db->driverName === \'mysql\') {
@@ -115,7 +115,7 @@ public function up()
115115
);
116116
}
117117
118-
public function down()
118+
public function safeDown()
119119
{
120120
$this->dropTable(\'{{%gs_columns}}\');
121121
}

tests/functional/UpdaterTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public function shouldUpdateTableByAddingColumn(): void
7979
MigrationControllerStub::$stdout
8080
);
8181
self::assertStringContainsString(
82-
'public function up()
82+
'public function safeUp()
8383
{
8484
$this->addColumn(\'{{%updater_base}}\', \'added\', $this->integer()->after(\'col3\'));
8585
}
8686
87-
public function down()
87+
public function safeDown()
8888
{
8989
$this->dropColumn(\'{{%updater_base}}\', \'added\');
9090
}',
@@ -101,12 +101,12 @@ public function shouldUpdateTableByAddingIndex(): void
101101

102102
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
103103
self::assertStringContainsString(
104-
'public function up()
104+
'public function safeUp()
105105
{
106106
$this->createIndex(\'idx-add\', \'{{%updater_base}}\', [\'col\']);
107107
}
108108
109-
public function down()
109+
public function safeDown()
110110
{
111111
$this->dropIndex(\'idx-add\', \'{{%updater_base}}\');
112112
}',
@@ -123,12 +123,12 @@ public function shouldUpdateTableByAddingUniqueIndex(): void
123123

124124
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
125125
self::assertStringContainsString(
126-
'public function up()
126+
'public function safeUp()
127127
{
128128
$this->createIndex(\'idx-add-unique\', \'{{%updater_base}}\', [\'col\'], true);
129129
}
130130
131-
public function down()
131+
public function safeDown()
132132
{
133133
$this->dropIndex(\'idx-add-unique\', \'{{%updater_base}}\');
134134
}',
@@ -145,12 +145,12 @@ public function shouldUpdateTableByAddingMultiIndex(): void
145145

146146
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
147147
self::assertStringContainsString(
148-
'public function up()
148+
'public function safeUp()
149149
{
150150
$this->createIndex(\'idx-add-multi\', \'{{%updater_base}}\', [\'col\', \'col2\']);
151151
}
152152
153-
public function down()
153+
public function safeDown()
154154
{
155155
$this->dropIndex(\'idx-add-multi\', \'{{%updater_base}}\');
156156
}',
@@ -172,12 +172,12 @@ public function shouldUpdateTableByAddingMultiUniqueIndex(): void
172172

173173
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
174174
self::assertStringContainsString(
175-
'public function up()
175+
'public function safeUp()
176176
{
177177
$this->createIndex(\'idx-add-multi-unique\', \'{{%updater_base}}\', [\'col\', \'col2\'], true);
178178
}
179179
180-
public function down()
180+
public function safeDown()
181181
{
182182
$this->dropIndex(\'idx-add-multi-unique\', \'{{%updater_base}}\');
183183
}',
@@ -194,12 +194,12 @@ public function shouldUpdateTableByDroppingIndex(): void
194194

195195
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base_fk']));
196196
self::assertStringContainsString(
197-
'public function up()
197+
'public function safeUp()
198198
{
199199
$this->dropIndex(\'idx-col\', \'{{%updater_base_fk}}\');
200200
}
201201
202-
public function down()
202+
public function safeDown()
203203
{
204204
$this->createIndex(\'idx-col\', \'{{%updater_base_fk}}\', [\'col\']);
205205
}',

tests/functional/mysql/GeneratorTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public function shouldGenerateGeneralSchemaCrossReferredTables(): void
617617

618618
self::assertEquals(ExitCode::OK, $this->controller->runAction('create', ['table21,table22']));
619619
self::assertStringContainsString(
620-
'public function up()
620+
'public function safeUp()
621621
{
622622
$tableOptions = null;
623623
if ($this->db->driverName === \'mysql\') {
@@ -636,14 +636,14 @@ public function shouldGenerateGeneralSchemaCrossReferredTables(): void
636636
$this->createIndex(\'fk-table22\', \'{{%table22}}\', [\'fk2\']);
637637
}
638638
639-
public function down()
639+
public function safeDown()
640640
{
641641
$this->dropTable(\'{{%table22}}\');
642642
}',
643643
MigrationControllerStub::$content
644644
);
645645
self::assertStringContainsString(
646-
'public function up()
646+
'public function safeUp()
647647
{
648648
$tableOptions = null;
649649
if ($this->db->driverName === \'mysql\') {
@@ -670,14 +670,14 @@ public function down()
670670
);
671671
}
672672
673-
public function down()
673+
public function safeDown()
674674
{
675675
$this->dropTable(\'{{%table21}}\');
676676
}',
677677
MigrationControllerStub::$content
678678
);
679679
self::assertStringContainsString(
680-
'public function up()
680+
'public function safeUp()
681681
{
682682
$this->addForeignKey(
683683
\'fk-table22\',
@@ -690,7 +690,7 @@ public function down()
690690
);
691691
}
692692
693-
public function down()
693+
public function safeDown()
694694
{
695695
$this->dropForeignKey(\'fk-table22\', \'{{%table22}}\');
696696
}',
@@ -772,7 +772,7 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedPrimaryKey(): void
772772
self::assertEquals(ExitCode::OK, $this->controller->runAction('create', ['unsigned_pk']));
773773
self::assertStringContainsString(
774774
$this->isV8()
775-
? 'public function up()
775+
? 'public function safeUp()
776776
{
777777
$tableOptions = null;
778778
if ($this->db->driverName === \'mysql\') {
@@ -788,12 +788,12 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedPrimaryKey(): void
788788
);
789789
}
790790
791-
public function down()
791+
public function safeDown()
792792
{
793793
$this->dropTable(\'{{%unsigned_pk}}\');
794794
}
795795
}
796-
' : 'public function up()
796+
' : 'public function safeUp()
797797
{
798798
$tableOptions = null;
799799
if ($this->db->driverName === \'mysql\') {
@@ -809,7 +809,7 @@ public function down()
809809
);
810810
}
811811
812-
public function down()
812+
public function safeDown()
813813
{
814814
$this->dropTable(\'{{%unsigned_pk}}\');
815815
}
@@ -839,7 +839,7 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedBigPrimaryKey(): voi
839839

840840
self::assertEquals(ExitCode::OK, $this->controller->runAction('create', ['unsigned_big_pk']));
841841
self::assertStringContainsString(
842-
'public function up()
842+
'public function safeUp()
843843
{
844844
$tableOptions = null;
845845
if ($this->db->driverName === \'mysql\') {
@@ -855,7 +855,7 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedBigPrimaryKey(): voi
855855
);
856856
}
857857
858-
public function down()
858+
public function safeDown()
859859
{
860860
$this->dropTable(\'{{%unsigned_big_pk}}\');
861861
}

tests/functional/mysql/UpdaterPkTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public function shouldUpdateTableByAddingPrimaryKey(): void
3131

3232
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['no_pk']));
3333
self::assertStringContainsString(
34-
'public function up()
34+
'public function safeUp()
3535
{
3636
$this->alterColumn(\'{{%no_pk}}\', \'col\', $this->primaryKey());
3737
}
3838
39-
public function down()
39+
public function safeDown()
4040
{
4141
$this->alterColumn(\'{{%no_pk}}\', \'col\', $this->integer());
4242
}',
@@ -56,12 +56,12 @@ public function shouldUpdateTableByDroppingPrimaryKey(): void
5656

5757
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['string_pk']));
5858
self::assertStringContainsString(
59-
'public function up()
59+
'public function safeUp()
6060
{
6161
$this->alterColumn(\'{{%string_pk}}\', \'col\', $this->string()->notNull());
6262
}
6363
64-
public function down()
64+
public function safeDown()
6565
{
6666
$this->alterColumn(\'{{%string_pk}}\', \'col\', $this->string()->append(\'PRIMARY KEY\'));
6767
}',
@@ -81,15 +81,15 @@ public function shouldUpdateTableByAddingCompositePrimaryKey(): void
8181

8282
self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['no_pk']));
8383
self::assertStringContainsString(
84-
'public function up()
84+
'public function safeUp()
8585
{
8686
$this->addPrimaryKey(\'PRIMARYKEY\', \'{{%no_pk}}\', [\'col\', \'col2\']);
8787
8888
$this->alterColumn(\'{{%no_pk}}\', \'col\', $this->integer()->notNull());
8989
$this->alterColumn(\'{{%no_pk}}\', \'col2\', $this->integer()->notNull());
9090
}
9191
92-
public function down()
92+
public function safeDown()
9393
{
9494
$this->dropPrimaryKey(\'PRIMARYKEY\', \'{{%no_pk}}\');
9595

0 commit comments

Comments
 (0)