Skip to content

Commit

Permalink
Update bit type (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Aug 8, 2024
1 parent c0f8c7a commit 0d13a32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 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 @@
- Enh #321: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov)
- Chg #339: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)
- Enh #342: Add JSON overlaps condition builder (@Tigrov)
- Enh #344: Update `bit` type according to main PR yiisoft/db#860 (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
10 changes: 3 additions & 7 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class Schema extends AbstractPdoSchema
*/
private const TYPE_MAP = [
'tinyint' => self::TYPE_TINYINT,
'bit' => self::TYPE_INTEGER,
'bit' => self::TYPE_BIT,
'smallint' => self::TYPE_SMALLINT,
'mediumint' => self::TYPE_INTEGER,
'int' => self::TYPE_INTEGER,
Expand Down Expand Up @@ -523,12 +523,8 @@ private function getColumnType(string $dbType, array &$info): string
$info['scale'] = (int) $values[1];
}

if ($dbType === 'bit') {
return match (true) {
$info['size'] === 1 => self::TYPE_BOOLEAN,
$info['size'] > 32 => self::TYPE_BIGINT,
default => self::TYPE_INTEGER,
};
if ($dbType === 'bit' && $info['size'] === 1) {
return self::TYPE_BOOLEAN;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static function columns(): array
'defaultValue' => new Expression('CURRENT_TIMESTAMP'),
],
'bit_col' => [
'type' => 'integer',
'type' => 'bit',
'dbType' => 'bit(8)',
'phpType' => 'integer',
'primaryKey' => false,
Expand Down Expand Up @@ -333,7 +333,7 @@ public static function columnsTypeBit(): array
'defaultValue' => true,
],
'bit_col_3' => [
'type' => 'integer',
'type' => 'bit',
'dbType' => 'bit(32)',
'phpType' => 'integer',
'primaryKey' => false,
Expand All @@ -346,7 +346,7 @@ public static function columnsTypeBit(): array
'defaultValue' => null,
],
'bit_col_4' => [
'type' => 'integer',
'type' => 'bit',
'dbType' => 'bit(32)',
'phpType' => 'integer',
'primaryKey' => false,
Expand All @@ -359,7 +359,7 @@ public static function columnsTypeBit(): array
'defaultValue' => 130,
],
'bit_col_5' => [
'type' => 'bigint',
'type' => 'bit',
'dbType' => 'bit(64)',
'phpType' => 'integer',
'primaryKey' => false,
Expand All @@ -372,7 +372,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 0d13a32

Please sign in to comment.