Indexing

db.transactions.createIndex({ consumer_id: 1, created_at: -1 });
db.transactions.createIndex({ provider_id: 1, created_at: -1 });
db.transactions.createIndex({ "solana.signature": 1 }, { unique: true });

db.projects.createIndex({ slug: 1 }, { unique: true });
db.projects.createIndex({ owner_id: 1 });

db.solana_tx_cache.createIndex({ signature: 1 }, { unique: true });
db.solana_tx_cache.createIndex({ expires_at: 1 }, { expireAfterSeconds: 0 });

Recommended Indexes (Your DB):

If using MongoDB:

// Payments
db.payments.createIndex({ "payment_id": 1 }, { unique: true });
db.payments.createIndex({ "tx_signature": 1 }, { sparse: true });
db.payments.createIndex({ "user_id": 1, "created_at": -1 });

// Access grants
db.access.createIndex({ "user_id": 1, "resource_id": 1 });
db.access.createIndex({ "payment_id": 1 });

If using PostgreSQL:

-- Payments
CREATE INDEX idx_payments_user ON payments(user_id, created_at DESC);
CREATE INDEX idx_payments_tx ON payments(tx_signature);
CREATE UNIQUE INDEX idx_payments_id ON payments(payment_id);

-- Access grants
CREATE INDEX idx_access_user_resource ON access(user_id, resource_id);

Last updated