Skip to content

fix: serialize TEXT[] columns as PostgreSQL array literals in pg-format#286

Merged
fiddur merged 3 commits intodevelopfrom
fix/pg-array-literal-screentime-categories
Mar 1, 2026
Merged

fix: serialize TEXT[] columns as PostgreSQL array literals in pg-format#286
fiddur merged 3 commits intodevelopfrom
fix/pg-array-literal-screentime-categories

Conversation

@fiddur
Copy link
Owner

@fiddur fiddur commented Mar 1, 2026

Summary

  • Fixes 500 error when creating/importing screentime categories (and during recategorization)
  • pg-format's %L treats JS arrays as sub-tuples in multi-row VALUES, producing 'TV' instead of the required PostgreSQL array literal '{TV}' for TEXT[] columns
  • Adds toPgArray() helper that properly serializes string[] to PostgreSQL array literal format (with proper escaping of special characters)
  • Fixes both batchUpdateResolvedCategory and insertProductivity which had the same issue
  • Includes 14 unit tests covering simple arrays, hierarchical paths, special characters, null handling, and edge cases

pg-format's %L treats JS arrays as sub-tuples in multi-row VALUES,
producing 'TV' instead of '{TV}' for TEXT[] columns. This caused
'malformed array literal' errors during screentime recategorization
and productivity record insertion.

Add toPgArray() helper to properly serialize string arrays to
PostgreSQL array literal format, and apply it in both
batchUpdateResolvedCategory and insertProductivity.
@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.88%. Comparing base (7800e05) to head (90d8e16).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #286      +/-   ##
===========================================
+ Coverage    31.43%   31.88%   +0.44%     
===========================================
  Files          181      181              
  Lines        22973    22992      +19     
  Branches      1855     1886      +31     
===========================================
+ Hits          7222     7331     +109     
+ Misses       15717    15627      -90     
  Partials        34       34              
Flag Coverage Δ
backend 58.93% <100.00%> (+0.85%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Covers insertProductivity, batchUpdateResolvedCategory,
getAllProductivityForCategorization, deleteProductivityRecord,
and restoreProductivityRecord with 21 tests including TEXT[]
array round-trips through a real PostgreSQL instance.
@fiddur fiddur marked this pull request as ready for review March 1, 2026 08:04
@fiddur fiddur enabled auto-merge March 1, 2026 08:04
@fiddur fiddur merged commit a2c37e5 into develop Mar 1, 2026
6 checks passed
@fiddur fiddur deleted the fix/pg-array-literal-screentime-categories branch March 1, 2026 08:08
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