From b6064a65efded83aee7e330e06e5dc6c76a0cba9 Mon Sep 17 00:00:00 2001 From: Brent Roose Date: Sat, 14 Dec 2024 13:34:04 +0100 Subject: [PATCH] fix(database): default strong comparison check (#858) --- src/Tempest/Database/src/QueryStatements/CharStatement.php | 2 +- src/Tempest/Database/src/QueryStatements/DateStatement.php | 2 +- .../Database/src/QueryStatements/DatetimeStatement.php | 2 +- src/Tempest/Database/src/QueryStatements/FloatStatement.php | 2 +- src/Tempest/Database/src/QueryStatements/IntegerStatement.php | 2 +- src/Tempest/Database/src/QueryStatements/JsonStatement.php | 4 ++-- src/Tempest/Database/src/QueryStatements/TextStatement.php | 2 +- src/Tempest/Database/src/QueryStatements/VarcharStatement.php | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Tempest/Database/src/QueryStatements/CharStatement.php b/src/Tempest/Database/src/QueryStatements/CharStatement.php index 26a50798d..2746a2441 100644 --- a/src/Tempest/Database/src/QueryStatements/CharStatement.php +++ b/src/Tempest/Database/src/QueryStatements/CharStatement.php @@ -21,7 +21,7 @@ public function compile(DatabaseDialect $dialect): string return sprintf( '`%s` CHAR %s %s', $this->name, - $this->default ? "DEFAULT \"{$this->default}\"" : '', + $this->default !== null ? "DEFAULT \"{$this->default}\"" : '', $this->nullable ? '' : 'NOT NULL', ); } diff --git a/src/Tempest/Database/src/QueryStatements/DateStatement.php b/src/Tempest/Database/src/QueryStatements/DateStatement.php index d3fe17b54..02a1bbcc5 100644 --- a/src/Tempest/Database/src/QueryStatements/DateStatement.php +++ b/src/Tempest/Database/src/QueryStatements/DateStatement.php @@ -21,7 +21,7 @@ public function compile(DatabaseDialect $dialect): string return sprintf( '`%s` DATE %s %s', $this->name, - $this->default ? "DEFAULT \"{$this->default}\"" : '', + $this->default !== null ? "DEFAULT \"{$this->default}\"" : '', $this->nullable ? '' : 'NOT NULL', ); } diff --git a/src/Tempest/Database/src/QueryStatements/DatetimeStatement.php b/src/Tempest/Database/src/QueryStatements/DatetimeStatement.php index 5ff34db7c..5324edd6f 100644 --- a/src/Tempest/Database/src/QueryStatements/DatetimeStatement.php +++ b/src/Tempest/Database/src/QueryStatements/DatetimeStatement.php @@ -21,7 +21,7 @@ public function compile(DatabaseDialect $dialect): string return sprintf( '`%s` DATETIME %s %s', $this->name, - $this->default ? "DEFAULT \"{$this->default}\"" : '', + $this->default !== null ? "DEFAULT \"{$this->default}\"" : '', $this->nullable ? '' : 'NOT NULL', ); } diff --git a/src/Tempest/Database/src/QueryStatements/FloatStatement.php b/src/Tempest/Database/src/QueryStatements/FloatStatement.php index 49ba8c267..b9c4f808a 100644 --- a/src/Tempest/Database/src/QueryStatements/FloatStatement.php +++ b/src/Tempest/Database/src/QueryStatements/FloatStatement.php @@ -21,7 +21,7 @@ public function compile(DatabaseDialect $dialect): string return sprintf( '`%s` FLOAT %s %s', $this->name, - $this->default ? "DEFAULT {$this->default}" : '', + $this->default !== null ? "DEFAULT {$this->default}" : '', $this->nullable ? '' : 'NOT NULL', ); } diff --git a/src/Tempest/Database/src/QueryStatements/IntegerStatement.php b/src/Tempest/Database/src/QueryStatements/IntegerStatement.php index c5ec74862..674927fc6 100644 --- a/src/Tempest/Database/src/QueryStatements/IntegerStatement.php +++ b/src/Tempest/Database/src/QueryStatements/IntegerStatement.php @@ -23,7 +23,7 @@ public function compile(DatabaseDialect $dialect): string '`%s` INTEGER %s %s %s', $this->name, $this->unsigned ? 'UNSIGNED' : '', - $this->default ? "DEFAULT {$this->default}" : '', + $this->default !== null ? "DEFAULT {$this->default}" : '', $this->nullable ? '' : 'NOT NULL', ); } diff --git a/src/Tempest/Database/src/QueryStatements/JsonStatement.php b/src/Tempest/Database/src/QueryStatements/JsonStatement.php index cc9d6887e..4a5d24b6c 100644 --- a/src/Tempest/Database/src/QueryStatements/JsonStatement.php +++ b/src/Tempest/Database/src/QueryStatements/JsonStatement.php @@ -32,13 +32,13 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::SQLITE => sprintf( '`%s` TEXT %s %s', $this->name, - $this->default ? "DEFAULT '{$this->default}'" : '', + $this->default !== null ? "DEFAULT '{$this->default}'" : '', $this->nullable ? '' : 'NOT NULL', ), DatabaseDialect::POSTGRESQL => sprintf( '`%s` JSONB %s %s', $this->name, - $this->default ? "DEFAULT (\"{$this->default}\")" : '', + $this->default !== null ? "DEFAULT (\"{$this->default}\")" : '', $this->nullable ? '' : 'NOT NULL', ), }; diff --git a/src/Tempest/Database/src/QueryStatements/TextStatement.php b/src/Tempest/Database/src/QueryStatements/TextStatement.php index b94bf50e5..5b9d91ca6 100644 --- a/src/Tempest/Database/src/QueryStatements/TextStatement.php +++ b/src/Tempest/Database/src/QueryStatements/TextStatement.php @@ -27,7 +27,7 @@ public function compile(DatabaseDialect $dialect): string default => sprintf( '`%s` TEXT %s %s', $this->name, - $this->default ? "DEFAULT \"{$this->default}\"" : '', + $this->default !== null ? "DEFAULT \"{$this->default}\"" : '', $this->nullable ? '' : 'NOT NULL', ), }; diff --git a/src/Tempest/Database/src/QueryStatements/VarcharStatement.php b/src/Tempest/Database/src/QueryStatements/VarcharStatement.php index 19928553b..4dcff9a16 100644 --- a/src/Tempest/Database/src/QueryStatements/VarcharStatement.php +++ b/src/Tempest/Database/src/QueryStatements/VarcharStatement.php @@ -23,7 +23,7 @@ public function compile(DatabaseDialect $dialect): string '`%s` VARCHAR(%s) %s %s', $this->name, $this->size, - $this->default ? "DEFAULT \"{$this->default}\"" : '', + $this->default !== null ? "DEFAULT \"{$this->default}\"" : '', $this->nullable ? '' : 'NOT NULL', ); }