1717use Migrations \Db \Table \CheckConstraint ;
1818use Migrations \Db \Table \Column ;
1919use Migrations \Db \Table \ForeignKey ;
20+ use Migrations \Db \Table \Index ;
2021use Migrations \Db \Table \Partition ;
2122use PDO ;
2223use PDOException ;
@@ -350,6 +351,27 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid()
350351 $ this ->assertTrue ($ this ->adapter ->hasColumn ('ztable ' , 'user_id ' ));
351352 }
352353
354+ public function testCreateTableBinaryLengthWithIndex ()
355+ {
356+ $ table = new Table ('ntable ' , [], $ this ->adapter );
357+ $ table
358+ ->addColumn ('file ' , 'binary ' , [
359+ 'default ' => null ,
360+ 'length ' => 20 ,
361+ 'null ' => true ,
362+ ])
363+ ->addIndex (
364+ (new Index ())
365+ ->setColumns (['file ' ])
366+ ->setName ('file_idx ' )
367+ ->setType ('unique ' ),
368+ )
369+ ->create ();
370+ $ this ->assertTrue ($ this ->adapter ->hasColumn ('ntable ' , 'id ' ));
371+ $ this ->assertTrue ($ this ->adapter ->hasColumn ('ntable ' , 'file ' ));
372+ $ this ->assertTrue ($ this ->adapter ->hasIndex ('ntable ' , 'file ' ));
373+ }
374+
353375 /**
354376 * @return void
355377 */
@@ -1224,8 +1246,11 @@ public static function binaryToBlobAutomaticConversionData()
12241246 return [
12251247 // When creating binary with limit > 255, MySQL auto-converts to BLOB
12261248 // input limit, expected SQL type name, expected column limit after round-trip
1249+ // For values smaller than 255, we preserve the length.
12271250 [null , 'blob ' , MysqlAdapter::BLOB_REGULAR ], // binary(null) becomes BLOB
1228- [64 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // binary(64) becomes TINYBLOB
1251+ [64 , 'binary ' , 64 ], // binary(64) becomes binary(64)
1252+ [254 , 'binary ' , 254 ], // binary(254) becomes binary(254)
1253+ [255 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // binary(255) becomes TINYBLOB
12291254 [MysqlAdapter::BLOB_REGULAR - 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
12301255 [MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter::BLOB_REGULAR ],
12311256 [MysqlAdapter::BLOB_REGULAR + 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
@@ -1251,8 +1276,11 @@ public static function varbinaryToBlobAutomaticConversionData()
12511276 return [
12521277 // When creating varbinary with limit > 255, MySQL auto-converts to BLOB
12531278 // input limit, expected SQL type name, expected column limit after round-trip
1279+ // For values smaller than 255, we preserve the length.
12541280 [null , 'blob ' , MysqlAdapter::BLOB_REGULAR ], // varbinary(null) becomes BLOB
1255- [64 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // varbinary(64) becomes TINYBLOB
1281+ [64 , 'binary ' , 64 ], // varbinary(64) becomes binary(64)
1282+ [254 , 'binary ' , 254 ], // varbinary(254) becomes binary(254)
1283+ [255 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // varbinary(255) becomes TINYBLOB
12561284 [MysqlAdapter::BLOB_REGULAR - 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
12571285 [MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter::BLOB_REGULAR ],
12581286 [MysqlAdapter::BLOB_REGULAR + 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
0 commit comments