@ -43,6 +43,16 @@ func (n *N) applySchema(ctx context.Context) error {
// NOTE: NostrUser unifies both NIP-01 author tracking and WoT social graph
// NOTE: NostrUser unifies both NIP-01 author tracking and WoT social graph
"CREATE CONSTRAINT nostrUser_pubkey IF NOT EXISTS FOR (n:NostrUser) REQUIRE n.pubkey IS UNIQUE" ,
"CREATE CONSTRAINT nostrUser_pubkey IF NOT EXISTS FOR (n:NostrUser) REQUIRE n.pubkey IS UNIQUE" ,
// ============================================================
// === OPTIONAL: Addressable Event Support (NIP-33) ===
// These support parameterized replaceable events (kinds 30000-39999)
// ============================================================
// OPTIONAL (NIP-33): naddr uniqueness for addressable events
// Format: pubkey:kind:dtag (colon-delimited coordinate)
// Ensures only one event per author+kind+d-tag combination
"CREATE CONSTRAINT naddr_unique IF NOT EXISTS FOR (e:Event) REQUIRE e.naddr IS UNIQUE" ,
// ============================================================
// ============================================================
// === OPTIONAL: Internal Relay Operations ===
// === OPTIONAL: Internal Relay Operations ===
// These are used for relay state management, not NIP-01 queries
// These are used for relay state management, not NIP-01 queries
@ -116,6 +126,15 @@ func (n *N) applySchema(ctx context.Context) error {
// Optimizes queries like: {"kinds": [1], "since": <ts>, "until": <ts>}
// Optimizes queries like: {"kinds": [1], "since": <ts>, "until": <ts>}
"CREATE INDEX event_kind_created_at IF NOT EXISTS FOR (e:Event) ON (e.kind, e.created_at)" ,
"CREATE INDEX event_kind_created_at IF NOT EXISTS FOR (e:Event) ON (e.kind, e.created_at)" ,
// ============================================================
// === OPTIONAL: Addressable Event Indexes (NIP-33) ===
// Support parameterized replaceable events (kinds 30000-39999)
// ============================================================
// OPTIONAL (NIP-33): Event.naddr index for addressable event lookups
// Enables fast queries by naddr coordinate (pubkey:kind:dtag)
"CREATE INDEX event_naddr IF NOT EXISTS FOR (e:Event) ON (e.naddr)" ,
// ============================================================
// ============================================================
// === OPTIONAL: Internal Relay Operation Indexes ===
// === OPTIONAL: Internal Relay Operation Indexes ===
// Used for relay-internal operations, not NIP-01 queries
// Used for relay-internal operations, not NIP-01 queries
@ -205,6 +224,9 @@ func (n *N) dropAll(ctx context.Context) error {
// Legacy constraint (removed in migration)
// Legacy constraint (removed in migration)
"DROP CONSTRAINT author_pubkey_unique IF EXISTS" ,
"DROP CONSTRAINT author_pubkey_unique IF EXISTS" ,
// OPTIONAL (NIP-33) constraints
"DROP CONSTRAINT naddr_unique IF EXISTS" ,
// OPTIONAL (Internal) constraints
// OPTIONAL (Internal) constraints
"DROP CONSTRAINT marker_key_unique IF EXISTS" ,
"DROP CONSTRAINT marker_key_unique IF EXISTS" ,
@ -232,6 +254,9 @@ func (n *N) dropAll(ctx context.Context) error {
// RECOMMENDED (Performance) indexes
// RECOMMENDED (Performance) indexes
"DROP INDEX event_kind_created_at IF EXISTS" ,
"DROP INDEX event_kind_created_at IF EXISTS" ,
// OPTIONAL (NIP-33) indexes
"DROP INDEX event_naddr IF EXISTS" ,
// OPTIONAL (Internal) indexes
// OPTIONAL (Internal) indexes
"DROP INDEX event_serial IF EXISTS" ,
"DROP INDEX event_serial IF EXISTS" ,
"DROP INDEX event_expiration IF EXISTS" ,
"DROP INDEX event_expiration IF EXISTS" ,