Skip to content

Commit

Permalink
Merge pull request #164 from bizley/4.3.1
Browse files Browse the repository at this point in the history
4.3.1
  • Loading branch information
Bizley authored Feb 20, 2022
2 parents e6448c6 + 126d988 commit 9abf721
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 123 deletions.
16 changes: 8 additions & 8 deletions src/renderers/BlueprintRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public function renderUp(

$renderedBlueprint = array_filter(
[
$this->renderIndexesToDrop($blueprint, $tableName, $indent),
$this->renderPrimaryKeyToDrop($blueprint, $tableName, $indent, $schema),
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema),
$this->renderForeignKeysToDrop($blueprint, $tableName, $indent, $schema),
$this->renderColumnsToDrop($blueprint, $tableName, $indent),
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema),
$this->renderColumnsToAdd($blueprint, $tableName, $indent, $schema, $engineVersion),
$this->renderColumnsToAlter($blueprint, $tableName, $indent, $schema, $engineVersion),
$this->renderForeignKeysToDrop($blueprint, $tableName, $indent, $schema),
$this->renderForeignKeysToAdd($blueprint, $tableName, $indent, $schema, $usePrefix, $dbPrefix),
$this->renderIndexesToDrop($blueprint, $tableName, $indent),
$this->renderIndexesToAdd($blueprint, $tableName, $indent),
]
);
Expand Down Expand Up @@ -99,15 +99,15 @@ public function renderDown(

$renderedBlueprint = array_filter(
[
$this->renderPrimaryKeyToDrop($blueprint, $tableName, $indent, $schema, true),
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema, true),
$this->renderIndexesToDrop($blueprint, $tableName, $indent, true),
$this->renderIndexesToAdd($blueprint, $tableName, $indent, true),
$this->renderPrimaryKeyToDrop($blueprint, $tableName, $indent, $schema, true),
$this->renderForeignKeysToDrop($blueprint, $tableName, $indent, $schema, true),
$this->renderForeignKeysToAdd($blueprint, $tableName, $indent, $schema, $usePrefix, $dbPrefix, true),
$this->renderColumnsToAlter($blueprint, $tableName, $indent, $schema, $engineVersion, true),
$this->renderColumnsToDrop($blueprint, $tableName, $indent, true),
$this->renderPrimaryKeyToAdd($blueprint, $tableName, $indent, $schema, true),
$this->renderColumnsToAdd($blueprint, $tableName, $indent, $schema, $engineVersion, true),
$this->renderColumnsToAlter($blueprint, $tableName, $indent, $schema, $engineVersion, true),
$this->renderIndexesToAdd($blueprint, $tableName, $indent, true),
$this->renderForeignKeysToAdd($blueprint, $tableName, $indent, $schema, $usePrefix, $dbPrefix, true),
]
);

Expand Down
4 changes: 2 additions & 2 deletions src/views/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

