Spaces:
Runtime error
Runtime error
File size: 22,027 Bytes
ceb943f 304bdf5 ceb943f 304bdf5 ceb943f 900ee77 304bdf5 ceb943f 36a3a93 256e9b3 36a3a93 ceb943f 5480d48 ceb943f 80d0777 ceb943f 6b7bc46 256e9b3 ceb943f 80d0777 ceb943f 081358f ceb943f 256e9b3 58864c6 ceb943f 900ee77 ceb943f 271988a e7abb94 271988a e7abb94 271988a 304bdf5 ceb943f 80d0777 ceb943f 271988a e7abb94 304bdf5 ceb943f 271988a e7abb94 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | import { pgTable, text, timestamp, boolean, integer, pgEnum, uniqueIndex, real, jsonb, index } from 'drizzle-orm/pg-core';
export const syncStatusEnum = pgEnum('sync_status', ['idle', 'syncing', 'errored']);
export const videoScanStatusEnum = pgEnum('video_scan_status', [
'pending_analysis',
'in_progress',
'awaiting_approval',
'completed',
'failed',
'idle',
'pending' // Keep for backwards compatibility during migration if needed
]);
export const channelTypeEnum = pgEnum('channel_type', ['verified', 'external']);
export const platformEnum = pgEnum('platform', ['youtube', 'instagram', 'tiktok', 'facebook']);
export const objectCategory = pgEnum('object_category', [
'Tech',
'Fashion',
'Furniture',
'Audio',
'Other',
'Person',
'Apparel',
]);
export const detectionStatus = pgEnum('detection_status', [
'pending_review',
'approved',
'rejected',
'flagged',
]);
export const moderationStatus = pgEnum('moderation_status', [
'PENDING', // Awaiting creator review (default)
'APPROVED', // Creator approved for Vault
'REJECTED', // Creator rejected, hidden from Vault
]);
export const adminModerationType = pgEnum('admin_moderation_type', [
'corrected', // Admin corrected name/category/links → back to creator queue
'marked_incorrect', // Admin marked as bad detection → removed from pipeline
'approved', // Admin approved for vault visibility
'rejected', // Admin rejected/hidden from vault
]);
export const reasonCode = pgEnum('reason_code', [
'wrong_object',
'wrong_category',
'false_positive',
'unclear_image',
'duplicate',
'out_of_scope',
]);
// Reusable timestamp pattern (recommended by Drizzle community)
export const timestamps = {
createdAt: timestamp('created_at', {
mode: 'date',
precision: 3,
withTimezone: true,
})
.defaultNow()
.notNull(),
updatedAt: timestamp('updated_at', {
mode: 'date',
precision: 3,
withTimezone: true,
})
.defaultNow()
.notNull()
.$onUpdateFn(() => new Date()),
};
// Users table - Extended for Better Auth
export const users = pgTable('users', {
id: text('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull().unique(),
emailVerified: boolean('email_verified').notNull(),
image: text('image'),
createdAt: timestamp('created_at').notNull(),
updatedAt: timestamp('updated_at').notNull(),
});
// Sessions table
export const sessions = pgTable('session', {
id: text('id').primaryKey(),
expiresAt: timestamp('expires_at').notNull(),
token: text('token').notNull().unique(),
createdAt: timestamp('created_at').notNull(),
updatedAt: timestamp('updated_at').notNull(),
ipAddress: text('ip_address'),
userAgent: text('user_agent'),
userId: text('user_id')
.notNull()
.references(() => users.id),
});
// Accounts table
export const accounts = pgTable('account', {
id: text('id').primaryKey(),
accountId: text('account_id').notNull(),
providerId: text('provider_id').notNull(),
userId: text('user_id')
.notNull()
.references(() => users.id),
accessToken: text('access_token'),
refreshToken: text('refresh_token'),
idToken: text('id_token'),
accessTokenExpiresAt: timestamp('access_token_expires_at'),
refreshTokenExpiresAt: timestamp('refresh_token_expires_at'),
scope: text('scope'),
password: text('password'),
createdAt: timestamp('created_at').notNull(),
updatedAt: timestamp('updated_at').notNull(),
});
// Verifications table
export const verifications = pgTable('verification', {
id: text('id').primaryKey(),
identifier: text('identifier').notNull(),
value: text('value').notNull(),
expiresAt: timestamp('expires_at').notNull(),
createdAt: timestamp('created_at'),
updatedAt: timestamp('updated_at'),
});
// YouTube Channels table
export const youtubeChannels = pgTable('youtube_channels', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
creatorId: text('creator_id')
.notNull()
.references(() => users.id),
channelId: text('channel_id').notNull(),
channelName: text('channel_name').notNull(),
creatorSlug: text('creator_slug').notNull().unique(), // Story 4.1: URL-friendly slug for public vault
subscriberCount: integer('subscriber_count'),
thumbnailUrl: text('thumbnail_url'),
connectedAt: timestamp('connected_at').defaultNow().notNull(),
syncStatus: syncStatusEnum('sync_status').default('idle').notNull(),
channelType: channelTypeEnum('channel_type').default('external').notNull(),
platform: platformEnum('platform').default('youtube').notNull(),
}, (table) => ({
creatorChannelIdx: uniqueIndex('creator_channel_idx').on(table.creatorId, table.channelId),
}));
// YouTube Videos table
export const youtubeVideos = pgTable('youtube_videos', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
channelId: text('channel_id')
.notNull()
.references(() => youtubeChannels.id, { onDelete: 'cascade' }),
videoId: text('video_id').notNull(),
title: text('title').notNull(),
description: text('description'),
thumbnailUrl: text('thumbnail_url'),
duration: text('duration'), // ISO 8601 format (PT15M33S)
viewCount: integer('view_count'),
availabilityStatus: text('availability_status').notNull().default('unknown'), // 'available' (public/unlisted) | 'private' | 'unknown'
scanStatus: videoScanStatusEnum('scan_status').default('pending').notNull(),
publishedAt: timestamp('published_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}),
platform: platformEnum('platform').default('youtube').notNull(),
url: text('url'), // Canonical URL for TikTok/Insta
width: integer('width'),
height: integer('height'),
isInWorkbench: boolean('is_in_workbench').default(true).notNull(),
...timestamps,
}, (table) => ({
channelVideoIdx: uniqueIndex('channel_video_idx').on(table.channelId, table.videoId),
}));
// Video Scan Jobs table for progress tracking
export const videoScanJobs = pgTable('video_scan_jobs', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
channelId: text('channel_id')
.notNull()
.references(() => youtubeChannels.id, { onDelete: 'cascade' }),
userId: text('user_id')
.notNull()
.references(() => users.id),
status: videoScanStatusEnum('status').default('pending').notNull(),
progress: integer('progress').default(0).notNull(), // 0-100
totalVideos: integer('total_videos'),
scannedVideos: integer('scanned_videos').default(0).notNull(),
errorMessage: text('error_message'),
inngestRunId: text('inngest_run_id'),
...timestamps,
});
// Type inference
export type User = typeof users.$inferSelect;
export type InsertUser = typeof users.$inferInsert;
export type Session = typeof sessions.$inferSelect;
export type Account = typeof accounts.$inferSelect;
export type Verification = typeof verifications.$inferSelect;
export type YoutubeChannel = typeof youtubeChannels.$inferSelect;
export type InsertYoutubeChannel = typeof youtubeChannels.$inferInsert;
export type YoutubeVideo = typeof youtubeVideos.$inferSelect;
export type InsertYoutubeVideo = typeof youtubeVideos.$inferInsert;
export type VideoScanJob = typeof videoScanJobs.$inferSelect;
export type InsertVideoScanJob = typeof videoScanJobs.$inferInsert;
// Detected Objects table
export const detectedObjects = pgTable('detected_objects', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
videoId: text('video_id')
.notNull()
.references(() => youtubeVideos.id, { onDelete: 'cascade' }),
objectName: text('object_name').notNull(),
category: objectCategory('category').notNull(),
confidenceScore: real('confidence_score').notNull(), // 0.0 - 1.0
frameTimestamp: integer('frame_timestamp').notNull(), // Seconds into video
detectionMetadata: jsonb('detection_metadata'), // Bounding box, model info
thumbnailUrl: text('thumbnail_url'),
status: detectionStatus('status').notNull().default('pending_review'),
// NEW COLUMNS FOR STORY 3.5
moderationStatus: moderationStatus('moderation_status').notNull().default('PENDING'),
moderatedAt: timestamp('moderated_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}),
moderatedBy: text('moderated_by').references(() => users.id),
moderationMetadata: jsonb('moderation_metadata'), // Edit history, notes
...timestamps,
});
export type DetectedObject = typeof detectedObjects.$inferSelect;
export type InsertDetectedObject = typeof detectedObjects.$inferInsert;
export const marketplaceType = pgEnum('marketplace_type', [
'amazon',
'ebay',
'etsy',
]);
export const availabilityStatus = pgEnum('availability_status', [
'IN_STOCK',
'SOLD_OUT',
'DISCONTINUED',
]);
export const interestPledgeStatus = pgEnum('interest_pledge_status', [
'ACTIVE', // Waiting for notification
'NOTIFIED', // User has been notified
'EXPIRED', // Pledge expired (optional future use)
]);
export const linkStatusEnum = pgEnum('link_status', [
'ACTIVE', // Link is working (default)
'CHECKING', // Currently being checked by monitoring job
'BROKEN', // Link is broken (404, deleted product)
]);
export const bountyPledgeStatusEnum = pgEnum('bounty_pledge_status', [
'ACTIVE', // Pledge is active and waiting for item to be sourced
'WITHDRAWN', // User withdrew their pledge
'FULFILLED', // Item was sourced and user was notified
]);
export const marketplaceMatches = pgTable('marketplace_matches', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
objectId: text('object_id')
.notNull()
.references(() => detectedObjects.id, { onDelete: 'cascade' }),
marketplace: marketplaceType('marketplace').notNull(),
productId: text('product_id').notNull(), // ASIN, eBay Item ID, Etsy Listing ID
productName: text('product_name').notNull(),
price: real('price').notNull(), // USD
availabilityStatus: availabilityStatus('availability_status').notNull(),
affiliateUrl: text('affiliate_url').notNull(),
imageUrl: text('image_url'),
// Link Health Tracking (Story 5.3)
linkStatus: linkStatusEnum('link_status').notNull().default('ACTIVE'),
lastCheckedAt: timestamp('last_checked_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}),
checkAttempts: integer('check_attempts').notNull().default(0),
checkMetadata: jsonb('check_metadata'), // { httpStatus, errorMessage, checkedAt, headers }
matchedAt: timestamp('matched_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}).notNull().defaultNow(),
...timestamps,
}, (table) => ({
linkStatusIdx: index('marketplace_matches_link_status_idx').on(table.linkStatus),
lastCheckedAtIdx: index('marketplace_matches_last_checked_at_idx').on(table.lastCheckedAt),
}));
export const productClicks = pgTable(
'product_clicks',
{
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
marketplaceMatchId: text('marketplace_match_id')
.notNull()
.references(() => marketplaceMatches.id, { onDelete: 'cascade' }),
clickedAt: timestamp('clicked_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}).notNull().defaultNow(),
viewerIp: text('viewer_ip'), // Anonymized for privacy (e.g., "192.168.1.0")
userAgent: text('user_agent'),
referrer: text('referrer'),
...timestamps,
},
(table) => ({
marketplaceMatchIdIdx: index('product_clicks_marketplace_match_id_idx').on(
table.marketplaceMatchId
),
clickedAtIdx: index('product_clicks_clicked_at_idx').on(table.clickedAt),
})
);
export const adminModeration = pgTable('admin_moderation', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
detectionId: text('detection_id')
.notNull()
.references(() => detectedObjects.id, { onDelete: 'cascade' }),
adminId: text('admin_id')
.notNull()
.references(() => users.id),
action: adminModerationType('action').notNull(),
reasonCode: reasonCode('reason_code'), // nullable — only set for 'marked_incorrect'
originalValues: jsonb('original_values').notNull(), // Snapshot before mutation
correctedValues: jsonb('corrected_values'), // What was changed to (null for mark_incorrect)
trainAiFlag: boolean('train_ai_flag').notNull().default(true), // Future: feed back to model
...timestamps,
});
export const interestPledges = pgTable('interest_pledges', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
marketplaceMatchId: text('marketplace_match_id')
.references(() => marketplaceMatches.id, { onDelete: 'cascade' }),
detectedObjectId: text('detected_object_id')
.references(() => detectedObjects.id, { onDelete: 'cascade' }),
emailHash: text('email_hash').notNull(), // SHA-256 hash for duplicate detection
emailEncrypted: text('email_encrypted').notNull(), // AES-256 encrypted email
status: interestPledgeStatus('status').notNull().default('ACTIVE'),
// GDPR/CCPA Compliance Fields (Story 5.2)
consentTimestamp: timestamp('consent_timestamp', {
mode: 'date',
precision: 3,
withTimezone: true,
}).notNull().defaultNow(), // When user agreed to receive emails
consentIp: text('consent_ip'), // Anonymized IP (e.g., "192.168.1.0")
unsubscribeToken: text('unsubscribe_token').notNull().$defaultFn(() => crypto.randomUUID()), // For one-click unsubscribe
consentMetadata: jsonb('consent_metadata'), // {userAgent, referrer, etc.}
notifiedAt: timestamp('notified_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}),
...timestamps,
}, (table) => ({
marketplaceMatchIdIdx: index('interest_pledges_marketplace_match_id_idx').on(
table.marketplaceMatchId
),
detectedObjectIdIdx: index('interest_pledges_detected_object_id_idx').on(
table.detectedObjectId
),
unsubscribeTokenIdx: uniqueIndex('interest_pledges_unsubscribe_token_idx').on(
table.unsubscribeToken
),
}));
export const bountyPledges = pgTable('bounty_pledges', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
// Product reference (denormalized for easier querying)
productId: text('product_id').notNull(),
marketplaceMatchId: text('marketplace_match_id')
.notNull()
.references(() => marketplaceMatches.id, { onDelete: 'cascade' }),
// Email and encryption (following Story 5.2 pattern)
emailHash: text('email_hash').notNull(), // SHA-256 for deduplication
encryptedEmail: text('encrypted_email').notNull(), // AES-256 encrypted
// Pledge details
pledgeAmount: real('pledge_amount').notNull(), // In USD
currency: text('currency').notNull().default('USD'),
status: bountyPledgeStatusEnum('status').notNull().default('ACTIVE'),
// GDPR/CCPA compliance (NFR-4)
consentTimestamp: timestamp('consent_timestamp', {
mode: 'date',
precision: 3,
withTimezone: true,
}).notNull().defaultNow(),
consentIp: text('consent_ip'), // Optional, for legal compliance
unsubscribeToken: text('unsubscribe_token').notNull().$defaultFn(() => crypto.randomUUID()),
// Notifications
notifiedAt: timestamp('notified_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}),
// Timestamps
...timestamps,
}, (table) => ({
productIdIdx: index('bounty_pledges_product_id_idx').on(table.productId),
statusIdx: index('bounty_pledges_status_idx').on(table.status),
emailHashIdx: index('bounty_pledges_email_hash_idx').on(table.emailHash),
}));
// Revenue tracking for affiliate commissions (Story 6.1)
export const affiliateRevenue = pgTable('affiliate_revenue', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
marketplaceMatchId: text('marketplace_match_id')
.notNull()
.references(() => marketplaceMatches.id, { onDelete: 'cascade' }),
amount: real('amount').notNull(), // Commission earned in USD
recordedAt: timestamp('recorded_at', {
mode: 'date',
precision: 3,
withTimezone: true,
}).notNull().defaultNow(),
orderId: text('order_id'), // Optional marketplace order ID
...timestamps,
}, (table) => ({
marketplaceMatchIdIdx: index('affiliate_revenue_marketplace_match_id_idx').on(
table.marketplaceMatchId
),
recordedAtIdx: index('affiliate_revenue_recorded_at_idx').on(table.recordedAt),
}));
export type MarketplaceMatch = typeof marketplaceMatches.$inferSelect;
export type InsertMarketplaceMatch = typeof marketplaceMatches.$inferInsert;
export type ProductClick = typeof productClicks.$inferSelect;
export type InsertProductClick = typeof productClicks.$inferInsert;
export type AdminModerationRecord = typeof adminModeration.$inferSelect;
export type InsertAdminModerationRecord = typeof adminModeration.$inferInsert;
export type InterestPledge = typeof interestPledges.$inferSelect;
export type InsertInterestPledge = typeof interestPledges.$inferInsert;
export type BountyPledge = typeof bountyPledges.$inferSelect;
export type InsertBountyPledge = typeof bountyPledges.$inferInsert;
export type AffiliateRevenue = typeof affiliateRevenue.$inferSelect;
export type InsertAffiliateRevenue = typeof affiliateRevenue.$inferInsert;
export const requestStatus = pgEnum('request_status', [
'PENDING',
'FULFILLED', // Creator added the product
'DISMISSED',
]);
export const affiliateSubmissionStatus = pgEnum('affiliate_submission_status', [
'PENDING', // Awaiting creator review
'APPROVED', // Creator accepted and added to Vault
'REJECTED', // Creator rejected
]);
export const productRequests = pgTable('product_requests', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
videoId: text('video_id')
.notNull()
.references(() => youtubeVideos.id, { onDelete: 'cascade' }),
creatorId: text('creator_id')
.notNull()
.references(() => users.id),
viewerName: text('viewer_name'),
viewerEmail: text('viewer_email'),
note: text('note').notNull(),
imageUrl: text('image_url'), // Snapshot or upload
frameTimestamp: integer('frame_timestamp'), // If request came from a specific point in video
status: requestStatus('status').notNull().default('PENDING'),
...timestamps,
});
export const affiliateProposals = pgTable('affiliate_proposals', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
objectId: text('object_id').references(() => detectedObjects.id, { onDelete: 'set null' }),
videoId: text('video_id').notNull().references(() => youtubeVideos.id, { onDelete: 'cascade' }),
creatorId: text('creator_id').notNull().references(() => users.id),
submitterName: text('submitter_name'),
submitterEmail: text('submitter_email'),
productUrl: text('product_url').notNull(),
affiliateUrl: text('affiliate_url').notNull(),
productName: text('product_name').notNull(),
price: real('price'),
imageUrl: text('image_url'),
note: text('note'),
status: affiliateSubmissionStatus('status').notNull().default('PENDING'),
...timestamps,
});
export type ProductRequest = typeof productRequests.$inferSelect;
export type InsertProductRequest = typeof productRequests.$inferInsert;
export const analysisNotifications = pgTable('analysis_notifications', {
id: text('id').notNull().primaryKey().$defaultFn(() => crypto.randomUUID()),
videoId: text('video_id')
.notNull()
.references(() => youtubeVideos.id, { onDelete: 'cascade' }),
emailHash: text('email_hash').notNull(),
emailEncrypted: text('email_encrypted').notNull(),
status: text('status', { enum: ['PENDING', 'SENT'] }).notNull().default('PENDING'),
unsubscribeToken: text('unsubscribe_token').notNull().$defaultFn(() => crypto.randomUUID()),
...timestamps,
});
export type AnalysisNotification = typeof analysisNotifications.$inferSelect;
export type InsertAnalysisNotification = typeof analysisNotifications.$inferInsert;
// Relations
import { relations } from 'drizzle-orm';
export const youtubeChannelsRelations = relations(youtubeChannels, ({ one, many }) => ({
user: one(users, {
fields: [youtubeChannels.creatorId],
references: [users.id],
}),
videos: many(youtubeVideos),
}));
export const youtubeVideosRelations = relations(youtubeVideos, ({ one, many }) => ({
channel: one(youtubeChannels, {
fields: [youtubeVideos.channelId],
references: [youtubeChannels.id],
}),
detections: many(detectedObjects),
requests: many(productRequests),
proposals: many(affiliateProposals),
analysisNotifications: many(analysisNotifications),
}));
export const analysisNotificationsRelations = relations(analysisNotifications, ({ one }) => ({
video: one(youtubeVideos, {
fields: [analysisNotifications.videoId],
references: [youtubeVideos.id],
}),
}));
export const detectedObjectsRelations = relations(detectedObjects, ({ one, many }) => ({
video: one(youtubeVideos, {
fields: [detectedObjects.videoId],
references: [youtubeVideos.id],
}),
marketplaceMatches: many(marketplaceMatches),
}));
export const marketplaceMatchesRelations = relations(marketplaceMatches, ({ one }) => ({
object: one(detectedObjects, {
fields: [marketplaceMatches.objectId],
references: [detectedObjects.id],
}),
}));
export const productRequestsRelations = relations(productRequests, ({ one }) => ({
video: one(youtubeVideos, {
fields: [productRequests.videoId],
references: [youtubeVideos.id],
}),
creator: one(users, {
fields: [productRequests.creatorId],
references: [users.id],
}),
}));
export const affiliateProposalsRelations = relations(affiliateProposals, ({ one }) => ({
video: one(youtubeVideos, {
fields: [affiliateProposals.videoId],
references: [youtubeVideos.id],
}),
creator: one(users, {
fields: [affiliateProposals.creatorId],
references: [users.id],
}),
object: one(detectedObjects, {
fields: [affiliateProposals.objectId],
references: [detectedObjects.id],
}),
}));
|