Skip to content

Commit

Permalink
Update bit type (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Aug 8, 2024
1 parent 15f0982 commit 4c42c68
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
for type casting performance. Related with yiisoft/db#752 (@Tigrov)
- Chg #307: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)
- Enh #310: Add JSON overlaps condition builder (@Tigrov)
- Enh #312: Update `bit` type according to main PR yiisoft/db#860 (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
10 changes: 1 addition & 9 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class Schema extends AbstractPdoSchema
*/
private const TYPE_MAP = [
'tinyint' => self::TYPE_TINYINT,
'bit' => self::TYPE_SMALLINT,
'bit' => self::TYPE_BIT,
'boolean' => self::TYPE_BOOLEAN,
'bool' => self::TYPE_BOOLEAN,
'smallint' => self::TYPE_SMALLINT,
Expand Down Expand Up @@ -518,14 +518,6 @@ private function getColumnType(string $dbType, array &$info): string
if (($dbType === 'tinyint' || $dbType === 'bit') && $info['size'] === 1) {
return self::TYPE_BOOLEAN;
}

if ($dbType === 'bit') {
return match (true) {
$info['size'] === 32 => self::TYPE_INTEGER,
$info['size'] > 32 => self::TYPE_BIGINT,
default => self::TYPE_SMALLINT,
};
}
}

return self::TYPE_MAP[$dbType] ?? self::TYPE_STRING;
Expand Down
10 changes: 5 additions & 5 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function columns(): array
'defaultValue' => new Expression('CURRENT_TIMESTAMP'),
],
'bit_col' => [
'type' => 'smallint',
'type' => 'bit',
'dbType' => 'bit(8)',
'phpType' => 'integer',
'primaryKey' => false,
Expand Down Expand Up @@ -361,7 +361,7 @@ public static function columnsTypeBit(): array
'defaultValue' => true,
],
'bit_col_3' => [
'type' => 'integer',
'type' => 'bit',
'dbType' => 'bit(32)',
'phpType' => 'integer',
'primaryKey' => false,
Expand All @@ -374,7 +374,7 @@ public static function columnsTypeBit(): array
'defaultValue' => null,
],
'bit_col_4' => [
'type' => 'integer',
'type' => 'bit',
'dbType' => 'bit(32)',
'phpType' => 'integer',
'primaryKey' => false,
Expand All @@ -387,7 +387,7 @@ public static function columnsTypeBit(): array
'defaultValue' => 1,
],
'bit_col_5' => [
'type' => 'bigint',
'type' => 'bit',
'dbType' => 'bit(64)',
'phpType' => 'integer',
'primaryKey' => false,
Expand All @@ -400,7 +400,7 @@ public static function columnsTypeBit(): array
'defaultValue' => null,
],
'bit_col_6' => [
'type' => 'bigint',
'type' => 'bit',
'dbType' => 'bit(64)',
'phpType' => 'integer',
'primaryKey' => false,
Expand Down

0 comments on commit 4c42c68

Please sign in to comment.