Make orgId nullable (#113)

This commit is contained in:
Chris Estreich 2025-06-20 19:02:21 -07:00 committed by GitHub
parent 45d7565605
commit ff5a94001c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 10 additions and 3 deletions

View file

@ -106,6 +106,6 @@ jobs:
run: pnpm install
- name: Migrate production database
run: npx drizzle-kit migrate
working-directory: apps/db
working-directory: packages/db
env:
DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}

View file

@ -21,7 +21,7 @@ type Table = 'events' | 'messages';
type AnalyticsEvent = {
id: string;
orgId: string;
orgId: string | null;
userId: string;
timestamp: number;
event: RooCodeTelemetryEvent;
@ -36,6 +36,7 @@ export const captureEvent = async ({ event, ...rest }: AnalyticsEvent) => {
table = 'messages';
const { taskId, mode, message } = event.properties;
const { ts, type, ask, say, text, reasoning, partial } = message;
value = {
...rest,
taskId,
@ -48,6 +49,7 @@ export const captureEvent = async ({ event, ...rest }: AnalyticsEvent) => {
reasoning,
partial,
};
break;
}
default: {
@ -95,10 +97,12 @@ export const getUsage = async ({
}
const userFilter = effectiveUserId ? 'AND userId = {userId: String}' : '';
const queryParams: Record<string, string | number> = {
orgId: orgId!,
timePeriod,
};
if (effectiveUserId) {
queryParams.userId = effectiveUserId;
}

View file

@ -10,7 +10,7 @@ import { analytics } from '@/lib/server';
const messageSchema = z.object({
id: z.string(),
orgId: z.string(),
orgId: z.string().nullable(),
userId: z.string(),
taskId: z.string(),
mode: z.string().nullable(),

View file

@ -32,3 +32,5 @@ CREATE TABLE default.events
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ORDER BY (id, type, timestamp)
SETTINGS index_granularity = 8192;
ALTER TABLE default.events MODIFY COLUMN `orgId` Nullable(String);

View file

@ -18,3 +18,4 @@ ORDER BY (id, timestamp)
SETTINGS index_granularity = 8192;
ALTER TABLE default.messages ADD COLUMN mode Nullable(String);
ALTER TABLE default.messages MODIFY COLUMN `orgId` Nullable(String);