-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #6198: stop considering generated column definition as being its …
…default value The `pg_get_expr(adbin, adrelid)` expression in Postgresql's internal table `pg_attrdef` is used to know a column definition for most column, if this returns something, it means this column's default value. So DBAL has been considering has ALWAYS meaning it contains its default. However for generated columns, it contains the value definition and not its default value, so we change the selectTableColumns' query to correctly set the 'default' column to `null` for generated columns It will help setting correctly the column's attributes which in turn will help generate correct schema diff.
- Loading branch information
1 parent
45941c6
commit bfb754f
Showing
6 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Platforms; | ||
|
||
/** | ||
* Provides the behavior, features and SQL dialect of the PostgreSQL 12.0 database platform. | ||
*/ | ||
class PostgreSQL120Platform extends PostgreSQL100Platform | ||
{ | ||
public function getDefaultColumnValueSQLSnippet(): string | ||
{ | ||
// in case of GENERATED ALWAYS AS ( foobar) STORED column (added in PostgreSQL 12.0) | ||
// postgreSQL's pg_get_expr(adbin, adrelid) will return the 'foobar' part | ||
// which is not the 'default' value of the column but its 'definition' | ||
// so in that case we force it to NULL as DBAL will use that column only for the | ||
// 'default' value | ||
return <<<'SQL' | ||
SELECT | ||
CASE | ||
WHEN a.attgenerated = 's' THEN NULL | ||
ELSE pg_get_expr(adbin, adrelid) | ||
END | ||
FROM pg_attrdef | ||
WHERE c.oid = pg_attrdef.adrelid | ||
AND pg_attrdef.adnum=a.attnum | ||
SQL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters