Skip to content
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

Use new column definition builder #367

Merged
merged 13 commits into from
Dec 23, 2024
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
Tigrov committed Dec 12, 2024
commit 3a288383d737c2611949c57a97700ceec1309221
5 changes: 4 additions & 1 deletion src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnSche
return new Expression('CURRENT_TIMESTAMP' . (!empty($matches[1]) ? '(' . $matches[1] . ')' : ''));
}

if (!empty($column->getExtra())) {
if (!empty($column->getExtra())
|| $defaultValue[0] === '('
&& !in_array($column->getType(), [ColumnType::CHAR, ColumnType::STRING, ColumnType::TEXT, ColumnType::BINARY], true)
) {
return new Expression($defaultValue);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static function defaultValueRaw(): array
[ColumnType::STRING, "'str''ing'", "str'ing"],
[ColumnType::TIMESTAMP, 'CURRENT_TIMESTAMP', new Expression('CURRENT_TIMESTAMP')],
[ColumnType::TIMESTAMP, 'current_timestamp(3)', new Expression('CURRENT_TIMESTAMP(3)')],
[ColumnType::INTEGER, '(1 + 2)', new Expression('(1 + 2)')],
];
}
}
13 changes: 13 additions & 0 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ public static function buildColumnDefinition(): array

$values[] = ["enum('a','b','c')", ColumnBuilder::string()->dbType("enum('a','b','c')")];

$db = self::getDb();
$serverVersion = $db->getServerInfo()->getVersion();
$db->close();

if (!str_contains($serverVersion, 'MariaDB')
&& version_compare($serverVersion, '8', '<')
) {
$values[PseudoType::UUID_PK][0] = 'binary(16) PRIMARY KEY';
$values[PseudoType::UUID_PK_SEQ][0] = 'binary(16) PRIMARY KEY';
$values['uuidPrimaryKey()'][0] = 'binary(16) PRIMARY KEY';
$values['defaultValue($expression)'] = ['int DEFAULT 3', ColumnBuilder::integer()->defaultValue(3)];
}

return $values;
}
}
Loading