@@ -336,122 +336,6 @@ export const docsArtifactCache = pgTable(
336336 } ) ,
337337)
338338
339- // NPM Packages table (combines registry and stats cache)
340- export const npmPackages = pgTable (
341- 'npm_packages' ,
342- {
343- id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
344- // Package name (e.g., "@tanstack/react-query")
345- packageName : varchar ( 'package_name' , { length : 255 } ) . notNull ( ) . unique ( ) ,
346-
347- // Package metadata (from npm registry)
348- githubRepo : varchar ( 'github_repo' , { length : 255 } ) ,
349- libraryId : varchar ( 'library_id' , { length : 255 } ) ,
350- isLegacy : boolean ( 'is_legacy' ) . default ( false ) ,
351- metadataCheckedAt : timestamp ( 'metadata_checked_at' , {
352- withTimezone : true ,
353- mode : 'date' ,
354- } ) ,
355-
356- // Stats cache (from npm downloads API)
357- downloads : bigint ( 'downloads' , { mode : 'number' } ) ,
358- ratePerDay : real ( 'rate_per_day' ) , // Growth rate in downloads per day (for animation)
359- statsExpiresAt : timestamp ( 'stats_expires_at' , {
360- withTimezone : true ,
361- mode : 'date' ,
362- } ) ,
363-
364- createdAt : timestamp ( 'created_at' , { withTimezone : true , mode : 'date' } )
365- . notNull ( )
366- . defaultNow ( ) ,
367- updatedAt : timestamp ( 'updated_at' , { withTimezone : true , mode : 'date' } )
368- . notNull ( )
369- . defaultNow ( ) ,
370- } ,
371- ( table ) => ( {
372- packageNameIdx : index ( 'npm_packages_package_name_idx' ) . on (
373- table . packageName ,
374- ) ,
375- githubRepoIdx : index ( 'npm_packages_github_repo_idx' ) . on ( table . githubRepo ) ,
376- libraryIdIdx : index ( 'npm_packages_library_id_idx' ) . on ( table . libraryId ) ,
377- statsExpiresAtIdx : index ( 'npm_packages_stats_expires_at_idx' ) . on (
378- table . statsExpiresAt ,
379- ) ,
380- } ) ,
381- )
382-
383- export type NpmPackage = InferSelectModel < typeof npmPackages >
384- export type NewNpmPackage = InferInsertModel < typeof npmPackages >
385-
386- // NPM Org Stats cache table (for pre-aggregated org-level stats)
387- export const npmOrgStatsCache = pgTable (
388- 'npm_org_stats_cache' ,
389- {
390- id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
391- // Organization name (e.g., "tanstack")
392- orgName : varchar ( 'org_name' , { length : 255 } ) . notNull ( ) . unique ( ) ,
393- // Pre-aggregated total downloads
394- totalDownloads : bigint ( 'total_downloads' , { mode : 'number' } ) . notNull ( ) ,
395- // Per-package stats breakdown (JSON) - needed for per-package rate info
396- packageStats : jsonb ( 'package_stats' ) . notNull ( ) ,
397- // When this cache entry expires (should refresh after this)
398- expiresAt : timestamp ( 'expires_at' , {
399- withTimezone : true ,
400- mode : 'date' ,
401- } ) . notNull ( ) ,
402- createdAt : timestamp ( 'created_at' , { withTimezone : true , mode : 'date' } )
403- . notNull ( )
404- . defaultNow ( ) ,
405- updatedAt : timestamp ( 'updated_at' , { withTimezone : true , mode : 'date' } )
406- . notNull ( )
407- . defaultNow ( ) ,
408- } ,
409- ( table ) => ( {
410- orgNameIdx : index ( 'npm_org_stats_cache_org_name_idx' ) . on ( table . orgName ) ,
411- expiresAtIdx : index ( 'npm_org_stats_cache_expires_at_idx' ) . on (
412- table . expiresAt ,
413- ) ,
414- } ) ,
415- )
416-
417- export type NpmOrgStatsCache = InferSelectModel < typeof npmOrgStatsCache >
418- export type NewNpmOrgStatsCache = InferInsertModel < typeof npmOrgStatsCache >
419-
420- // NPM Library Stats cache table (for pre-aggregated library-level stats)
421- export const npmLibraryStatsCache = pgTable (
422- 'npm_library_stats_cache' ,
423- {
424- id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
425- // Library ID (e.g., "query", "table")
426- libraryId : varchar ( 'library_id' , { length : 255 } ) . notNull ( ) . unique ( ) ,
427- // Pre-aggregated total downloads for this library
428- totalDownloads : bigint ( 'total_downloads' , { mode : 'number' } ) . notNull ( ) ,
429- // Previous total downloads (for calculating rate of change)
430- previousTotalDownloads : bigint ( 'previous_total_downloads' , {
431- mode : 'number' ,
432- } ) ,
433- // Package count
434- packageCount : integer ( 'package_count' ) . notNull ( ) ,
435- // When this cache entry was last updated
436- updatedAt : timestamp ( 'updated_at' , { withTimezone : true , mode : 'date' } )
437- . notNull ( )
438- . defaultNow ( ) ,
439- createdAt : timestamp ( 'created_at' , { withTimezone : true , mode : 'date' } )
440- . notNull ( )
441- . defaultNow ( ) ,
442- } ,
443- ( table ) => ( {
444- libraryIdIdx : index ( 'npm_library_stats_cache_library_id_idx' ) . on (
445- table . libraryId ,
446- ) ,
447- } ) ,
448- )
449-
450- export type NpmLibraryStatsCache = InferSelectModel < typeof npmLibraryStatsCache >
451- export type NewNpmLibraryStatsCache = InferInsertModel <
452- typeof npmLibraryStatsCache
453- >
454-
455339export const ossStatsCache = pgTable (
456340 'oss_stats_cache' ,
457341 {
0 commit comments