Summary
All sanitization strategies operate by casting column values to ::text. Columns of type JSONB, BYTEA, ARRAY, UUID, range types, and others are not explicitly handled and may produce incorrect results or runtime errors when cast.
Current Limitation
For example, hash strategy generates:
encode(sha256("column"::text::bytea), 'hex')
On a JSONB column this produces a hash of the JSON text representation, which is semantically correct. But BYTEA columns would produce a hex-encoded hash of the binary's text encoding, not the binary itself.
faker strategies assign text values that may fail type casting on strictly-typed columns.
Proposed Approach
- Type-aware SQL generation in each strategy: detect column data type during validation and emit type-appropriate SQL (e.g.,
sha256(column) directly for bytea, uuid_generate_v4() for UUID, '{}'::jsonb for JSONB null replacement).
- New faker methods for typed columns:
faker: uuid, faker: jsonb_empty, faker: bytea_empty.
- Validation warning when a strategy is applied to a column type it does not natively support.
Affected Types
| Type |
Current Behavior |
Needed |
JSONB |
Casts to text, works but lossy |
Native JSON manipulation support |
BYTEA |
May corrupt binary data |
Direct binary handling |
UUID |
Works via text cast |
Native uuid_generate_v4() |
ARRAY |
Likely fails or corrupts |
Per-element sanitization |
| Range types |
Unsupported |
New strategy or raw_sql |
Acceptance Criteria
Summary
All sanitization strategies operate by casting column values to
::text. Columns of typeJSONB,BYTEA,ARRAY,UUID, range types, and others are not explicitly handled and may produce incorrect results or runtime errors when cast.Current Limitation
For example,
hashstrategy generates:On a
JSONBcolumn this produces a hash of the JSON text representation, which is semantically correct. ButBYTEAcolumns would produce a hex-encoded hash of the binary's text encoding, not the binary itself.fakerstrategies assign text values that may fail type casting on strictly-typed columns.Proposed Approach
sha256(column)directly for bytea,uuid_generate_v4()for UUID,'{}'::jsonbfor JSONB null replacement).faker: uuid,faker: jsonb_empty,faker: bytea_empty.Affected Types
JSONBBYTEAUUIDuuid_generate_v4()ARRAYAcceptance Criteria
validatereports a warning when a strategy is applied to an unsupported column typehashstrategy works correctly onBYTEAcolumnsnull_valueworks correctly on all nullable typesfaker: uuidgenerates valid UUIDs for UUID columnsfakerstrategies that return text emit a validation warning on non-text columns