Add TYPE_VARBINARY for proper binary type distinction#19258
Add TYPE_VARBINARY for proper binary type distinction#19258dereuromark wants to merge 2 commits into6.xfrom
Conversation
This is a BC-breaking alternative to #19207 that adds a proper TYPE_VARBINARY constant instead of using a `fixed` attribute. - binary type now always generates BINARY (fixed-length) - New varbinary type generates VARBINARY (variable-length) - SQLite/PostgreSQL map both to BLOB/BYTEA respectively
Migration ImpactFor users upgrading to 6.x, existing migrations using the Before (5.x with #19207): // Fixed-length BINARY(20)
$table->addColumn('hash', 'binary', ['length' => 20, 'fixed' => true]);
// Variable-length VARBINARY(20)
$table->addColumn('data', 'binary', ['length' => 20]);After (6.x with this PR): // Fixed-length BINARY(20)
$table->addColumn('hash', 'binary', ['length' => 20]);
// Variable-length VARBINARY(20)
$table->addColumn('data', 'varbinary', ['length' => 20]);The
Schema reflection will now correctly identify |
SQL Server only supports BINARY with lengths up to 8000. For MAX lengths, fall back to VARBINARY(MAX).
Adds a rector rule to help users upgrade to CakePHP 6.0 where
TYPE_VARBINARY was added:
- `addColumn('col', 'binary', ['fixed' => true])` becomes
`addColumn('col', 'binary', [])` (remove fixed attribute)
- `addColumn('col', 'binary', [...])` becomes
`addColumn('col', 'varbinary', [...])` (change type)
See: cakephp/cakephp#19258
It doesn't feel great to be introducing a new option in 5.3, and then breaking that behavior in the next major. Perhaps it won't matter much as varbinary is hopefully an infrequently used datatype? |
|
|
||
| if (!empty($column['fixed'])) { | ||
| $out .= ' BINARY'; | ||
| } else { | ||
| $out .= ' VARBINARY'; | ||
| } |
There was a problem hiding this comment.
Keeping this for compatibility seems like a reasonable compromise. At least then we aren't breaking something we recently shipped. It would give two ways do express varbinary/binary columns but we could avoid the breaking change.
Summary
This is a BC-breaking alternative to #19207 that adds a proper
TYPE_VARBINARYconstant instead of using afixedattribute on the binary type.binarytype now always generatesBINARY(fixed-length)varbinarytype generatesVARBINARY(variable-length)BLOB/BYTEArespectively (no distinction in those databases)This mirrors the existing pattern for string types where
char→CHARandstring→VARCHAR.