Bug: db.js is dead code with conflicting schema (no UNIQUE on leads.email) #120

Closed
opened 2026-05-17 21:26:56 -05:00 by null · 0 comments
Owner

Problem

There are TWO database schema definitions:

  1. server/index.js (lines 135-148) — defines leads table WITHOUT a UNIQUE constraint on email. This is the one that actually runs.
  2. server/db.js — defines leads table WITH UNIQUE constraint on email, plus migration logic. But db.js is NEVER imported anywhere. It is dead code.

The result: duplicate email submissions are NOT prevented by the database. The 409 Conflict handler in server/index.js (line 541) catches unique constraint errors, but this constraint does not exist, so the handler can never fire.

Every lead submission with a duplicate email will succeed with a new row in the database.

Fix

Either:

  • A) Delete db.js entirely and add the UNIQUE constraint directly in server/index.js schema (requires migration for existing DB)
  • B) Import and use db.js instead of the inline schema in server/index.js

Recommendation: Option A — delete db.js, add the UNIQUE constraint, add a migration path for existing databases.

Files

  • server/db.js — delete entirely
  • server/index.js — add UNIQUE constraint to leads.email, add migration logic

Severity

High — duplicate leads are being inserted; 409 error handler is dead code

## Problem There are TWO database schema definitions: 1. `server/index.js` (lines 135-148) — defines `leads` table WITHOUT a UNIQUE constraint on `email`. This is the one that actually runs. 2. `server/db.js` — defines `leads` table WITH UNIQUE constraint on `email`, plus migration logic. But `db.js` is NEVER imported anywhere. It is dead code. The result: duplicate email submissions are NOT prevented by the database. The 409 Conflict handler in server/index.js (line 541) catches `unique constraint` errors, but this constraint does not exist, so the handler can never fire. Every lead submission with a duplicate email will succeed with a new row in the database. ## Fix Either: - A) Delete db.js entirely and add the UNIQUE constraint directly in server/index.js schema (requires migration for existing DB) - B) Import and use db.js instead of the inline schema in server/index.js Recommendation: Option A — delete db.js, add the UNIQUE constraint, add a migration path for existing databases. ## Files - server/db.js — delete entirely - server/index.js — add UNIQUE constraint to leads.email, add migration logic ## Severity High — duplicate leads are being inserted; 409 error handler is dead code
null closed this issue 2026-05-17 21:35:14 -05:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: null/Queue-North-Website#120
No description provided.