Skip to content

Add TYPE_VARBINARY for proper binary type distinction#19258

Open
dereuromark wants to merge 2 commits into6.xfrom
feature/type-varbinary
Open

Add TYPE_VARBINARY for proper binary type distinction#19258
dereuromark wants to merge 2 commits into6.xfrom
feature/type-varbinary

Conversation

@dereuromark
Copy link
Member

Summary

This is a BC-breaking alternative to #19207 that adds a proper TYPE_VARBINARY constant instead of using a fixed attribute on the binary type.

  • binary type now always generates BINARY (fixed-length)
  • New varbinary type generates VARBINARY (variable-length)
  • SQLite/PostgreSQL map both to BLOB/BYTEA respectively (no distinction in those databases)
CakePHP Type MySQL SQLite SQL Server PostgreSQL
binary BINARY BLOB BINARY BYTEA
varbinary VARBINARY BLOB VARBINARY BYTEA

This mirrors the existing pattern for string types where charCHAR and stringVARCHAR.

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
@dereuromark
Copy link
Member Author

Migration Impact

For users upgrading to 6.x, existing migrations using the binary type with fixed => true will need to be updated:

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 fixed attribute is no longer used for binary types. Instead, use the appropriate type directly:

  • binary → fixed-length BINARY
  • varbinary → variable-length VARBINARY

Schema reflection will now correctly identify VARBINARY columns as type varbinary instead of binary, ensuring proper round-tripping in migrations.

@dereuromark dereuromark added this to the 6.0 milestone Feb 12, 2026
SQL Server only supports BINARY with lengths up to 8000.
For MAX lengths, fall back to VARBINARY(MAX).
dereuromark added a commit to cakephp/upgrade that referenced this pull request Feb 12, 2026
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
@markstory
Copy link
Member

The fixed attribute is no longer used for binary types. Instead, use the appropriate type directly:

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?

Comment on lines 624 to -625

if (!empty($column['fixed'])) {
$out .= ' BINARY';
} else {
$out .= ' VARBINARY';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants