fix/error: relation "failed_relay_publishes" does not exist#225
fix/error: relation "failed_relay_publishes" does not exist#225RiH-137 wants to merge 1 commit intoshopstr-eng:mainfrom
Conversation
…creation + migration support in DB
|
@RiH-137 is attempting to deploy a commit to the shopstr-eng Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a database error (relation "failed_relay_publishes" does not exist) by adding proper table creation, migration support, and schema initialization. The solution ensures the failed_relay_publishes table exists before querying it, adds the missing event_data column needed for retries, and removes an invalid join to a non-existent events table.
Changes:
- Added
failed_relay_publishestable definition with indexes to database schema and initialization code - Implemented migration logic to add
event_datacolumn to existing tables - Updated failed publish tracking endpoints to self-heal schema and store full event payloads
- Modified API endpoints to query
failed_relay_publishesdirectly instead of joining non-existenteventstable
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| db/schema.sql | Adds failed_relay_publishes table definition and indexes to the base schema |
| utils/db/db-service.ts | Adds table creation and migration logic for event_data column in initialization |
| pages/api/db/get-failed-publishes.ts | Adds self-healing schema logic and removes invalid events table join |
| pages/api/db/track-failed-publish.ts | Adds schema self-healing and stores full event payload with event_data |
| pages/api/db/clear-failed-publish.ts | Adds table creation logic for consistency across endpoints |
| utils/db/db-client.ts | Updates function signature to accept optional NostrEvent parameter |
| utils/nostr/nostr-helper-functions.ts | Updates call sites to pass full event object to tracking function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| IF NOT EXISTS ( | ||
| SELECT 1 FROM information_schema.columns | ||
| WHERE table_name = 'failed_relay_publishes' AND column_name = 'event_data' | ||
| ) THEN | ||
| ALTER TABLE failed_relay_publishes ADD COLUMN event_data TEXT; | ||
| END IF; |
There was a problem hiding this comment.
The migration logic attempts to add event_data column to failed_relay_publishes table, but this table is already created with the event_data column at lines 187-193. This migration block is redundant and may cause confusion. If the migration is intended for existing databases that don't have this column, it should be placed before the table creation block or the table creation should not include this column initially.
| IF NOT EXISTS ( | |
| SELECT 1 FROM information_schema.columns | |
| WHERE table_name = 'failed_relay_publishes' AND column_name = 'event_data' | |
| ) THEN | |
| ALTER TABLE failed_relay_publishes ADD COLUMN event_data TEXT; | |
| END IF; |
| await client.query(` | ||
| ALTER TABLE failed_relay_publishes | ||
| ADD COLUMN IF NOT EXISTS event_data TEXT | ||
| `); | ||
|
|
There was a problem hiding this comment.
The ALTER TABLE statement for adding the event_data column is executed on every request to this endpoint. This is inefficient and should be removed since the column is now part of the initial table creation schema (lines 26-33). Schema migrations should be handled during initialization, not on every API request.
| await client.query(` | |
| ALTER TABLE failed_relay_publishes | |
| ADD COLUMN IF NOT EXISTS event_data TEXT | |
| `); |
| await client.query(` | ||
| ALTER TABLE failed_relay_publishes | ||
| ADD COLUMN IF NOT EXISTS event_data TEXT | ||
| `); | ||
|
|
There was a problem hiding this comment.
The ALTER TABLE statement for adding the event_data column is executed on every request to this endpoint. This is inefficient and should be removed since the column is now part of the initial table creation schema (lines 19-26). Schema migrations should be handled during initialization, not on every API request.
| await client.query(` | |
| ALTER TABLE failed_relay_publishes | |
| ADD COLUMN IF NOT EXISTS event_data TEXT | |
| `); |
…creation + migration support in DB
Description
error: relation "failed_relay_publishes" does not exist
code: 42P01
Resolved or fixed issue
#224
Root Cause
get-failed-publishesqueriedfailed_relay_publishesbefore ensuring the table exists.eventstable.event_data) needed for retries.Solution
failed_relay_publishestable and indexes in DB schema/bootstrap.event_data(ALTER TABLE ... ADD COLUMN IF NOT EXISTS).eventstable and fetched data directly fromfailed_relay_publishes.Files Changed (Path)
db/schema.sqlutils/db/db-service.tspages/api/db/get-failed-publishes.tspages/api/db/track-failed-publish.tspages/api/db/clear-failed-publish.tsutils/db/db-client.tsutils/nostr/nostr-helper-functions.tsOutcome / Impact
42P01(relation does not exist) for failed publish endpoints.GET /api/db/get-failed-publishesnow returns200reliably on fresh/local DBs.event_datais stored and can be replayed.