Skip to content

Commit

Permalink
{RDBMS} az postgres flexible-server create: Fix the comparator for so…
Browse files Browse the repository at this point in the history
…rting sku name so it also sort the core number too when displaying the error message (#30582)

Co-authored-by: Matthew Boentoro <mboentoro@microsoft.com>
  • Loading branch information
mattboentoro and Matthew Boentoro authored Jan 3, 2025
1 parent 77e4d7e commit 024cfb6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/azure-cli/azure/cli/command_modules/rdbms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,24 @@ def _pg_tier_validator(tier, sku_info):


def compare_sku_names(sku_1, sku_2):
regex_pattern = r"_v(\d)"
regex_pattern = r"\D+(?P<core_number>\d+)\D+(?P<version>\d*)"

sku_1_match = re.search(regex_pattern, sku_1)
sku_2_match = re.search(regex_pattern, sku_2)

return (int(sku_2_match.group(1)) if sku_2_match else 0) - \
(int(sku_1_match.group(1)) if sku_1_match else 0)
# the case where version number is different, sort by the version number first
if sku_1_match.group('version') and int(sku_2_match.group('version')) > int(sku_1_match.group('version')):
return 1
if sku_1_match.group('version') and int(sku_2_match.group('version')) < int(sku_1_match.group('version')):
return -1

# the case where version number is the same, we want to sort by the core number
if int(sku_2_match.group('core_number')) > int(sku_1_match.group('core_number')):
return 1
if int(sku_2_match.group('core_number')) < int(sku_1_match.group('core_number')):
return -1

return 0


def _pg_sku_name_validator(sku_name, sku_info, tier, instance):
Expand Down

0 comments on commit 024cfb6

Please sign in to comment.