Skip to content

Commit cf87538

Browse files
committed
chore(drizzle): alias _query to query and enforce via lint
Prep for drizzle v1, which renames the RQB namespace from `query` to `_query`. Adds a runtime alias so both names work, rewrites every `.query` drizzle receiver to `._query`, and enforces the new name with an oxlint rule plus a type-aware CI check. - New `@kilocode/drizzle-shims` package patches PgDatabase and BaseSQLiteDatabase prototypes with a `_query` getter; transaction subclasses (`tx._query`) are covered automatically. - Side-effect imports added at every `drizzle(...)` construction site (packages/db client plus 12 DO service files). - `oxlint-plugin-drizzle.js` gains `prefer-underscore-query` (autofix, name-gated: db / ctx.db / this.db / tx / trx). - `scripts/drizzle-query-rename.ts` is a ts-morph codemod/verifier that walks every workspace tsconfig plus dev/ and scripts/ orphans and checks the drizzle `query` property by declaration location. Exposed as `pnpm drizzle:query-rename` and `pnpm drizzle:query-check`; the check runs as part of `pnpm validate`. - 372 call sites across 76 files rewritten.
1 parent c87cf72 commit cf87538

108 files changed

Lines changed: 1045 additions & 401 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.oxlintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@
119119
"@next/next/no-head-import-in-document": "error",
120120
"@next/next/no-script-component-in-head": "error",
121121
"drizzle/enforce-delete-with-where": ["error", { "drizzleObjectName": ["db", "ctx.db"] }],
122-
"drizzle/enforce-update-with-where": ["error", { "drizzleObjectName": ["db", "ctx.db"] }]
122+
"drizzle/enforce-update-with-where": ["error", { "drizzleObjectName": ["db", "ctx.db"] }],
123+
"drizzle/prefer-underscore-query": [
124+
"error",
125+
{ "drizzleObjectName": ["db", "ctx.db", "this.db", "tx", "trx"] }
126+
]
123127
},
124128
"overrides": [
125129
{

apps/web/src/app/admin/api/users/add-credit/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function POST(
2424
return warnAndCreateErrorResponse('Invalid email parameter');
2525
}
2626

27-
const user = await db.query.kilocode_users.findFirst({
27+
const user = await db._query.kilocode_users.findFirst({
2828
where: eq(kilocode_users.google_user_email, email),
2929
});
3030

apps/web/src/app/admin/api/users/credit-transactions/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function GET(
2020

2121
if (!kilo_user_id) throw new Error('kilo_user_id is required');
2222

23-
const transactions = await db.query.credit_transactions.findMany({
23+
const transactions = await db._query.credit_transactions.findMany({
2424
where: and(
2525
eq(credit_transactions.kilo_user_id, kilo_user_id),
2626
isNull(credit_transactions.organization_id)

apps/web/src/app/admin/api/users/payment-methods/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function GET(
1818

1919
if (!kilo_user_id) throw new Error('kilo_user_id is required');
2020

21-
const methods = await db.query.payment_methods.findMany({
21+
const methods = await db._query.payment_methods.findMany({
2222
where: eq(payment_methods.user_id, kilo_user_id),
2323
orderBy: desc(payment_methods.created_at),
2424
});

apps/web/src/app/admin/api/users/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export async function GET(
176176
const orderFunction = sortOrder === 'asc' ? asc : desc;
177177
const orderCondition = orderFunction(kilocode_users[sortField]);
178178

179-
const users = await db.query.kilocode_users.findMany({
179+
const users = await db._query.kilocode_users.findMany({
180180
where: whereCondition,
181181
orderBy: orderCondition,
182182
limit: limit,
@@ -196,7 +196,7 @@ export async function GET(
196196
const notes =
197197
userIds.length <= 0
198198
? []
199-
: await db.query.user_admin_notes.findMany({
199+
: await db._query.user_admin_notes.findMany({
200200
where: inArray(user_admin_notes.kilo_user_id, userIds),
201201
orderBy: desc(user_admin_notes.created_at),
202202
});

apps/web/src/app/admin/organizations/[id]/webhooks/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function AdminOrganizationWebhooksPage({
1818
const { id } = await params;
1919
const organizationId = decodeURIComponent(id);
2020

21-
const organization = await db.query.organizations.findFirst({
21+
const organization = await db._query.organizations.findFirst({
2222
columns: {
2323
id: true,
2424
name: true,

apps/web/src/app/admin/users/[id]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function getUserData(userId: string): Promise<UserDetailProps | null> {
2727
return null;
2828
}
2929

30-
const notes = await db.query.user_admin_notes.findMany({
30+
const notes = await db._query.user_admin_notes.findMany({
3131
where: eq(user_admin_notes.kilo_user_id, userId),
3232
orderBy: desc(user_admin_notes.created_at),
3333
});
@@ -36,7 +36,7 @@ async function getUserData(userId: string): Promise<UserDetailProps | null> {
3636

3737
const admins =
3838
adminIds.length > 0
39-
? await db.query.kilocode_users.findMany({
39+
? await db._query.kilocode_users.findMany({
4040
where: inArray(kilocode_users.id, adminIds),
4141
limit: 50,
4242
})
@@ -68,7 +68,7 @@ async function getUserData(userId: string): Promise<UserDetailProps | null> {
6868

6969
// Fetch auto-top-up config
7070
const autoTopUpConfig =
71-
(await db.query.auto_top_up_configs.findFirst({
71+
(await db._query.auto_top_up_configs.findFirst({
7272
where: eq(auto_top_up_configs.owned_by_user_id, userId),
7373
})) ?? null;
7474

apps/web/src/app/admin/users/[id]/webhooks/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function AdminUserWebhooksPage({
1818
const { id } = await params;
1919
const userId = decodeURIComponent(id);
2020

21-
const user = await db.query.kilocode_users.findFirst({
21+
const user = await db._query.kilocode_users.findFirst({
2222
columns: {
2323
id: true,
2424
google_user_email: true,

apps/web/src/app/api/cron/deployment-threat-scan/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function GET(request: Request) {
3838

3939
// Get deployments pending scan, oldest first (by last_deployed_at)
4040
// Uses partial index idx_deployments_threat_status_pending for efficient queries
41-
const pendingDeployments = await db.query.deployments.findMany({
41+
const pendingDeployments = await db._query.deployments.findMany({
4242
where: eq(deployments.threat_status, 'pending_scan'),
4343
orderBy: asc(deployments.last_deployed_at),
4444
limit: 25,

apps/web/src/app/api/dev/create-kilocode-org/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function POST(_request: NextRequest): Promise<NextResponse> {
115115
console.log('[DEV CREATE KILOCODE ORG] Stripe customer ID created');
116116

117117
// Verify membership was created
118-
const newMembership = await db.query.organization_memberships.findFirst({
118+
const newMembership = await db._query.organization_memberships.findFirst({
119119
where: and(
120120
eq(organization_memberships.organization_id, DEV_ORG_ID),
121121
eq(organization_memberships.kilo_user_id, user.id)

0 commit comments

Comments
 (0)