Skip to content

fix(csv-to-pg): add preserveEmptyStrings option, default true#1089

Merged
pyramation merged 3 commits intomainfrom
feat/csv-to-pg-preserve-empty-strings
May 9, 2026
Merged

fix(csv-to-pg): add preserveEmptyStrings option, default true#1089
pyramation merged 3 commits intomainfrom
feat/csv-to-pg-preserve-empty-strings

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented May 9, 2026

Summary

The text type coercion in csv-to-pg called cleanseEmptyStrings() which treats '' as a NULL token. This is wrong for PostgreSQL where '' and NULL are distinct values.

Root cause: When the webauthn_settings trigger inserts rp_id = '' (the NOT NULL default), the export converts ''NULL. The subsequent migration fails with:

null value in column "rp_id" of relation "webauthn_settings" violates not-null constraint

Fix: Add a preserveEmptyStrings option to the Parser:

  • Default (true): Empty strings preserved as '' — correct for PostgreSQL
  • false: Empty strings → NULL (CSV convention, opt-in)

This unblocks constructive-db PR #1078.

Review & Testing Checklist for Human

Notes

  • 3 new tests: default preserves empty strings, opt-out converts to NULL, null values still produce NULL

Link to Devin session: https://app.devin.ai/sessions/18d6c72085dc4b06b1428e2baddbf430
Requested by: @pyramation

…erting to NULL

The text type coercion was calling cleanseEmptyStrings() which treated
empty strings as NULL tokens. This is incorrect for database export/re-import
workflows where PostgreSQL distinguishes between '' and NULL.

This caused the webauthn_settings migration to fail: the table has
rp_id/rp_name as NOT NULL DEFAULT '', but the export converted '' to NULL,
producing an INSERT that violates the NOT NULL constraint.

The fix: for text fields, only treat actual null/undefined as NULL.
Empty strings are preserved as valid text values.
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Instead of unconditionally changing the text coercion behavior, add a
preserveEmptyStrings option that controls whether empty strings are
treated as NULL tokens (the default CSV convention) or preserved as
valid text values.

- Default behavior unchanged: empty strings → NULL (CSV convention)
- preserveEmptyStrings: true → empty strings preserved as ''
- export-meta.ts sets preserveEmptyStrings: true since database data
  distinguishes between '' and NULL

This fixes the webauthn_settings migration failure where rp_id/rp_name
default to '' but the export converted them to NULL.
@devin-ai-integration devin-ai-integration Bot changed the title fix(csv-to-pg): preserve empty strings in text fields instead of converting to NULL fix(csv-to-pg): add preserveEmptyStrings option for database export May 9, 2026
Empty strings are valid text values in PostgreSQL and should be
preserved by default. The setting can be set to false to opt into
the CSV convention of treating empty strings as NULL.
@devin-ai-integration devin-ai-integration Bot changed the title fix(csv-to-pg): add preserveEmptyStrings option for database export fix(csv-to-pg): add preserveEmptyStrings option, default true May 9, 2026
@pyramation pyramation merged commit 8abfb39 into main May 9, 2026
54 checks passed
@pyramation pyramation deleted the feat/csv-to-pg-preserve-empty-strings branch May 9, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant