feat: update GetLatestPromotedPatch to include architecture and platform parameters

This commit is contained in:
Tony
2026-06-12 20:59:23 +08:00
parent 5f72264b06
commit d391ac678f
4 changed files with 9 additions and 8 deletions
+2 -2
View File
@@ -44,7 +44,7 @@ func (h *DeviceHandler) PatchCheck(w http.ResponseWriter, r *http.Request) {
if err != nil {
// Release not found, no patch available
respondJSON(w, http.StatusOK, models.PatchCheckResponse{
PatchAvailable: false,
PatchAvailable: false,
RolledBackPatchNumbers: []int{},
})
return
@@ -73,7 +73,7 @@ func (h *DeviceHandler) PatchCheck(w http.ResponseWriter, r *http.Request) {
}
// Find the latest promoted patch for this release+channel
patch, err := h.DB.GetLatestPromotedPatch(r.Context(), release.ID, channel.ID)
patch, err := h.DB.GetLatestPromotedPatch(r.Context(), release.ID, channel.ID, req.Arch, req.Platform)
if err != nil {
// No patch available
respondJSON(w, http.StatusOK, models.PatchCheckResponse{
+4 -3
View File
@@ -595,17 +595,18 @@ func (db *PgStore) PromotePatch(ctx context.Context, patchID, channelID int) err
}
// GetLatestPromotedPatch returns the latest patch promoted to a specific channel for a release.
func (db *PgStore) GetLatestPromotedPatch(ctx context.Context, releaseID, channelID int) (*PatchWithArtifactRow, error) {
func (db *PgStore) GetLatestPromotedPatch(ctx context.Context, releaseID, channelID int, arch, platform string) (*PatchWithArtifactRow, error) {
row := &PatchWithArtifactRow{}
err := db.queryRow(ctx,
`SELECT p.id, p.release_id, p.number, p.notes, p.created_at,
pa.hash, pa.storage_key, pa.hash_signature
FROM patches p
JOIN patch_channels pc ON p.id = pc.patch_id
LEFT JOIN patch_artifacts pa ON p.id = pa.patch_id
JOIN patch_artifacts pa ON p.id = pa.patch_id
WHERE p.release_id = $1 AND pc.channel_id = $2
AND pa.arch = $3 AND pa.platform = $4
ORDER BY p.number DESC LIMIT 1`,
releaseID, channelID,
releaseID, channelID, arch, platform,
).Scan(&row.ID, &row.ReleaseID, &row.Number, &row.Notes, &row.CreatedAt,
&row.Hash, &row.StorageKey, &row.HashSignature)
if err != nil {
+2 -2
View File
@@ -505,9 +505,9 @@ func (s *SqliteStore) PromotePatch(ctx context.Context, patchID, channelID int)
_, err := s.db.ExecContext(ctx, `INSERT OR IGNORE INTO patch_channels (patch_id, channel_id) VALUES (?, ?)`, patchID, channelID)
return err
}
func (s *SqliteStore) GetLatestPromotedPatch(ctx context.Context, releaseID, channelID int) (*PatchWithArtifactRow, error) {
func (s *SqliteStore) GetLatestPromotedPatch(ctx context.Context, releaseID, channelID int, arch, platform string) (*PatchWithArtifactRow, error) {
r := &PatchWithArtifactRow{}
err := s.db.QueryRowContext(ctx, `SELECT p.id, p.release_id, p.number, p.notes, p.created_at, pa.hash, pa.storage_key, pa.hash_signature FROM patches p JOIN patch_channels pc ON p.id = pc.patch_id LEFT JOIN patch_artifacts pa ON p.id = pa.patch_id WHERE p.release_id = ? AND pc.channel_id = ? ORDER BY p.number DESC LIMIT 1`, releaseID, channelID).Scan(&r.ID, &r.ReleaseID, &r.Number, &r.Notes, &r.CreatedAt, &r.Hash, &r.StorageKey, &r.HashSignature)
err := s.db.QueryRowContext(ctx, `SELECT p.id, p.release_id, p.number, p.notes, p.created_at, pa.hash, pa.storage_key, pa.hash_signature FROM patches p JOIN patch_channels pc ON p.id = pc.patch_id JOIN patch_artifacts pa ON p.id = pa.patch_id WHERE p.release_id = ? AND pc.channel_id = ? AND pa.arch = ? AND pa.platform = ? ORDER BY p.number DESC LIMIT 1`, releaseID, channelID, arch, platform).Scan(&r.ID, &r.ReleaseID, &r.Number, &r.Notes, &r.CreatedAt, &r.Hash, &r.StorageKey, &r.HashSignature)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -132,7 +132,7 @@ type Store interface {
GetLatestPatchForRelease(ctx context.Context, releaseID int) (*PatchRow, error)
GetPatchesByReleaseID(ctx context.Context, releaseID int) ([]PatchWithChannelRow, error)
PromotePatch(ctx context.Context, patchID, channelID int) error
GetLatestPromotedPatch(ctx context.Context, releaseID, channelID int) (*PatchWithArtifactRow, error)
GetLatestPromotedPatch(ctx context.Context, releaseID, channelID int, arch, platform string) (*PatchWithArtifactRow, error)
// --- Patch Artifacts ---
CreatePatchArtifact(ctx context.Context, patchID int, arch, platform, hash, storageKey string, size int64, hashSignature, podfileLockHash *string) (*PatchArtifactRow, error)