mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem `getDatabaseMajorVersion` and `getSemanticVersion` in `apps/studio/lib/helpers.ts` returned `NaN` for Postgres versions with an architecture prefix, e.g. `supabase-postgres-arm64-17.9.0.019` (expected 17 / 1790019). `parseAppVersionKey` already handled `arm64-` and `x86_64-`, but the two helpers did not. Fixes FE-4974 Closes #53109 ## Solution - `formatSemver` now strips any leading architecture token (`^[a-z][a-z0-9_]*-`) rather than a hardcoded list. A version segment always starts with a digit, so this covers `arm`, `arm64`, `x86_64`, `aarch64`, `amd64` and future values. - `APP_VERSION_KEY_RE` in `useSelectedProject.utils.ts` uses the same rule, so the two parsers stay consistent. - Because the rule is generic, strings like `supabase-postgres-custom-123` would otherwise parse as a number. `formatSemver` now rejects anything that doesn't look like `\d+.\d+` after stripping, and both helpers return `0` for it (matching their existing empty-string behavior). Callers only compare the result numerically, so `0` behaves like the previous `NaN`. Tests cover each prefix on both helpers and on `parseAppVersionKey`, a release suffix (`-vault-rc1`), and non-version strings. Not changed: `getSemanticVersion` concatenates segments without padding (`17.10.0.001` becomes 171001, which compares below `17.9.0.019`). That predates this change and its callers pin to a single major line.
43 lines
1.9 KiB
TypeScript
43 lines
1.9 KiB
TypeScript
export type OrioleDbReleaseStage = 'alpha' | 'beta'
|
|
|
|
// OrioleDB engine versions ship as 4-part strings (e.g. `17.11.0.001`), which
|
|
// `lib/semver` doesn't parse (it's strict 3-part semver), so compare them separately here.
|
|
export const ORIOLEDB_PUBLIC_BETA_VERSION = 'supabase-postgres-17.11.0.001-orioledb'
|
|
|
|
// Sortable [major, minor, patch, build] key parsed from a dbVersion string like
|
|
// `supabase-postgres-17.11.0.001-orioledb` or `supabase-postgres-arm64-17.11.0.001`.
|
|
const APP_VERSION_KEY_RE = /^supabase-postgres-(?:[a-z][a-z0-9_]*-)?(\d+)\.(\d+)\.(\d+)\.(\d+)/
|
|
|
|
export type AppVersionKey = [number, number, number, number]
|
|
|
|
// Returns null for non-conforming strings — callers should treat null as "not orderable".
|
|
export function parseAppVersionKey(version: string | null | undefined): AppVersionKey | null {
|
|
if (!version) return null
|
|
|
|
const match = APP_VERSION_KEY_RE.exec(version)
|
|
if (!match) return null
|
|
|
|
return [Number(match[1]), Number(match[2]), Number(match[3]), Number(match[4])]
|
|
}
|
|
|
|
// Negative when `a` is older, zero when equal, positive when newer.
|
|
// Throws on unparseable input — null-tolerant callers parse first.
|
|
export function compareAppVersions(a: string, b: string): number {
|
|
const keyA = parseAppVersionKey(a)
|
|
const keyB = parseAppVersionKey(b)
|
|
if (!keyA) throw new Error(`unparseable app_version: ${a}`)
|
|
if (!keyB) throw new Error(`unparseable app_version: ${b}`)
|
|
|
|
return keyA[0] - keyB[0] || keyA[1] - keyB[1] || keyA[2] - keyB[2] || keyA[3] - keyB[3]
|
|
}
|
|
|
|
export function appVersionAtLeast(version: string, threshold: string): boolean {
|
|
if (!parseAppVersionKey(version)) return false
|
|
return compareAppVersions(version, threshold) >= 0
|
|
}
|
|
|
|
export const isOrioleDbVersionAtLeast = (dbVersion: string | undefined, threshold: string) => {
|
|
if (!dbVersion?.endsWith('orioledb') || !threshold.endsWith('orioledb')) return false
|
|
return appVersionAtLeast(dbVersion, threshold)
|
|
}
|