Skip to content

fix/error: relation "failed_relay_publishes" does not exist#225

Open
RiH-137 wants to merge 1 commit intoshopstr-eng:mainfrom
RiH-137:fix/added-indexes-migration-support-in-DB
Open

fix/error: relation "failed_relay_publishes" does not exist#225
RiH-137 wants to merge 1 commit intoshopstr-eng:mainfrom
RiH-137:fix/added-indexes-migration-support-in-DB

Conversation

@RiH-137
Copy link

@RiH-137 RiH-137 commented Feb 14, 2026

…creation + migration support in DB

Description

error: relation "failed_relay_publishes" does not exist
code: 42P01

Resolved or fixed issue

#224

Root Cause

  1. get-failed-publishes queried failed_relay_publishes before ensuring the table exists.
  2. The same endpoint also joined a non-existent events table.
  3. Failed publish tracking did not consistently store event payload (event_data) needed for retries.

Solution

  1. Added failed_relay_publishes table and indexes in DB schema/bootstrap.
  2. Added migration support for event_data (ALTER TABLE ... ADD COLUMN IF NOT EXISTS).
  3. Updated API endpoints to self-heal schema on request path where needed.
  4. Removed invalid join to events table and fetched data directly from failed_relay_publishes.
  5. Updated client and publish call-sites to send/store full failed event payload.

Files Changed (Path)

  1. db/schema.sql
  2. utils/db/db-service.ts
  3. pages/api/db/get-failed-publishes.ts
  4. pages/api/db/track-failed-publish.ts
  5. pages/api/db/clear-failed-publish.ts
  6. utils/db/db-client.ts
  7. utils/nostr/nostr-helper-functions.ts

Outcome / Impact

  • Fixed 42P01 (relation does not exist) for failed publish endpoints.
  • GET /api/db/get-failed-publishes now returns 200 reliably on fresh/local DBs.
  • Retry flow is now more reliable because event_data is stored and can be replayed.

Copilot AI review requested due to automatic review settings February 14, 2026 13:32
@vercel
Copy link

vercel bot commented Feb 14, 2026

@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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_publishes table definition with indexes to database schema and initialization code
  • Implemented migration logic to add event_data column to existing tables
  • Updated failed publish tracking endpoints to self-heal schema and store full event payloads
  • Modified API endpoints to query failed_relay_publishes directly instead of joining non-existent events table

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.

Comment on lines +225 to +231

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;
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +39
await client.query(`
ALTER TABLE failed_relay_publishes
ADD COLUMN IF NOT EXISTS event_data TEXT
`);

Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
await client.query(`
ALTER TABLE failed_relay_publishes
ADD COLUMN IF NOT EXISTS event_data TEXT
`);

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +32
await client.query(`
ALTER TABLE failed_relay_publishes
ADD COLUMN IF NOT EXISTS event_data TEXT
`);

Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
await client.query(`
ALTER TABLE failed_relay_publishes
ADD COLUMN IF NOT EXISTS event_data TEXT
`);

Copilot uses AI. Check for mistakes.
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

Comments