@ -297,21 +297,30 @@ public class ClientImporter @Inject constructor(
}
private fun resolveBuilds ( connection : Connection ) {
connection . prepareStatement ( """
UPDATE artifacts
SET
resolved _build _major = build _major ,
resolved _build _minor = build _minor
""" .trimIndent()).use { stmt ->
stmt . execute ( )
}
connection . prepareStatement (
"""
UPDATE artifacts a
SET
resolved _build _major = t . build _major ,
resolved _build _minor = t . build _minor
resolved _build _major = coalesce ( a . build _major , t . build _major ) ,
resolved _build _minor = coalesce ( a . build _minor , t . build _minor )
FROM (
SELECT DISTINCT ON ( a1 . blob _id )
a1 . blob _id ,
coalesce ( a1 . build _major , a2 . build _major ) build _major ,
coalesce ( a1 . build _minor , a2 . build _minor ) build _minor
a2 . build _major ,
a2 . build _minor
FROM artifacts a1
LEFT JOIN artifact _links al ON al . blob _id = a1 . blob _id
LEFT JOIN blobs b2 ON b2 . sha1 = al . sha1
LEFT JOIN artifacts a2 ON a2 . blob _id = b2 . id
JOIN artifact _links al ON al . blob _id = a1 . blob _id
JOIN blobs b2 ON b2 . sha1 = al . sha1
JOIN artifacts a2 ON a2 . blob _id = b2 . id AND a2 . build _major IS NOT NULL
ORDER BY a1 . blob _id ASC , b2 . id ASC
) t
WHERE a . blob _id = t . blob _id