Skip to content

fix: add indexes for watcher and retention queries - #655

Merged
0xNgoo merged 5 commits into
Anchor-kit:mainfrom
Hakimi674:fix/issue-599-add-database-indexes-for-watcher-and-retention
Sep 30, 2026
Merged

0xNgoo merged 5 commits into
Anchor-kit:mainfrom
Hakimi674:fix/issue-599-add-database-indexes-for-watcher-and-retention

Conversation

@Hakimi674

Copy link
Copy Markdown

Overview

This PR adds supporting database indexes for the watcher and retention/cleanup queries that filter by status and timestamps. It ensures migrations are repeatable and safe for both fresh and already-migrated SQLite and PostgreSQL databases, keeping query cost predictable as transaction and event tables grow.

Related Issue

Changes

🗄️ Database Indexes

  • [MODIFY] src/runtime/database/sql-database-adapter.ts
    • Add index creation for pending status plus created/expiry timestamps used by the current watcher and cleanup queries.
    • Make index migrations idempotent so they apply safely on both fresh and already-migrated databases.
    • Keep behavior compatible across SQLite and PostgreSQL.

✅ Tests

  • [MODIFY] tests/runtime/database/sql-database-adapter.test.ts
    • Assert the indexes are created and that migration is repeatable.
  • [MODIFY] tests/runtime/sql-adapter-watcher-tasks.test.ts
    • Confirm watcher query results are unchanged with the new indexes present.
  • [MODIFY] tests/runtime/sql-adapter-cleanup.test.ts
    • Confirm retention/cleanup query results are unchanged with the new indexes present.

Verification Results

bun test
✅ passing
Acceptance Criteria Status
Existing query results remain unchanged ✅ Watcher and cleanup tests assert identical results
A fresh and already-migrated database receives the indexes safely ✅ Idempotent migration covered by schema assertions
Indexes added for pending status plus created/expiry timestamps ✅ Added in sql-database-adapter.ts
Migrations repeatable for SQLite and PostgreSQL ✅ Idempotent index creation

Closes #599

@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

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

@0xNgoo
0xNgoo merged commit d91d8be into Anchor-kit:main Sep 30, 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.

Add database indexes for watcher and retention queries

3 participants