Skip to content

refactor(db): PR 2 — rename channel_badge_counts to badge_counts#2914

Merged
iscekic merged 3 commits intofeat/kilo-chat-migration-pr1from
feat/kilo-chat-migration-pr2
Apr 30, 2026
Merged

refactor(db): PR 2 — rename channel_badge_counts to badge_counts#2914
iscekic merged 3 commits intofeat/kilo-chat-migration-pr1from
feat/kilo-chat-migration-pr2

Conversation

@iscekic
Copy link
Copy Markdown
Contributor

@iscekic iscekic commented Apr 29, 2026

Stacked on #2907 (PR 1). Part of the kilo-chat migration plan (plan).

Summary

  • Rename Drizzle table channel_badge_countsbadge_counts and column channel_idbadge_bucket. The table becomes a generic per-user/per-bucket unread-count store; badge_bucket is whatever string the producer chooses (sandbox id today, conversation id later).
  • Update every reader/writer: services/notifications/src/dos/NotificationChannelDO.ts, apps/web/src/routers/user-router.ts (markChatRead input renamed channelIdbadgeBucket; getUnreadCounts returns badgeBucket instead of channelId), and apps/web/src/routers/user-router.test.ts.
  • Drizzle migration 0107_dapper_power_pack.sql performs the rename via ALTER TABLE … RENAME with PK/FK drop+re-add, then DELETE FROM badge_counts to wipe pre-cutover Stream-keyed rows (acceptable per the plan — pre-cutover unread state has no semantic mapping forward).

Notes

  • Mobile call sites (apps/mobile/src/components/kiloclaw/chat.tsx) are intentionally not updated — the plan ships the Stream-chat removal in PR 6 (Phase 14) and explicitly accepts these stale references in this PR.
  • Local drizzle-kit push was skipped because the local Postgres isn't running; CI applies migrations against a real DB.

Test plan

  • cd packages/db && pnpm typecheck
  • cd services/notifications && pnpm typecheck
  • cd apps/web && pnpm typecheck
  • pnpm lint clean for apps/web and services/notifications
  • pnpm run format:changed (no diff)
  • git grep -nE "channel_badge_counts|ChannelBadgeCount" returns zero hits outside packages/db/src/migrations/ and apps/mobile/
  • CI: apps/web jest suite (incl. user-router.test.ts) passes against real DB
  • CI: notifications + db typecheck/build pass

@iscekic iscekic self-assigned this Apr 29, 2026
Comment thread apps/web/src/routers/user-router.ts
Comment thread packages/db/src/migrations/0107_dapper_power_pack.sql
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 29, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/routers/user-router.ts 732 Carried forward: markChatRead now requires badgeBucket, but released mobile clients still send channelId, breaking badge clearing after backend deploy.
packages/db/src/migrations/0107_dapper_power_pack.sql 6 Carried forward: migration rebuilds PK/FK constraints before deleting all rows, causing avoidable table locking/scanning of discarded data.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
N/A N/A No additional observations
Files Reviewed (11 files)
  • apps/web/src/routers/user-router.test.ts - 0 issues
  • apps/web/src/routers/user-router.ts - 1 issue
  • packages/db/src/migrations/0107_dapper_power_pack.sql - 1 issue
  • packages/db/src/migrations/meta/0107_snapshot.json - generated, skipped
  • packages/db/src/migrations/meta/_journal.json - generated, skipped
  • packages/db/src/schema.ts - 0 issues
  • packages/notifications/src/badge-buckets.ts - 0 issues
  • packages/notifications/src/index.ts - 0 issues
  • pnpm-lock.yaml - lockfile, skipped
  • services/notifications/package.json - 0 issues
  • services/notifications/src/dos/NotificationChannelDO.ts - 0 issues

Reviewed by gpt-5.5-2026-04-23 · 786,985 tokens

The badge_counts.badge_bucket column is a free-form string. To prevent
namespace collisions as more surfaces start emitting badge updates
(per-instance today, per-conversation later), centralize bucket-key
derivation in @kilocode/notifications and route NotificationChannelDO
through it. Mirrors the presence-context builders in @kilocode/event-service.

Safe to introduce now without a data migration because PR 2's migration
already wipes badge_counts.
@iscekic iscekic merged commit 4b46ce7 into feat/kilo-chat-migration-pr1 Apr 30, 2026
2 checks passed
@iscekic iscekic deleted the feat/kilo-chat-migration-pr2 branch April 30, 2026 12:53
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.

1 participant