diff --git a/internal/api/handlers/device.go b/internal/api/handlers/device.go index 75946f7..0ca54d1 100644 --- a/internal/api/handlers/device.go +++ b/internal/api/handlers/device.go @@ -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{ diff --git a/internal/db/db.go b/internal/db/db.go index 594548d..1ec3f05 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -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 { diff --git a/internal/db/sqlite.go b/internal/db/sqlite.go index 1a167e0..52c1146 100644 --- a/internal/db/sqlite.go +++ b/internal/db/sqlite.go @@ -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 } diff --git a/internal/db/store.go b/internal/db/store.go index 49dce2e..ee2c27e 100644 --- a/internal/db/store.go +++ b/internal/db/store.go @@ -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)