forked from boos/BoosAPI
fix: handle empty-string column defaults in MySQL schema introspection
MySQL information_schema.COLUMNS.COLUMN_DEFAULT stores DEFAULT '' as an empty string, not NULL. normalizeDefaultValueForColumn was treating any empty rawDefaultValue as 'no default' and returning null, causing the MySQL schema parity test to see defaultValue: null for post_refresh_probe_model while schemaContract.json (generated from TypeScript schema) had "''". Fix: when rawDefaultValue is empty string, return "''" for text/json columns instead of null, so the round-trip through MySQL introspection matches the contract.
This commit is contained in:
@@ -207,7 +207,12 @@ function normalizeDefaultValueForColumn(
|
||||
if (rawDefaultValue == null) return null;
|
||||
|
||||
let normalized = String(rawDefaultValue).trim();
|
||||
if (!normalized) return null;
|
||||
// MySQL stores DEFAULT '' as an empty string in information_schema.COLUMNS.COLUMN_DEFAULT.
|
||||
// An empty string here is a valid empty-string literal default, not "no default".
|
||||
// Encode it as two single-quotes so it round-trips through schemaContract correctly.
|
||||
if (!normalized) {
|
||||
return (logicalType === 'text' || logicalType === 'json') ? "''" : null;
|
||||
}
|
||||
|
||||
normalized = normalized.replace(/^default\s+/i, '').trim();
|
||||
normalized = unwrapSurroundingParentheses(normalized);
|
||||
|
||||
Reference in New Issue
Block a user