Skip to content

Commit d9848a2

Browse files
committed
Add schema dumps and expected outputs for decimal migration_diff test
- Created schema-dump-test_comparisons_mysql.lock and pgsql.lock with DECIMAL(8,2) - Modified setup migrations to CREATE table instead of CHANGE column - Added expected output files in mysql/ and pgsql/ subdirectories with CHANGE column - This allows the diff command to compare DB (10,2) vs dump (8,2) and generate changeColumn migration
1 parent 09ce21a commit d9848a2

File tree

6 files changed

+102
-22
lines changed

6 files changed

+102
-22
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Migrations\BaseMigration;
5+
6+
class TheDiffDecimalChangeMysql extends BaseMigration
7+
{
8+
/**
9+
* Up Method.
10+
*
11+
* More information on this method is available here:
12+
* https://book.cakephp.org/migrations/4/en/migrations.html#the-up-method
13+
*
14+
* @return void
15+
*/
16+
public function up(): void
17+
{
18+
$this->table('products')
19+
->changeColumn('price', 'decimal', [
20+
'default' => null,
21+
'limit' => null,
22+
'null' => false,
23+
'precision' => 10,
24+
'scale' => 2,
25+
])
26+
->update();
27+
}
28+
29+
/**
30+
* Down Method.
31+
*
32+
* More information on this method is available here:
33+
* https://book.cakephp.org/phinx/0/en/migrations.html#the-down-method
34+
*
35+
* @return void
36+
*/
37+
public function down(): void
38+
{
39+
$this->table('products')
40+
->changeColumn('price', 'decimal', [
41+
'default' => null,
42+
'null' => false,
43+
'precision' => 8,
44+
'scale' => 2,
45+
])
46+
->update();
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Migrations\BaseMigration;
5+
6+
class TheDiffDecimalChangePgsql extends BaseMigration
7+
{
8+
/**
9+
* Up Method.
10+
*
11+
* More information on this method is available here:
12+
* https://book.cakephp.org/migrations/4/en/migrations.html#the-up-method
13+
*
14+
* @return void
15+
*/
16+
public function up(): void
17+
{
18+
$this->table('products')
19+
->changeColumn('price', 'decimal', [
20+
'default' => null,
21+
'limit' => null,
22+
'null' => false,
23+
'precision' => 10,
24+
'scale' => 2,
25+
])
26+
->update();
27+
}
28+
29+
/**
30+
* Down Method.
31+
*
32+
* More information on this method is available here:
33+
* https://book.cakephp.org/phinx/0/en/migrations.html#the-down-method
34+
*
35+
* @return void
36+
*/
37+
public function down(): void
38+
{
39+
$this->table('products')
40+
->changeColumn('price', 'decimal', [
41+
'default' => null,
42+
'null' => false,
43+
'precision' => 8,
44+
'scale' => 2,
45+
])
46+
->update();
47+
}
48+
}
Binary file not shown.
Binary file not shown.

tests/comparisons/Diff/decimalChange/the_diff_decimal_change_mysql.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ class TheDiffDecimalChangeMysql extends BaseMigration
1616
public function up(): void
1717
{
1818
$this->table('products')
19-
->changeColumn('price', 'decimal', [
19+
->addColumn('price', 'decimal', [
2020
'default' => null,
21-
'limit' => null,
2221
'null' => false,
2322
'precision' => 10,
2423
'scale' => 2,
2524
])
26-
->update();
25+
->create();
2726
}
2827

2928
/**
@@ -36,13 +35,6 @@ public function up(): void
3635
*/
3736
public function down(): void
3837
{
39-
$this->table('products')
40-
->changeColumn('price', 'decimal', [
41-
'default' => null,
42-
'null' => false,
43-
'precision' => 8,
44-
'scale' => 2,
45-
])
46-
->update();
38+
$this->table('products')->drop()->save();
4739
}
4840
}

tests/comparisons/Diff/decimalChange/the_diff_decimal_change_pgsql.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ class TheDiffDecimalChangePgsql extends BaseMigration
1616
public function up(): void
1717
{
1818
$this->table('products')
19-
->changeColumn('price', 'decimal', [
19+
->addColumn('price', 'decimal', [
2020
'default' => null,
21-
'limit' => null,
2221
'null' => false,
2322
'precision' => 10,
2423
'scale' => 2,
2524
])
26-
->update();
25+
->create();
2726
}
2827

2928
/**
@@ -36,13 +35,6 @@ public function up(): void
3635
*/
3736
public function down(): void
3837
{
39-
$this->table('products')
40-
->changeColumn('price', 'decimal', [
41-
'default' => null,
42-
'null' => false,
43-
'precision' => 8,
44-
'scale' => 2,
45-
])
46-
->update();
38+
$this->table('products')->drop()->save();
4739
}
4840
}

0 commit comments

Comments
 (0)