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:
Xiang Li
2026-04-23 23:46:10 +08:00
parent 078ac4aa9d
commit 99392341fe
+6 -1
View File
@@ -207,7 +207,12 @@ function normalizeDefaultValueForColumn(
if (rawDefaultValue == null) return null; if (rawDefaultValue == null) return null;
let normalized = String(rawDefaultValue).trim(); 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 = normalized.replace(/^default\s+/i, '').trim();
normalized = unwrapSurroundingParentheses(normalized); normalized = unwrapSurroundingParentheses(normalized);