Skip to content

JSON issue fix #3

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

Merged
merged 3 commits into from
Dec 29, 2022
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,3 @@ Professional support, consulting as well as software development services are av
https://www.cebe.cc/en/contact

Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud).

21 changes: 20 additions & 1 deletion src/lib/migrations/BaseMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Yii;
use yii\db\ColumnSchema;
use yii\helpers\VarDumper;
use yii\db\Connection;
use yii\db\{Connection, Expression};

abstract class BaseMigrationBuilder
{
Expand Down Expand Up @@ -477,4 +477,23 @@ public static function isEnumValuesChanged(
}
return false;
}

public function isDefaultValueChanged(ColumnSchema $current,
ColumnSchema $desired): bool
{
// if the default value is object of \yii\db\Expression then default value is expression instead of constant. See https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html
// in such case instead of comparing two objects, we should compare expression

if ($current->defaultValue instanceof Expression &&
$desired->defaultValue instanceof Expression
&& $current->defaultValue->expression === $desired->defaultValue->expression
) {
return false;
}

if ($current->defaultValue !== $desired->defaultValue) {
return true;
}
return false;
}
}
10 changes: 8 additions & 2 deletions src/lib/migrations/MysqlMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ protected function compareColumns(ColumnSchema $current, ColumnSchema $desired):
, 'dbType', 'phpType'
, 'precision', 'scale', 'unsigned'
] as $attr) {
if ($current->$attr !== $desiredFromDb->$attr) {
$changedAttributes[] = $attr;
if ($attr === 'defaultValue') {
if ($this->isDefaultValueChanged($current, $desiredFromDb)) {
$changedAttributes[] = $attr;
}
} else {
if ($current->$attr !== $desiredFromDb->$attr) {
$changedAttributes[] = $attr;
}
}
}
return $changedAttributes;
Expand Down
10 changes: 8 additions & 2 deletions src/lib/migrations/PostgresMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ protected function compareColumns(ColumnSchema $current, ColumnSchema $desired):
, 'dbType', 'phpType'
, 'precision', 'scale', 'unsigned'
] as $attr) {
if ($current->$attr !== $desiredFromDb->$attr) {
$changedAttributes[] = $attr;
if ($attr === 'defaultValue') {
if ($this->isDefaultValueChanged($current, $desiredFromDb)) {
$changedAttributes[] = $attr;
}
} else {
if ($current->$attr !== $desiredFromDb->$attr) {
$changedAttributes[] = $attr;
}
}
}
return $changedAttributes;
Expand Down