1717use Migrations \Db \Table ;
1818use Migrations \Db \Table \Column ;
1919use Migrations \Db \Table \ForeignKey ;
20+ use Migrations \Db \Table \Index ;
2021use PDO ;
2122use PDOException ;
2223use PHPUnit \Framework \Attributes \DataProvider ;
@@ -337,6 +338,27 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid()
337338 $ this ->assertTrue ($ this ->adapter ->hasColumn ('ztable ' , 'user_id ' ));
338339 }
339340
341+ public function testCreateTableBinaryLengthWithIndex ()
342+ {
343+ $ table = new Table ('ntable ' , [], $ this ->adapter );
344+ $ table
345+ ->addColumn ('file ' , 'binary ' , [
346+ 'default ' => null ,
347+ 'length ' => 20 ,
348+ 'null ' => true ,
349+ ])
350+ ->addIndex (
351+ (new Index ())
352+ ->setColumns (['file ' ])
353+ ->setName ('file_idx ' )
354+ ->setType ('unique ' ),
355+ )
356+ ->create ();
357+ $ this ->assertTrue ($ this ->adapter ->hasColumn ('ntable ' , 'id ' ));
358+ $ this ->assertTrue ($ this ->adapter ->hasColumn ('ntable ' , 'file ' ));
359+ $ this ->assertTrue ($ this ->adapter ->hasIndex ('ntable ' , 'file ' ));
360+ }
361+
340362 /**
341363 * @return void
342364 */
@@ -1071,8 +1093,11 @@ public static function binaryToBlobAutomaticConversionData()
10711093 return [
10721094 // When creating binary with limit > 255, MySQL auto-converts to BLOB
10731095 // input limit, expected SQL type name, expected column limit after round-trip
1096+ // For values smaller than 255, we preserve the length.
10741097 [null , 'blob ' , MysqlAdapter::BLOB_REGULAR ], // binary(null) becomes BLOB
1075- [64 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // binary(64) becomes TINYBLOB
1098+ [64 , 'binary ' , 64 ], // binary(64) becomes binary(64)
1099+ [254 , 'binary ' , 254 ], // binary(254) becomes binary(254)
1100+ [255 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // binary(255) becomes TINYBLOB
10761101 [MysqlAdapter::BLOB_REGULAR - 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
10771102 [MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter::BLOB_REGULAR ],
10781103 [MysqlAdapter::BLOB_REGULAR + 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
@@ -1099,8 +1124,11 @@ public static function varbinaryToBlobAutomaticConversionData()
10991124 return [
11001125 // When creating varbinary with limit > 255, MySQL auto-converts to BLOB
11011126 // input limit, expected SQL type name, expected column limit after round-trip
1127+ // For values smaller than 255, we preserve the length.
11021128 [null , 'blob ' , MysqlAdapter::BLOB_REGULAR ], // varbinary(null) becomes BLOB
1103- [64 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // varbinary(64) becomes TINYBLOB
1129+ [64 , 'binary ' , 64 ], // varbinary(64) becomes binary(64)
1130+ [254 , 'binary ' , 254 ], // varbinary(254) becomes binary(254)
1131+ [255 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // varbinary(255) becomes TINYBLOB
11041132 [MysqlAdapter::BLOB_REGULAR - 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
11051133 [MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter::BLOB_REGULAR ],
11061134 [MysqlAdapter::BLOB_REGULAR + 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
0 commit comments