1- import { deleteMavenPackageRepoLinks } from '@crowd/data-access-layer'
21import {
32 NpmRepoUrlRow ,
43 getOrCreateRepoByUrl ,
@@ -103,7 +102,8 @@ export async function backfillNpmRepositoryUrls(
103102
104103 const updates : { id : string ; repositoryUrl : string | null } [ ] = [ ]
105104 // Rows that had a link and now change to a different one — their stale 'declared' link is pruned.
106- const pruneTargets : number [ ] = [ ]
105+ // Kept as strings (packages.id is bigint) — Number() coercion would lose precision above 2^53.
106+ const pruneTargets : string [ ] = [ ]
107107 // Rows that gained/changed a canonical URL — their repo link is (re)written after the update.
108108 const linkTargets : { id : string ; repositoryUrl : string ; host : string } [ ] = [ ]
109109 for ( const row of rows ) {
@@ -120,7 +120,7 @@ export async function backfillNpmRepositoryUrls(
120120 else totals . rewritten ++
121121 updates . push ( { id : row . id , repositoryUrl : desired } )
122122 if ( row . repositoryUrl !== null && desired !== row . repositoryUrl ) {
123- pruneTargets . push ( Number ( row . id ) )
123+ pruneTargets . push ( row . id )
124124 }
125125 if ( canonical )
126126 linkTargets . push ( { id : row . id , repositoryUrl : canonical . url , host : canonical . host } )
@@ -135,7 +135,13 @@ export async function backfillNpmRepositoryUrls(
135135 await withDeadlockRetry ( ( ) =>
136136 qx . tx ( async ( t : QueryExecutor ) => {
137137 await updateNpmRepositoryUrls ( t , updates )
138- if ( pruneTargets . length > 0 ) await deleteMavenPackageRepoLinks ( t , pruneTargets )
138+ if ( pruneTargets . length > 0 ) {
139+ await t . result (
140+ `DELETE FROM package_repos
141+ WHERE package_id = ANY($(packageIds)::bigint[]) AND source = 'declared'` ,
142+ { packageIds : pruneTargets } ,
143+ )
144+ }
139145 for ( const target of linkTargets ) {
140146 const { id : repoId } = await getOrCreateRepoByUrl ( t , target . repositoryUrl , target . host )
141147 await upsertPackageRepo ( t , target . id , repoId , 'declared' , 0.8 )
0 commit comments