Skip to content

Commit db712c8

Browse files
{SQL} Display warning message when Azure SQL DB with Geo-replicated-link is updated to Hyperscale tier (#31344)
* Print warning message during update slo to Hyperscale for a geo-replicated database * Auto generated test changes after running tests in record mode * Revert "Auto generated test changes after running tests in record mode" This reverts commit 9cec2ad. * Recorded tests * Update logic to return boolean instead of tuple and function name changes * Recorded tests
1 parent 6ea66d1 commit db712c8

12 files changed

+6934
-8418
lines changed

src/azure-cli/azure/cli/command_modules/sql/custom.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
get_sql_managed_instances_operations,
9090
get_sql_restorable_dropped_database_managed_backup_short_term_retention_policies_operations,
9191
get_sql_managed_database_restore_details_operations,
92+
get_sql_replication_links_operations,
93+
get_sql_elastic_pools_operations,
9294
)
9395

9496

@@ -1219,6 +1221,56 @@ def _backup_storage_redundancy_take_source_warning():
12191221
To learn more about Azure Paired Regions visit https://aka.ms/azure-ragrs-regions.""")
12201222

12211223

1224+
def _should_show_forward_migration_with_links_warnings(
1225+
cli_ctx,
1226+
instance,
1227+
server_name,
1228+
resource_group_name):
1229+
'''
1230+
Checks if the database update operation is a forward migration to Hyperscale and if geo-replication links exist.
1231+
1232+
:param cli_ctx: The CLI context object to interact with Azure SQL.
1233+
:param instance: The database instance object.
1234+
:param server_name: The name of the server.
1235+
:param resource_group_name: The name of the resource group.
1236+
:return: A boolean indicating if it is forward migration of database with geo-replication links.
1237+
'''
1238+
1239+
# Find the replication links for the database
1240+
replication_links_client = get_sql_replication_links_operations(cli_ctx, None)
1241+
links = list(replication_links_client.list_by_database(
1242+
database_name=instance.name,
1243+
server_name=server_name,
1244+
resource_group_name=resource_group_name))
1245+
1246+
elastic_pools_client = get_sql_elastic_pools_operations(cli_ctx, None)
1247+
elastic_pool = None
1248+
if instance.elastic_pool_id:
1249+
elastic_pool = elastic_pools_client.get(
1250+
elastic_pool_name=instance.elastic_pool_id.split('/')[-1],
1251+
server_name=server_name,
1252+
resource_group_name=resource_group_name)
1253+
1254+
# Check if the current SKU is not Hyperscale and the target SKU is Hyperscale
1255+
# This is to verify forward migration to Hyperscale
1256+
current_sku = instance.current_sku.name if instance.current_sku else None
1257+
target_sku = instance.sku.name if instance.sku else None
1258+
is_target_hyperscale_pool = elastic_pool is not None and elastic_pool.sku.tier == "Hyperscale"
1259+
1260+
is_forward_migration = (
1261+
current_sku is not None and "HS" not in current_sku and
1262+
((target_sku is not None and "HS" in target_sku) or is_target_hyperscale_pool)
1263+
)
1264+
links_exist = links is not None and len(links) > 0
1265+
1266+
return is_forward_migration and links_exist
1267+
1268+
1269+
def _forward_migration_with_geodr_links_warning():
1270+
print("""Changing the service tier to Hyperscale also converts the geo-secondary replica to Hyperscale.
1271+
For more information, see https://go.microsoft.com/fwlink/?linkid=2314103""")
1272+
1273+
12221274
def db_create(
12231275
cmd,
12241276
client,
@@ -1840,6 +1892,10 @@ def db_update( # pylint: disable=too-many-locals, too-many-branches
18401892
if instance.elastic_pool_id:
18411893
instance.sku = None
18421894

1895+
# Display warning if database is being updated to Hyperscale and if geo-replication links exist
1896+
if _should_show_forward_migration_with_links_warnings(cmd.cli_ctx, instance, server_name, resource_group_name):
1897+
_forward_migration_with_geodr_links_warning()
1898+
18431899
#####
18441900
# Set other (non-sku related) properties
18451901
#####

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_forward_migration_manual_cutover.yaml

Lines changed: 291 additions & 435 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_free_params.yaml

Lines changed: 546 additions & 640 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_mgmt.yaml

Lines changed: 512 additions & 422 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_operation_mgmt.yaml

Lines changed: 146 additions & 578 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_preferred_enclave_type.yaml

Lines changed: 320 additions & 224 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_read_replica_mgmt.yaml

Lines changed: 447 additions & 351 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_serverless_mgmt.yaml

Lines changed: 537 additions & 969 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_db_vcore_mgmt.yaml

Lines changed: 635 additions & 1643 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/sql/tests/latest/recordings/test_sql_per_db_cmk.yaml

Lines changed: 137 additions & 89 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)