mirror of
https://github.com/block/buzz.git
synced 2026-10-27 04:30:52 +00:00
NIP-33: d-tag keyed replacement for parameterized replaceable events (#246)
This commit is contained in:
17
scripts/backfill-d-tag.sql
Normal file
17
scripts/backfill-d-tag.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- Backfill d_tag for existing NIP-33 range events (kind 30000–39999).
|
||||
-- Idempotent: only updates rows where d_tag is still NULL.
|
||||
-- Includes soft-deleted rows so the column is fully populated.
|
||||
-- Run once after adding the d_tag column to the events table.
|
||||
--
|
||||
-- Usage: psql $DATABASE_URL -f scripts/backfill-d-tag.sql
|
||||
|
||||
UPDATE events
|
||||
SET d_tag = COALESCE(
|
||||
(SELECT elem->>1
|
||||
FROM jsonb_array_elements(tags) AS elem
|
||||
WHERE elem->>0 = 'd'
|
||||
LIMIT 1),
|
||||
''
|
||||
)
|
||||
WHERE kind BETWEEN 30000 AND 39999
|
||||
AND d_tag IS NULL;
|
||||
@@ -151,6 +151,17 @@ else
|
||||
sleep 2
|
||||
done
|
||||
success "Migrations applied via pgschema"
|
||||
|
||||
# Run data backfills (idempotent — safe to re-run).
|
||||
BACKFILL_DIR="${REPO_ROOT}/scripts"
|
||||
if [[ -f "${BACKFILL_DIR}/backfill-d-tag.sql" ]]; then
|
||||
log "Running d_tag backfill for NIP-33 events..."
|
||||
if psql "${DATABASE_URL}" -f "${BACKFILL_DIR}/backfill-d-tag.sql" 2>/dev/null; then
|
||||
success "d_tag backfill complete"
|
||||
else
|
||||
warn "d_tag backfill failed (relay startup will retry automatically)"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
error "pgschema not found at ${PGSCHEMA}. Run: ./bin/hermit install pgschema"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user