migrate_columns() doesn't preserve the NOT NULL constraint when updating column comments. The MODIFY COLUMN statement only includes the type and new comment, so MySQL defaults the column to nullable.
The generated SQL looks like:
ALTER TABLE `db`.`table` MODIFY COLUMN `col` longblob COMMENT ':blob:my comment'
But for columns that were NOT NULL, it should be:
ALTER TABLE `db`.`table` MODIFY COLUMN `col` longblob NOT NULL COMMENT ':blob:my comment'
The root cause is in analyze_columns(). The information_schema.COLUMNS query only fetches COLUMN_NAME, COLUMN_TYPE, DATA_TYPE, COLUMN_COMMENT and doesn't include IS_NULLABLE. So by the time migrate_columns() builds the ALTER TABLE, it has no way to know whether the column was NOT NULL.
The fix would be to add IS_NULLABLE to the query, carry that through to col_info, and conditionally include NOT NULL in the MODIFY COLUMN statement.
migrate_columns()doesn't preserve the NOT NULL constraint when updating column comments. TheMODIFY COLUMNstatement only includes the type and new comment, so MySQL defaults the column to nullable.The generated SQL looks like:
But for columns that were NOT NULL, it should be:
The root cause is in
analyze_columns(). Theinformation_schema.COLUMNSquery only fetchesCOLUMN_NAME, COLUMN_TYPE, DATA_TYPE, COLUMN_COMMENTand doesn't includeIS_NULLABLE. So by the timemigrate_columns()builds the ALTER TABLE, it has no way to know whether the column was NOT NULL.The fix would be to add
IS_NULLABLEto the query, carry that through tocol_info, and conditionally includeNOT NULLin theMODIFY COLUMNstatement.