upsert all version platform records

This commit is contained in:
Lucy Cifferello
2022-11-29 18:41:02 -05:00
parent d2196a3c2b
commit dd0e2557c7
4 changed files with 13 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ module Database.Queries where
import Database.Persist.Sql (
PersistStoreRead (get),
PersistStoreWrite (insertKey, insert_, insertMany_, repsert),
PersistStoreWrite (insertKey, insert_, repsertMany, repsert),
SqlBackend,
)
import Lib.Types.Core (
@@ -15,7 +15,7 @@ import Lib.Types.Core (
)
import Lib.Types.Emver (Version)
import Model (
Key (PkgRecordKey, VersionRecordKey),
Key (PkgRecordKey, VersionRecordKey, VersionPlatformKey),
Metric (Metric),
PkgDependency (..),
PkgRecord (PkgRecord),
@@ -324,10 +324,11 @@ upsertPackageVersionPlatform PackageManifest{..} = do
let pkgId = PkgRecordKey packageManifestId
let arches = [X86_64, AARCH64]
let records = createVersionPlatformRecord now pkgId packageManifestVersion <$> arches
insertMany_ records
repsertMany records
where
createVersionPlatformRecord time id version = VersionPlatform
createVersionPlatformRecord time id version arch = ((VersionPlatformKey id version arch), VersionPlatform
time
(Just time)
id
version
version
arch)

View File

@@ -143,6 +143,7 @@ import Yesod (
)
import Yesod.Auth (YesodAuth (maybeAuthId))
import Yesod.Core.Types (JSONResponse (JSONResponse))
import Database.Persist.Sql (runSqlPool)
postPkgUploadR :: Handler ()
@@ -226,7 +227,7 @@ postPkgIndexR = do
[i|Could not locate manifest for #{indexPkgReqId}@#{indexPkgReqVersion}|]
pool <- getsYesod appConnPool
runSqlPoolNoTransaction (upsertPackageVersion man) pool Nothing
runSqlPoolNoTransaction (upsertPackageVersionPlatform man) pool Nothing
runSqlPool (upsertPackageVersionPlatform man) pool
postPkgDeindexR :: Handler ()
postPkgDeindexR = do

View File

@@ -106,6 +106,10 @@ instance PersistField OsArch where
fromPersistValue other = Left [i|Invalid OsArch: #{other}|]
instance PersistFieldSql OsArch where
sqlType _ = SqlString
instance FromJSON OsArch where
parseJSON = parseJSON
instance ToJSON OsArch where
toJSON = toJSON
newtype Extension (a :: Symbol) = Extension String deriving (Eq)
type S9PK = Extension "s9pk"

View File

@@ -70,7 +70,7 @@ VersionPlatform
pkgId PkgRecordId
versionNumber Version
arch OsArch
Primary pkgId versionNumber
Primary pkgId versionNumber arch
deriving Eq
deriving Show