Skip to content

docs: add unique constraint and search sanitization patterns#296

Merged
hoiekim merged 1 commit intohoiekim:mainfrom
moltboie:docs/dev-md-unique-constraints-migration
Mar 27, 2026
Merged

docs: add unique constraint and search sanitization patterns#296
hoiekim merged 1 commit intohoiekim:mainfrom
moltboie:docs/dev-md-unique-constraints-migration

Conversation

@moltboie
Copy link
Copy Markdown
Contributor

Add two patterns to DEVELOPMENT.md extracted from recent merged PRs:

Data Integrity Constraints

From PR #143 — enforce uniqueness at the database level with UNIQUE constraints and ON CONFLICT upserts. Application-level dedup is insufficient due to race conditions and concurrency. Includes guidance on manual migration scripts for DDL changes.

Search Highlight Sanitization

From PR #174 — sanitize ts_headline output before dangerouslySetInnerHTML to prevent XSS via crafted email content in search results.

E2E Testing

Documentation-only change. Verified markdown renders correctly.

Copy link
Copy Markdown
Contributor Author

@moltboie moltboie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-Review

Discussion thread status:

  • No prior thread.

Checked:

  • Logic — Documents two patterns: (1) UNIQUE constraints for natural keys with ON CONFLICT upsert; (2) ts_headline output sanitization before dangerouslySetInnerHTML.
  • Types — Docs only.
  • Quality — Clear examples with bad/good patterns and references to implementing PRs.
  • Maintainability — Migration script placement convention (migrations/ with numbered prefix) is well specified.
  • Security — The ts_headline sanitization note is important — allowing only <b> tags prevents XSS from PostgreSQL highlight output.
  • Tests — N/A.
  • Blockers — None.

Issues found:

  • None.

Confidence: High

Patterns extracted from recent merged PRs:
- Data integrity constraints (PR hoiekim#143): enforce uniqueness at DB level
  with UNIQUE constraints and ON CONFLICT upserts, not just app logic
- Search highlight sanitization (PR hoiekim#174): sanitize ts_headline output
  before dangerouslySetInnerHTML to prevent XSS via crafted content
@moltboie moltboie force-pushed the docs/dev-md-unique-constraints-migration branch from a4dd67d to 938cfb3 Compare March 21, 2026 16:39
@hoiekim hoiekim merged commit c142999 into hoiekim:main Mar 27, 2026
2 checks passed
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.

2 participants