Open History to see the last commit
1import { relations, sql } from 'drizzle-orm'
2import {
3 sqliteTable,
4 text,
5 integer,
6 index,
7 check,
8 primaryKey,
9} from 'drizzle-orm/sqlite-core'
10import type { AnySQLiteColumn } from 'drizzle-orm/sqlite-core'
11
12import type { CapabilityMap } from '#/lib/capabilities.ts'
13
14export const user = sqliteTable('user', {
15 id: text('id').primaryKey(),
16 name: text('name').notNull(),
17 email: text('email').notNull().unique(),
18 emailVerified: integer('email_verified', { mode: 'boolean' })
19 .default(false)
20 .notNull(),
21 image: text('image'),
22 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
23 updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
24 .$onUpdate(() => new Date())
25 .notNull(),
26})
27
28export const session = sqliteTable(
29 'session',
30 {
31 id: text('id').primaryKey(),
32 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
33 token: text('token').notNull().unique(),
34 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
35 updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
36 .$onUpdate(() => new Date())
37 .notNull(),
38 ipAddress: text('ip_address'),
39 userAgent: text('user_agent'),
40 userId: text('user_id')
41 .notNull()
42 .references(() => user.id, { onDelete: 'cascade' }),
43 },
44 (table) => [index('session_userId_idx').on(table.userId)],
45)
46
47export const account = sqliteTable(
48 'account',
49 {
50 id: text('id').primaryKey(),
51 accountId: text('account_id').notNull(),
52 providerId: text('provider_id').notNull(),
53 userId: text('user_id')
54 .notNull()
55 .references(() => user.id, { onDelete: 'cascade' }),
56 accessToken: text('access_token'),
57 refreshToken: text('refresh_token'),
58 idToken: text('id_token'),
59 accessTokenExpiresAt: integer('access_token_expires_at', {
60 mode: 'timestamp_ms',
61 }),
62 refreshTokenExpiresAt: integer('refresh_token_expires_at', {
63 mode: 'timestamp_ms',
64 }),
65 scope: text('scope'),
66 password: text('password'),
67 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
68 updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
69 .$onUpdate(() => new Date())
70 .notNull(),
71 },
72 (table) => [index('account_userId_idx').on(table.userId)],
73)
74
75export const verification = sqliteTable(
76 'verification',
77 {
78 id: text('id').primaryKey(),
79 identifier: text('identifier').notNull(),
80 value: text('value').notNull(),
81 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
82 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
83 updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
84 .$onUpdate(() => new Date())
85 .notNull(),
86 },
87 (table) => [index('verification_identifier_idx').on(table.identifier)],
88)
89
90export const agentHost = sqliteTable(
91 'agent_host',
92 {
93 id: text('id').primaryKey(),
94 name: text('name'),
95 userId: text('user_id').references(() => user.id, { onDelete: 'cascade' }),
96 defaultCapabilities: text('default_capabilities'),
97 publicKey: text('public_key'),
98 kid: text('kid'),
99 jwksUrl: text('jwks_url'),
100 enrollmentTokenHash: text('enrollment_token_hash'),
101 enrollmentTokenExpiresAt: integer('enrollment_token_expires_at', {
102 mode: 'timestamp_ms',
103 }),
104 status: text('status').default('active').notNull(),
105 activatedAt: integer('activated_at', { mode: 'timestamp_ms' }),
106 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }),
107 lastUsedAt: integer('last_used_at', { mode: 'timestamp_ms' }),
108 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
109 updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
110 },
111 (table) => [
112 index('agentHost_userId_idx').on(table.userId),
113 index('agentHost_kid_idx').on(table.kid),
114 index('agentHost_enrollmentTokenHash_idx').on(table.enrollmentTokenHash),
115 index('agentHost_status_idx').on(table.status),
116 ],
117)
118
119export const agent = sqliteTable(
120 'agent',
121 {
122 id: text('id').primaryKey(),
123 name: text('name').notNull(),
124 userId: text('user_id').references(() => user.id, { onDelete: 'cascade' }),
125 hostId: text('host_id')
126 .notNull()
127 .references(() => agentHost.id, { onDelete: 'cascade' }),
128 status: text('status').default('active').notNull(),
129 mode: text('mode').default('delegated').notNull(),
130 publicKey: text('public_key').notNull(),
131 kid: text('kid'),
132 jwksUrl: text('jwks_url'),
133 lastUsedAt: integer('last_used_at', { mode: 'timestamp_ms' }),
134 activatedAt: integer('activated_at', { mode: 'timestamp_ms' }),
135 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }),
136 metadata: text('metadata'),
137 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
138 updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
139 },
140 (table) => [
141 index('agent_userId_idx').on(table.userId),
142 index('agent_hostId_idx').on(table.hostId),
143 index('agent_status_idx').on(table.status),
144 index('agent_kid_idx').on(table.kid),
145 ],
146)
147
148export const agentCapabilityGrant = sqliteTable(
149 'agent_capability_grant',
150 {
151 id: text('id').primaryKey(),
152 agentId: text('agent_id')
153 .notNull()
154 .references(() => agent.id, { onDelete: 'cascade' }),
155 capability: text('capability').notNull(),
156 deniedBy: text('denied_by').references(() => user.id, {
157 onDelete: 'cascade',
158 }),
159 grantedBy: text('granted_by').references(() => user.id, {
160 onDelete: 'cascade',
161 }),
162 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }),
163 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
164 updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
165 status: text('status').default('active').notNull(),
166 reason: text('reason'),
167 constraints: text('constraints'),
168 },
169 (table) => [
170 index('agentCapabilityGrant_agentId_idx').on(table.agentId),
171 index('agentCapabilityGrant_capability_idx').on(table.capability),
172 index('agentCapabilityGrant_grantedBy_idx').on(table.grantedBy),
173 index('agentCapabilityGrant_status_idx').on(table.status),
174 ],
175)
176
177export const approvalRequest = sqliteTable(
178 'approval_request',
179 {
180 id: text('id').primaryKey(),
181 method: text('method').notNull(),
182 agentId: text('agent_id').references(() => agent.id, {
183 onDelete: 'cascade',
184 }),
185 hostId: text('host_id').references(() => agentHost.id, {
186 onDelete: 'cascade',
187 }),
188 userId: text('user_id').references(() => user.id, { onDelete: 'cascade' }),
189 capabilities: text('capabilities'),
190 status: text('status').default('pending').notNull(),
191 userCodeHash: text('user_code_hash'),
192 loginHint: text('login_hint'),
193 bindingMessage: text('binding_message'),
194 clientNotificationToken: text('client_notification_token'),
195 clientNotificationEndpoint: text('client_notification_endpoint'),
196 deliveryMode: text('delivery_mode'),
197 interval: integer('interval').notNull(),
198 lastPolledAt: integer('last_polled_at', { mode: 'timestamp_ms' }),
199 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
200 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
201 updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
202 },
203 (table) => [
204 index('approvalRequest_agentId_idx').on(table.agentId),
205 index('approvalRequest_hostId_idx').on(table.hostId),
206 index('approvalRequest_userId_idx').on(table.userId),
207 index('approvalRequest_status_idx').on(table.status),
208 ],
209)
210
211export const apikey = sqliteTable(
212 'apikey',
213 {
214 id: text('id').primaryKey(),
215 configId: text('config_id').default('default').notNull(),
216 name: text('name'),
217 start: text('start'),
218 referenceId: text('reference_id').notNull(),
219 prefix: text('prefix'),
220 key: text('key').notNull(),
221 refillInterval: integer('refill_interval'),
222 refillAmount: integer('refill_amount'),
223 lastRefillAt: integer('last_refill_at', { mode: 'timestamp_ms' }),
224 enabled: integer('enabled', { mode: 'boolean' }).default(true),
225 rateLimitEnabled: integer('rate_limit_enabled', {
226 mode: 'boolean',
227 }).default(true),
228 rateLimitTimeWindow: integer('rate_limit_time_window').default(86400000),
229 rateLimitMax: integer('rate_limit_max').default(10),
230 requestCount: integer('request_count').default(0),
231 remaining: integer('remaining'),
232 lastRequest: integer('last_request', { mode: 'timestamp_ms' }),
233 expiresAt: integer('expires_at', { mode: 'timestamp_ms' }),
234 createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
235 updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
236 permissions: text('permissions'),
237 metadata: text('metadata'),
238 },
239 (table) => [
240 index('apikey_configId_idx').on(table.configId),
241 index('apikey_referenceId_idx').on(table.referenceId),
242 index('apikey_key_idx').on(table.key),
243 ],
244)
245
246export const userRelations = relations(user, ({ many }) => ({
247 sessions: many(session),
248 accounts: many(account),
249 agentHosts: many(agentHost),
250 agents: many(agent),
251 agentCapabilityGrants: many(agentCapabilityGrant),
252 approvalRequests: many(approvalRequest),
253}))
254
255export const sessionRelations = relations(session, ({ one }) => ({
256 user: one(user, {
257 fields: [session.userId],
258 references: [user.id],
259 }),
260}))
261
262export const accountRelations = relations(account, ({ one }) => ({
263 user: one(user, {
264 fields: [account.userId],
265 references: [user.id],
266 }),
267}))
268
269export const agentHostRelations = relations(agentHost, ({ one, many }) => ({
270 user: one(user, {
271 fields: [agentHost.userId],
272 references: [user.id],
273 }),
274 agents: many(agent),
275 approvalRequests: many(approvalRequest),
276}))
277
278export const agentRelations = relations(agent, ({ one, many }) => ({
279 user: one(user, {
280 fields: [agent.userId],
281 references: [user.id],
282 }),
283 agentHost: one(agentHost, {
284 fields: [agent.hostId],
285 references: [agentHost.id],
286 }),
287 agentCapabilityGrants: many(agentCapabilityGrant),
288 approvalRequests: many(approvalRequest),
289}))
290
291export const agentCapabilityGrantDeniedByRelations = relations(
292 agentCapabilityGrant,
293 ({ one }) => ({
294 user: one(user, {
295 fields: [agentCapabilityGrant.deniedBy],
296 references: [user.id],
297 }),
298 }),
299)
300
301export const agentCapabilityGrantGrantedByRelations = relations(
302 agentCapabilityGrant,
303 ({ one }) => ({
304 user: one(user, {
305 fields: [agentCapabilityGrant.grantedBy],
306 references: [user.id],
307 }),
308 }),
309)
310
311export const agentCapabilityGrantRelations = relations(
312 agentCapabilityGrant,
313 ({ one }) => ({
314 agent: one(agent, {
315 fields: [agentCapabilityGrant.agentId],
316 references: [agent.id],
317 }),
318 }),
319)
320
321export const approvalRequestRelations = relations(
322 approvalRequest,
323 ({ one }) => ({
324 agent: one(agent, {
325 fields: [approvalRequest.agentId],
326 references: [agent.id],
327 }),
328 agentHost: one(agentHost, {
329 fields: [approvalRequest.hostId],
330 references: [agentHost.id],
331 }),
332 user: one(user, {
333 fields: [approvalRequest.userId],
334 references: [user.id],
335 }),
336 }),
337)
338
339// ---------------------------------------------------------------------------
340// Core domain tables (PLAN.md task 1.1).
341// Conventions: ids are lowercase kebab/slug text; times are unix epoch seconds
342// (plain integers — the timestamp_ms columns above are better-auth-generated).
343// ---------------------------------------------------------------------------
344
345export const activities = [
346 'chat',
347 'image',
348 'video',
349 'audio',
350 'embeddings',
351 'moderation',
352] as const
353export type Activity = (typeof activities)[number]
354
355export const changeTypes = [
356 'model.added',
357 'model.removed',
358 'model.updated',
359 'schema.added',
360 'schema.updated',
361 'endpoint.added',
362 'endpoint.removed',
363] as const
364export type ChangeType = (typeof changeTypes)[number]
365
366export const providers = sqliteTable('providers', {
367 id: text('id').primaryKey(),
368 displayName: text('display_name').notNull(),
369 specSourceUrl: text('spec_source_url').notNull(),
370 modelsEndpoint: text('models_endpoint'),
371 authEnvVar: text('auth_env_var'),
372 lastPolledAt: integer('last_polled_at'),
373 lastSyncedAt: integer('last_synced_at'),
374 status: text('status', {
375 enum: ['active', 'degraded', 'disabled'],
376 })
377 .notNull()
378 .default('active'),
379})
380
381/** Names other providers' model ids use for a provider (`google` → gemini). */
382export const providerModelNamespaces = sqliteTable(
383 'provider_model_namespaces',
384 {
385 namespace: text('namespace').notNull(),
386 providerId: text('provider_id')
387 .notNull()
388 .references(() => providers.id, { onDelete: 'cascade' }),
389 },
390 (table) => [
391 primaryKey({ columns: [table.namespace, table.providerId] }),
392 index('provider_model_namespaces_providerId_idx').on(table.providerId),
393 ],
394)
395
396export const models = sqliteTable(
397 'models',
398 {
399 id: text('id').primaryKey(),
400 providerId: text('provider_id')
401 .notNull()
402 .references(() => providers.id, { onDelete: 'cascade' }),
403 rawId: text('raw_id').notNull(),
404 activity: text('activity', { enum: activities }),
405 displayName: text('display_name'),
406 contextWindow: integer('context_window'),
407 maxOutput: integer('max_output'),
408 modalities: text('modalities', { mode: 'json' }),
409 pricing: text('pricing', { mode: 'json' }),
410 // A flag map: `{ tools: true, reasoning: false }`. true = the provider
411 // states support, false = it states none, key absent = unknown, null =
412 // nothing known. Booleans only.
413 capabilities: text('capabilities', {
414 mode: 'json',
415 }).$type<CapabilityMap | null>(),
416 // The provider's own listing object, as published and not normalised
417 // (fal category, Ark features, ElevenLabs languages, …). Never flags.
418 providerMetadata: text('provider_metadata', { mode: 'json' }).$type<Record<
419 string,
420 unknown
421 > | null>(),
422 // Thinking configuration and provider-hosted tool type ids (issue #77).
423 reasoning: text('reasoning', { mode: 'json' }),
424 serverTools: text('server_tools', { mode: 'json' }),
425 // Wire map for thinking, token limits, and roles (issue #95). Null until
426 // verified. `reasoning` stays the readable fact.
427 requestMap: text('request_map', { mode: 'json' }),
428 // Caller ids that resolve to this dated row (issue #112).
429 aliases: text('aliases', { mode: 'json' }).$type<Array<string> | null>(),
430 // The provider's own statement of its upstream model (issue #199); it
431 // can precede the target row's arrival. The namespace resolves through
432 // providers / provider_model_namespaces.
433 upstreamProvider: text('upstream_provider'),
434 upstreamRawId: text('upstream_raw_id'),
435 upstreamSource: text('upstream_source', { mode: 'json' }),
436 // Resolved link, written only by reconcileSameAs; never the row's facts.
437 sameAsModelId: text('same_as_model_id').references(
438 (): AnySQLiteColumn => models.id,
439 { onDelete: 'set null' },
440 ),
441 // Per-field provenance for catalog facts (issue #53). JSON ModelFactSources.
442 factSources: text('fact_sources', { mode: 'json' }),
443 // Generation route decided from listing data the read path cannot see
444 // (Gemini's supportedGenerationMethods → :predict vs :generateContent).
445 // Null → config binds at read time; Gemini still reads leftover
446 // methods from capabilities until the poller rewrites the row.
447 schemaEndpointId: text('schema_endpoint_id'),
448 // The provider's own stated release/created date; null when it reports
449 // none. `firstSeenAt` below folds the same date in and cannot say which.
450 releasedAt: integer('released_at'),
451 // `YYYY-MM` or `YYYY-MM-DD`, as precise as the provider states it.
452 knowledgeCutoff: text('knowledge_cutoff'),
453 // Stated by the provider itself, never inferred; null = unstated.
454 openWeights: integer('open_weights', { mode: 'boolean' }),
455 weightsUrl: text('weights_url'),
456 // Upstream release date when the provider reports one (backdated by the
457 // poller, issue #1); otherwise when our poller first observed the model.
458 firstSeenAt: integer('first_seen_at').notNull(),
459 lastSeenAt: integer('last_seen_at').notNull(),
460 deprecatedAt: integer('deprecated_at'),
461 },
462 (table) => [
463 index('models_providerId_idx').on(table.providerId),
464 index('models_activity_idx').on(table.activity),
465 index('models_sameAsModelId_idx').on(table.sameAsModelId),
466 check(
467 'models_upstream_identity_pair',
468 sql`(${table.upstreamProvider} IS NULL) = (${table.upstreamRawId} IS NULL)
469 AND (${table.upstreamProvider} IS NULL) = (${table.upstreamSource} IS NULL)`,
470 ),
471 check('models_sameAs_not_self', sql`${table.sameAsModelId} != ${table.id}`),
472 ],
473)
474
475export const endpoints = sqliteTable(
476 'endpoints',
477 {
478 id: text('id').primaryKey(),
479 providerId: text('provider_id')
480 .notNull()
481 .references(() => providers.id, { onDelete: 'cascade' }),
482 activity: text('activity', { enum: activities }).notNull(),
483 method: text('method').notNull(),
484 path: text('path').notNull(),
485 description: text('description'),
486 },
487 (table) => [index('endpoints_providerId_idx').on(table.providerId)],
488)
489
490export const schemaVersions = sqliteTable(
491 'schema_versions',
492 {
493 id: text('id').primaryKey(),
494 endpointId: text('endpoint_id')
495 .notNull()
496 .references(() => endpoints.id, { onDelete: 'cascade' }),
497 kind: text('kind', { enum: ['input', 'output'] }).notNull(),
498 contentHash: text('content_hash').notNull(),
499 schema: text('schema').notNull(),
500 specRevision: text('spec_revision'),
501 // Provenance (nullable on rows synced before it was recorded): the
502 // upstream document this version was derived from, and the extractor
503 // that derived it. createdAt doubles as the fetched-at timestamp.
504 sourceUrl: text('source_url'),
505 sourceHash: text('source_hash'),
506 extractorVersion: text('extractor_version'),
507 /**
508 * How the content was arrived at — the `Derivation` trust ladder in
509 * `src/server/providers/types.ts`. Nullable on rows synced before it was
510 * recorded. `verifiedAt` is a `YYYY-MM-DD` date and is only meaningful
511 * for `probe-verified`, whose accuracy is a point-in-time claim.
512 */
513 derivation: text('derivation', {
514 enum: ['upstream-spec', 'generated', 'probe-verified', 'docs-derived'],
515 }),
516 verifiedAt: text('verified_at'),
517 createdAt: integer('created_at').notNull(),
518 supersededAt: integer('superseded_at'),
519 },
520 (table) => [
521 index('schema_versions_endpointId_kind_idx').on(
522 table.endpointId,
523 table.kind,
524 ),
525 index('schema_versions_contentHash_idx').on(table.contentHash),
526 ],
527)
528
529export const changes = sqliteTable(
530 'changes',
531 {
532 id: text('id').primaryKey(),
533 type: text('type', { enum: changeTypes }).notNull(),
534 providerId: text('provider_id')
535 .notNull()
536 .references(() => providers.id, { onDelete: 'cascade' }),
537 subjectId: text('subject_id').notNull(),
538 summary: text('summary').notNull(),
539 payload: text('payload', { mode: 'json' }),
540 createdAt: integer('created_at').notNull(),
541 },
542 (table) => [
543 index('changes_createdAt_idx').on(table.createdAt),
544 index('changes_providerId_idx').on(table.providerId),
545 ],
546)
547
548export const providersRelations = relations(providers, ({ many }) => ({
549 models: many(models),
550 endpoints: many(endpoints),
551 changes: many(changes),
552}))
553
554export const modelsRelations = relations(models, ({ one }) => ({
555 provider: one(providers, {
556 fields: [models.providerId],
557 references: [providers.id],
558 }),
559}))
560
561export const endpointsRelations = relations(endpoints, ({ one, many }) => ({
562 provider: one(providers, {
563 fields: [endpoints.providerId],
564 references: [providers.id],
565 }),
566 schemaVersions: many(schemaVersions),
567}))
568
569export const schemaVersionsRelations = relations(schemaVersions, ({ one }) => ({
570 endpoint: one(endpoints, {
571 fields: [schemaVersions.endpointId],
572 references: [endpoints.id],
573 }),
574}))
575
576export const changesRelations = relations(changes, ({ one }) => ({
577 provider: one(providers, {
578 fields: [changes.providerId],
579 references: [providers.id],
580 }),
581}))
582
583// ---------------------------------------------------------------------------
584// Cache + delivery tables (PLAN.md task 1.2).
585// ---------------------------------------------------------------------------
586
587export const cacheMeta = sqliteTable('cache_meta', {
588 key: text('key').primaryKey(),
589 fetchedAt: integer('fetched_at').notNull(),
590 staleTime: integer('stale_time').notNull(),
591 lastError: text('last_error'),
592 refreshing: integer('refreshing', { mode: 'boolean' })
593 .notNull()
594 .default(false),
595})
596
597export const subscriptions = sqliteTable(
598 'subscriptions',
599 {
600 id: text('id').primaryKey(),
601 agentId: text('agent_id')
602 .notNull()
603 .references(() => user.id, { onDelete: 'cascade' }),
604 url: text('url').notNull(),
605 secret: text('secret').notNull(),
606 events: text('events', { mode: 'json' }).notNull(),
607 providerFilter: text('provider_filter').references(() => providers.id, {
608 onDelete: 'cascade',
609 }),
610 active: integer('active', { mode: 'boolean' }).notNull().default(true),
611 createdAt: integer('created_at').notNull(),
612 },
613 (table) => [index('subscriptions_agentId_idx').on(table.agentId)],
614)
615
616export const webhookDeliveries = sqliteTable(
617 'webhook_deliveries',
618 {
619 id: text('id').primaryKey(),
620 subscriptionId: text('subscription_id')
621 .notNull()
622 .references(() => subscriptions.id, { onDelete: 'cascade' }),
623 changeId: text('change_id')
624 .notNull()
625 .references(() => changes.id, { onDelete: 'cascade' }),
626 attempt: integer('attempt').notNull().default(0),
627 nextAttemptAt: integer('next_attempt_at').notNull(),
628 status: text('status', { enum: ['pending', 'ok', 'failed'] })
629 .notNull()
630 .default('pending'),
631 lastResponseCode: integer('last_response_code'),
632 },
633 (table) => [
634 index('webhook_deliveries_status_nextAttemptAt_idx').on(
635 table.status,
636 table.nextAttemptAt,
637 ),
638 index('webhook_deliveries_subscriptionId_idx').on(table.subscriptionId),
639 ],
640)
641
642export const subscriptionsRelations = relations(
643 subscriptions,
644 ({ one, many }) => ({
645 agent: one(user, {
646 fields: [subscriptions.agentId],
647 references: [user.id],
648 }),
649 deliveries: many(webhookDeliveries),
650 }),
651)
652
653export const webhookDeliveriesRelations = relations(
654 webhookDeliveries,
655 ({ one }) => ({
656 subscription: one(subscriptions, {
657 fields: [webhookDeliveries.subscriptionId],
658 references: [subscriptions.id],
659 }),
660 change: one(changes, {
661 fields: [webhookDeliveries.changeId],
662 references: [changes.id],
663 }),
664 }),
665)