class <?= $className ?> extends Migration
{
public function up()
public function safeUp()
{
<?= $bodyUp ?>

}

public function down()
public function safeDown()
{
<?= $bodyDown ?>

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function shouldGenerateGeneralSchemaTableWithCommonColumns(): void
self::assertStringContainsString(
'_create_table_gs_columns extends Migration
{
public function up()
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === \'mysql\') {
Expand Down Expand Up @@ -115,7 +115,7 @@ public function up()
);
}
public function down()
public function safeDown()
{
$this->dropTable(\'{{%gs_columns}}\');
}
Expand Down
24 changes: 12 additions & 12 deletions tests/functional/UpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public function shouldUpdateTableByAddingColumn(): void
MigrationControllerStub::$stdout
);
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->addColumn(\'{{%updater_base}}\', \'added\', $this->integer()->after(\'col3\'));
}
public function down()
public function safeDown()
{
$this->dropColumn(\'{{%updater_base}}\', \'added\');
}',
Expand All @@ -101,12 +101,12 @@ public function shouldUpdateTableByAddingIndex(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->createIndex(\'idx-add\', \'{{%updater_base}}\', [\'col\']);
}
public function down()
public function safeDown()
{
$this->dropIndex(\'idx-add\', \'{{%updater_base}}\');
}',
Expand All @@ -123,12 +123,12 @@ public function shouldUpdateTableByAddingUniqueIndex(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->createIndex(\'idx-add-unique\', \'{{%updater_base}}\', [\'col\'], true);
}
public function down()
public function safeDown()
{
$this->dropIndex(\'idx-add-unique\', \'{{%updater_base}}\');
}',
Expand All @@ -145,12 +145,12 @@ public function shouldUpdateTableByAddingMultiIndex(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->createIndex(\'idx-add-multi\', \'{{%updater_base}}\', [\'col\', \'col2\']);
}
public function down()
public function safeDown()
{
$this->dropIndex(\'idx-add-multi\', \'{{%updater_base}}\');
}',
Expand All @@ -172,12 +172,12 @@ public function shouldUpdateTableByAddingMultiUniqueIndex(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->createIndex(\'idx-add-multi-unique\', \'{{%updater_base}}\', [\'col\', \'col2\'], true);
}
public function down()
public function safeDown()
{
$this->dropIndex(\'idx-add-multi-unique\', \'{{%updater_base}}\');
}',
Expand All @@ -194,12 +194,12 @@ public function shouldUpdateTableByDroppingIndex(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['updater_base_fk']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->dropIndex(\'idx-col\', \'{{%updater_base_fk}}\');
}
public function down()
public function safeDown()
{
$this->createIndex(\'idx-col\', \'{{%updater_base_fk}}\', [\'col\']);
}',
Expand Down
24 changes: 12 additions & 12 deletions tests/functional/mysql/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public function shouldGenerateGeneralSchemaCrossReferredTables(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('create', ['table21,table22']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === \'mysql\') {
Expand All @@ -636,14 +636,14 @@ public function shouldGenerateGeneralSchemaCrossReferredTables(): void
$this->createIndex(\'fk-table22\', \'{{%table22}}\', [\'fk2\']);
}
public function down()
public function safeDown()
{
$this->dropTable(\'{{%table22}}\');
}',
MigrationControllerStub::$content
);
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === \'mysql\') {
Expand All @@ -670,14 +670,14 @@ public function down()
);
}
public function down()
public function safeDown()
{
$this->dropTable(\'{{%table21}}\');
}',
MigrationControllerStub::$content
);
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->addForeignKey(
\'fk-table22\',
Expand All @@ -690,7 +690,7 @@ public function down()
);
}
public function down()
public function safeDown()
{
$this->dropForeignKey(\'fk-table22\', \'{{%table22}}\');
}',
Expand Down Expand Up @@ -772,7 +772,7 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedPrimaryKey(): void
self::assertEquals(ExitCode::OK, $this->controller->runAction('create', ['unsigned_pk']));
self::assertStringContainsString(
$this->isV8()
? 'public function up()
? 'public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === \'mysql\') {
Expand All @@ -788,12 +788,12 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedPrimaryKey(): void
);
}
public function down()
public function safeDown()
{
$this->dropTable(\'{{%unsigned_pk}}\');
}
}
' : 'public function up()
' : 'public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === \'mysql\') {
Expand All @@ -809,7 +809,7 @@ public function down()
);
}
public function down()
public function safeDown()
{
$this->dropTable(\'{{%unsigned_pk}}\');
}
Expand Down Expand Up @@ -839,7 +839,7 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedBigPrimaryKey(): voi

self::assertEquals(ExitCode::OK, $this->controller->runAction('create', ['unsigned_big_pk']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === \'mysql\') {
Expand All @@ -855,7 +855,7 @@ public function shouldGenerateGeneralSchemaTableWithUnsignedBigPrimaryKey(): voi
);
}
public function down()
public function safeDown()
{
$this->dropTable(\'{{%unsigned_big_pk}}\');
}
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/mysql/UpdaterPkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public function shouldUpdateTableByAddingPrimaryKey(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['no_pk']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->alterColumn(\'{{%no_pk}}\', \'col\', $this->primaryKey());
}
public function down()
public function safeDown()
{
$this->alterColumn(\'{{%no_pk}}\', \'col\', $this->integer());
}',
Expand All @@ -56,12 +56,12 @@ public function shouldUpdateTableByDroppingPrimaryKey(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['string_pk']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->alterColumn(\'{{%string_pk}}\', \'col\', $this->string()->notNull());
}
public function down()
public function safeDown()
{
$this->alterColumn(\'{{%string_pk}}\', \'col\', $this->string()->append(\'PRIMARY KEY\'));
}',
Expand All @@ -81,15 +81,15 @@ public function shouldUpdateTableByAddingCompositePrimaryKey(): void

self::assertEquals(ExitCode::OK, $this->controller->runAction('update', ['no_pk']));
self::assertStringContainsString(
'public function up()
'public function safeUp()
{
$this->addPrimaryKey(\'PRIMARYKEY\', \'{{%no_pk}}\', [\'col\', \'col2\']);
$this->alterColumn(\'{{%no_pk}}\', \'col\', $this->integer()->notNull());
$this->alterColumn(\'{{%no_pk}}\', \'col2\', $this->integer()->notNull());
}
public function down()
public function safeDown()
{
$this->dropPrimaryKey(\'PRIMARYKEY\', \'{{%no_pk}}\');
Expand Down
Loading

0 comments on commit 9abf721

Please sign in to comment.