Skip to content

[AISAGE-729] chore(db): drop unused tables - #7765

Merged
chrarnoldus merged 4 commits into
mainfrom
chore/drop-unused-db-tables
Oct 16, 2026
Merged

chrarnoldus merged 4 commits into
mainfrom
chore/drop-unused-db-tables

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Important

Stacked on #7767, which removes all runtime references to these tables first, because rollout is gradual. Merge this only after #7767 is fully rolled out to production. This PR contains only the schema change and the generated migration.

Drops the shared PostgreSQL tables that nothing in the codebase reads or writes anymore. I checked every pgTable/pgView in packages/db/src/schema.ts for references by export name and SQL name in non-test code, with the GDPR soft-delete and migrations excluded. I also searched the Kilo-Org GitHub org, including kilocode-dbt and the data-ops Snowflake replication config.

Table Why it can go
free_model_usage #7534 removed the last writer and reader (rate limiting moved to a Vercel Firewall rule) and said the table would stay "until the table is dropped". All that was left was the hourly cleanup cron and the soft-delete FK nulling, and #7767 removes both. #7534 is already live in production (deploy of 8d7dc6c947 succeeded).
user_period_cache Has never been read or written in this repository (the "wrapped"/share-token cache). The only reference was the delete in softDeleteUser.
kilo_pass_org_term_transitions Scaffolded with Kilo Pass for Organizations (#4501) but never used. Agreements only ever use the seeded -v1 term versions, and the table can be re-added if term migrations are ever built.

The migration is generated (0281_drop_unused_tables.sql: three DROP TABLE ... CASCADE). Only outbound FKs exist and no views depend on these tables. None of them is replicated to Snowflake or referenced by dbt.

Unused tables kept on purpose

  • stripe_early_fraud_warning_actions: production code never writes or reads it, but it is the action ledger required by .specs/stripe-early-fraud-warnings.md. The spec rolls out in stages: the persistence foundation ships inert before action processing. The tests intentionally assert that observation-only ingestion creates no action rows.

Follow-up candidate (not in this PR)

  • slack_bot_requests: nothing has written it since feat(bot): route Slack app through Chat SDK #2738 (Apr 2026), so the admin Slack bot stats page only shows stale data. It's still read by that page, replicated to Snowflake (data-ops/snowflake/config.py), and has a dbt staging model (stg_backend__slack_bot_requests). Dropping it needs coordination with analytics.

Verification

Visual Changes

N/A

Reviewer Notes

@chrarnoldus chrarnoldus self-assigned this Oct 16, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

This PR cleanly removes three unused tables (free_model_usage, user_period_cache, kilo_pass_org_term_transitions), their cron route/config, and the corresponding soft-delete logic; I verified there are no remaining code, raw-SQL, or config references and that the generated migration/snapshot/journal are internally consistent.

Files Reviewed (9 files)
  • apps/web/src/app/api/cron/cleanup-free-model-usage/route.ts
  • apps/web/src/app/api/cron/cleanup-free-model-usage/route.test.ts
  • apps/web/src/lib/user/index.ts
  • apps/web/src/lib/user/index.test.ts
  • apps/web/vercel.json
  • packages/db/src/schema.ts
  • packages/db/src/migrations/0281_drop_unused_tables.sql
  • packages/db/src/migrations/meta/0281_snapshot.json
  • packages/db/src/migrations/meta/_journal.json

Verification Notes

  • Repo-wide search (excluding packages/db/src/migrations/**) for free_model_usage, FreeModelUsage, user_period_cache, UserPeriodCache, kilo_pass_org_term_transitions, PeriodType, and cleanup-free-model-usage returns zero remaining references; only historical migrations and the new drop reference the tables.
  • Snapshot diff between 0280 and 0281 removes exactly the three intended tables; _journal.json idx 281 follows 280, and 0281_snapshot.prevId matches 0280_snapshot.id.
  • Only outbound FKs exist, so DROP TABLE ... CASCADE matches the three intended objects.
  • @kilocode/db is "private": true, so removing the FreeModelUsage/PeriodCache/PeriodType exports is not a published-API break.
  • Operational note (no action requested): as the PR description already states, applying this destructive migration while a pre-[AISAGE-729] refactor(gateway): replace free model database rate limit with Vercel Firewall rule #7534 AI gateway build is still serving would break free-model requests; ensure the AI gateway is on a post-[AISAGE-729] refactor(gateway): replace free model database rate limit with Vercel Firewall rule #7534 build before/at migration time.

Reviewed by deepseek-v4.1-flash · Input: 71K · Output: 9.4K · Cached: 976K

Review guidance: REVIEW.md from base branch main

@chrarnoldus
chrarnoldus changed the base branch from main to chore/stop-using-dropped-tables October 16, 2026 14:20

@iscekic iscekic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from chore/stop-using-dropped-tables to main October 16, 2026 15:19
@chrarnoldus
chrarnoldus enabled auto-merge October 16, 2026 15:53
@chrarnoldus
chrarnoldus added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit 2971309 Oct 16, 2026
85 checks passed
@chrarnoldus
chrarnoldus deleted the chore/drop-unused-db-tables branch October 16, 2026 15:59
@chrarnoldus chrarnoldus changed the title chore(db): drop unused tables [AISAGE-729] chore(db): drop unused tables Oct 21, 2026
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.

2 participants