fix(nhost): correctly handle text column size for varchar vs text types#192
fix(nhost): correctly handle text column size for varchar vs text types#192deepshekhardas wants to merge 1 commit into
Conversation
Previously text columns (unlimited length) fell through to 10485760 default, and character_octet_length (byte length) was used as a secondary fallback which can differ from character_maximum_length for multi-byte encodings. Now properly distinguishes text type columns and avoids using character_octet_length as a substitute for character_maximum_length.
Greptile SummaryThis PR corrects the
Confidence Score: 4/5The change is targeted and safe to merge; the corrected logic produces the right size value for all standard scalar column types, and the one edge case (text[] arrays) also arrives at the correct final value through the existing fallback. The fix correctly handles text vs varchar(n) for non-array columns. For text[] arrays, data_type is ARRAY so the new explicit text branch is bypassed, but the fallback still yields 10485760 since character_octet_length is null for array text columns in PostgreSQL. The observable behavior is identical to the intended fix for arrays today, but the asymmetry in code paths could silently diverge if PostgreSQL ever surfaces a non-null character_octet_length for array types. Only src/Migration/Sources/NHost.php changed; the array-column path in the default branch is worth a second look for the text[] case. Important Files Changed
Reviews (1): Last reviewed commit: "fix(nhost): handle text column size corr..." | Re-trigger Greptile |
| default: $column['column_default'], | ||
| array: $isArray, | ||
| size: $column['character_maximum_length'] ?? $column['character_octet_length'] ?? 10485760, | ||
| size: $column['character_maximum_length'] ?? ($column['data_type'] === 'text' ? 10485760 : ($column['character_octet_length'] ?? 10485760)), |
There was a problem hiding this comment.
text[] arrays bypass the explicit text branch
For array columns with an underlying text type (e.g. text[]), $column['data_type'] is 'ARRAY', not 'text'. The switch expression uses str_replace('_', '', $column['udt_name']) (so _text → text) which still falls to default, but inside default the condition $column['data_type'] === 'text' evaluates to false. The code then reaches $column['character_octet_length'] ?? 10485760, and since PostgreSQL also leaves character_octet_length null for text arrays, the final value is still 10485760 — so the observable result is correct today. However, the logic is silently inconsistent: text[] takes a different code path than scalar text and would behave differently if character_octet_length were ever populated for arrays. A safer check would test the underlying udt_name as well, e.g. $column['data_type'] === 'text' || ltrim($column['udt_name'] ?? '', '_') === 'text'.
Problem
When importing from Supabase (which uses the NHost source), all text columns are imported with size 10485760 regardless of their actual type:
.
Fix
The fix checks data_type === 'text' separately so that:
�archar(n) columns: use character_maximum_length =
ext columns: uses 10485760 as a reasonable default for unlimited text
character_octet_length is only used for other edge-case types
Related
Fixes appwrite/appwrite#7182