Skip to content

feat(db): optimize schema with performance indexes and constraints#44

Merged
Abidoyesimze merged 3 commits intoNeurowealth:mainfrom
kryputh:issue-42-db-optimizations
Apr 28, 2026
Merged

feat(db): optimize schema with performance indexes and constraints#44
Abidoyesimze merged 3 commits intoNeurowealth:mainfrom
kryputh:issue-42-db-optimizations

Conversation

@kryputh
Copy link
Copy Markdown
Contributor

@kryputh kryputh commented Apr 25, 2026

Description

This Pull Request addresses issue #42 by reviewing and optimizing the schema.prisma file. The changes focus on improving query performance and ensuring data integrity through the addition of strategic indexes and the removal of redundant ones.

Changes

  • User Model: Removed redundant index on walletAddress (already covered by @unique).
  • Session Model:
    • Removed redundant index on token.
    • Added indexes on expiresAt and a composite index on [userId, expiresAt] to optimize session cleanup and validation.
  • Position Model:
    • Added indexes on status and [userId, status] for faster filtering of active/closed positions.
    • Added a composite index on [protocolName, assetSymbol] and a single index on assetSymbol for protocol-based queries.
  • Transaction Model:
    • Removed redundant index on txHash.
    • Added indexes on type, status, createdAt, and [userId, createdAt] to accelerate historical transaction lookups and dashboard analytics.
  • AgentLog Model: Added indexes on status and [userId, status] to improve agent performance monitoring.
  • ProcessedEvent Model: Added an index on ledger for faster blockchain event tracking.

Integrity & Performance

  • All new indexes are non-breaking and do not modify existing data structures.
  • Redundant indexes were removed to reduce storage overhead and improve write latency on frequently updated tables like users and sessions.
  • A new migration file 20260425140000_add_performance_indexes has been generated containing the corresponding SQL.

Verification

  • prisma generate was executed successfully to update the Prisma Client.
  • The schema was validated for consistency.

Closes #42

This commit adds several performance-improving indexes to the User, Session, Position, Transaction, and AgentLog models. It also removes redundant indexes on unique fields to optimize storage and write performance.
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 25, 2026

@kryputh Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@robertocarlous
Copy link
Copy Markdown
Contributor

resolve conflict

1 similar comment
@robertocarlous
Copy link
Copy Markdown
Contributor

resolve conflict

@Abidoyesimze Abidoyesimze merged commit 4c3aa84 into Neurowealth:main Apr 28, 2026
1 check passed
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.

Enhance Prisma schema with more constraints or indexes if needed

3 participants