Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x - Make diff tests run again #623

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/bake/config/diff.twig
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ not empty %}
}) | raw -}}
{% endif -%}
{% for tableName, tableDiff in data -%}
{% Migration.resetTableStatementGenerationFor(tableName) %}
{% do Migration.resetTableStatementGenerationFor(tableName) %}
{% if tableDiff['indexes']['add'] is not empty %}

$this->table('{{ tableName }}')
Expand Down
2 changes: 1 addition & 1 deletion templates/bake/element/add-foreign-keys.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set statement = Migration.tableStatement(table, true) %}
{% set hasProcessedConstraint = false %}
{% for constraintName, constraint in constraints[table] %}
{% for constraintName, constraint in constraints %}
{% set constraintColumns = constraint['columns']|sort %}
{% if constraint['type'] != 'unique' %}
{% set hasProcessedConstraint = true %}
Expand Down
2 changes: 1 addition & 1 deletion templates/bake/element/create-tables.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
{% if createData.constraints %}
{% for table, tableConstraints in createData.constraints %}
{{- element('Migrations.add-foreign-keys', {
constraints: createData.constraints,
constraints: tableConstraints,
table: table,
})
-}}
Expand Down
26 changes: 15 additions & 11 deletions tests/TestCase/Command/BakeMigrationDiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testEmptyHistoryNoMigrations()
*/
public function testBakingDiff()
{
$this->skipIf(env('DB_URL_COMPARE') !== false);
$this->skipIf(!env('DB_URL_COMPARE'));

$diffConfigFolder = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Diff' . DS;
$diffMigrationsPath = $diffConfigFolder . 'the_diff_' . env('DB') . '.php';
Expand All @@ -125,8 +125,9 @@ public function testBakingDiff()
unlink($destination);
copy($diffDumpPath, $destinationDumpPath);

/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get('test_comparisons');
$connection->newQuery()
$connection->deleteQuery()
->delete('phinxlog')
->where(['version' => 20160415220805])
->execute();
Expand All @@ -137,7 +138,7 @@ public function testBakingDiff()
'length' => 255,
]);
foreach ($table->createSql($connection) as $stmt) {
$connection->query($stmt);
$connection->execute($stmt);
}

$this->_compareBasePath = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Diff' . DS;
Expand All @@ -155,7 +156,7 @@ public function testBakingDiff()
rename($destinationConfigDir . $generatedMigration, $destination);
$versionParts = explode('_', $generatedMigration);

$connection->newQuery()
$connection->insertQuery()
->insert(['version', 'migration_name', 'start_time', 'end_time'])
->into('phinxlog')
->values([
Expand All @@ -165,10 +166,11 @@ public function testBakingDiff()
'end_time' => '2016-05-22 16:51:46',
])
->execute();

$this->getMigrations()->rollback(['target' => 'all']);

foreach ($table->dropSql($connection) as $stmt) {
$connection->query($stmt);
$connection->execute($stmt);
}
}

Expand All @@ -180,7 +182,7 @@ public function testBakingDiff()
*/
public function testBakingDiffSimple()
{
$this->skipIf(env('DB_URL_COMPARE') !== false);
$this->skipIf(!env('DB_URL_COMPARE'));

$diffConfigFolder = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Diff' . DS . 'simple' . DS;
$diffMigrationsPath = $diffConfigFolder . 'the_diff_simple_' . env('DB') . '.php';
Expand All @@ -201,8 +203,9 @@ public function testBakingDiffSimple()
unlink($destination);
copy($diffDumpPath, $destinationDumpPath);

/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get('test_comparisons');
$connection->newQuery()
$connection->deleteQuery()
->delete('phinxlog')
->where(['version' => 20160415220805])
->execute();
Expand All @@ -223,7 +226,7 @@ public function testBakingDiffSimple()
rename($destinationConfigDir . $generatedMigration, $destination);
$versionParts = explode('_', $generatedMigration);

$connection->newQuery()
$connection->insertQuery()
->insert(['version', 'migration_name', 'start_time', 'end_time'])
->into('phinxlog')
->values([
Expand All @@ -244,7 +247,7 @@ public function testBakingDiffSimple()
*/
public function testBakingDiffAddRemove()
{
$this->skipIf(env('DB_URL_COMPARE') !== false);
$this->skipIf(!env('DB_URL_COMPARE'));

$diffConfigFolder = Plugin::path('Migrations') . 'tests' . DS . 'comparisons' . DS . 'Diff' . DS . 'addremove' . DS;
$diffMigrationsPath = $diffConfigFolder . 'the_diff_add_remove_' . env('DB') . '.php';
Expand All @@ -265,8 +268,9 @@ public function testBakingDiffAddRemove()
unlink($destination);
copy($diffDumpPath, $destinationDumpPath);

/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get('test_comparisons');
$connection->newQuery()
$connection->deleteQuery()
->delete('phinxlog')
->where(['version' => 20160415220805])
->execute();
Expand All @@ -288,7 +292,7 @@ public function testBakingDiffAddRemove()
rename($destinationConfigDir . $generatedMigration, $destination);
$versionParts = explode('_', $generatedMigration);

$connection->newQuery()
$connection->insertQuery()
->insert(['version', 'migration_name', 'start_time', 'end_time'])
->into('phinxlog')
->values([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TheDiffAddRemoveMysql extends AbstractMigration
*/
public function up(): void
{

$this->table('articles')
->removeColumn('excerpt')
->changeColumn('id', 'integer', [
Expand Down Expand Up @@ -43,6 +44,7 @@ public function up(): void
*/
public function down(): void
{

$this->table('articles')
->addColumn('excerpt', 'text', [
'after' => 'title',
Expand Down
1 change: 1 addition & 0 deletions tests/comparisons/Diff/simple/the_diff_simple_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function up(): void
[
'update' => 'RESTRICT',
'delete' => 'RESTRICT',
'constraint' => 'articles_ibfk_1'
]
)
->update();
Expand Down
9 changes: 9 additions & 0 deletions tests/comparisons/Diff/the_diff_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ public function up(): void
->addIndex(
[
'user_id',
],
[
'name' => 'categories_ibfk_1',
]
)
->addIndex(
[
'name',
],
[
'name' => 'name',
]
)
->create();
Expand All @@ -93,6 +99,7 @@ public function up(): void
[
'update' => 'RESTRICT',
'delete' => 'RESTRICT',
'constraint' => 'categories_ibfk_1'
]
)
->update();
Expand Down Expand Up @@ -145,6 +152,7 @@ public function up(): void
[
'update' => 'NO_ACTION',
'delete' => 'NO_ACTION',
'constraint' => 'articles_ibfk_1'
]
)
->update();
Expand Down Expand Up @@ -263,6 +271,7 @@ public function down(): void
[
'update' => 'CASCADE',
'delete' => 'CASCADE',
'constraint' => 'articles_ibfk_1'
]
)
->update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Console\Arguments;
use Cake\Core\Plugin;
use Migrations\Command\BakeMigrationDiffCommand;
use function Cake\Core\env;

class CustomBakeMigrationDiffCommand extends BakeMigrationDiffCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Console\Arguments;
use Cake\Core\Plugin;
use Migrations\Command\BakeMigrationDiffCommand;
use function Cake\Core\env;

class CustomRemoveBakeMigrationDiffCommand extends BakeMigrationDiffCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Console\Arguments;
use Cake\Core\Plugin;
use Migrations\Command\BakeMigrationDiffCommand;
use function Cake\Core\env;

class CustomSimpleBakeMigrationDiffCommand extends BakeMigrationDiffCommand
{
Expand Down
Loading