Skip to content

Commit

Permalink
[sql] az sql midb update: Add update command (#22790)
Browse files Browse the repository at this point in the history
* support update operation and tags parameter on create and update

* custom command

* call update instead from sdk

* Add help file change

* Adding test and change update logic a bit

Co-authored-by: Milan Brkic <[email protected]>
  • Loading branch information
milanbrkic-ms and MDCS-sql authored Jun 30, 2022
1 parent 93d2b3b commit 415c45b
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 825 deletions.
8 changes: 8 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,14 @@
text: az sql midb create -g mygroup --mi myinstance -n mymanageddb --collation Latin1_General_100_CS_AS_SC
"""

helps['sql midb update'] = """
type: command
short-summary: Update a managed database.
examples:
- name: Update a managed database with specified tags
text: az sql midb update -g mygroup --mi myinstance -n mymanageddb --tags tag1="value1"
"""

helps['sql midb delete'] = """
type: command
short-summary: Delete a managed database.
Expand Down
11 changes: 11 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,13 +2147,24 @@ def _configure_security_policy_storage_params(arg_ctx):
create_args_for_complex_type(
c, 'parameters', ManagedDatabase, [
'collation',
'tags',
])

c.argument('tags', arg_type=tags_type)

c.argument('collation',
required=False,
help='The collation of the Azure SQL Managed Database collation to use, '
'e.g.: SQL_Latin1_General_CP1_CI_AS or Latin1_General_100_CS_AS_SC')

with self.argument_context('sql midb update') as c:
create_args_for_complex_type(
c, 'parameters', ManagedDatabase, [
'tags',
])

c.argument('tags', arg_type=tags_type)

with self.argument_context('sql midb restore') as c:
create_args_for_complex_type(
c, 'parameters', ManagedDatabase, [
Expand Down
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,10 @@ def load_command_table(self, _):
client_factory=get_sql_managed_databases_operations) as g:

g.custom_command('create', 'managed_db_create', supports_no_wait=True)
g.generic_update_command('update',
setter_name='begin_create_or_update',
custom_func_name='managed_db_update',
supports_no_wait=True)
g.custom_command('restore', 'managed_db_restore', supports_no_wait=True)
g.show_command('show', 'get')
g.command('list', 'list_by_instance')
Expand Down
10 changes: 10 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4692,6 +4692,16 @@ def managed_db_create(
parameters=kwargs)


def managed_db_update(
instance,
tags=None):

if tags is not None:
instance.tags = tags

return instance


def managed_db_restore(
cmd,
client,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5243,6 +5243,18 @@ def test_sql_managed_db_mgmt(self, mi, rg):
.format(resource_group_1, managed_instance_name_1),
checks=[JMESPathCheck('length(@)', 2)])

self.cmd('sql midb update -g {} --managed-instance {} -n {} --tags {}'
.format(resource_group_1, managed_instance_name_1, database_name, "bar=foo"),
checks=[JMESPathCheck('tags', "{'bar': 'foo'}")])

# test merge managed database tags
tag3 = "tagName3=tagValue3"
self.cmd('sql midb update -g {} --managed-instance {} -n {} --set tags.{}'
.format(resource_group_1, managed_instance_name_1, database_name, tag3),
checks=[
JMESPathCheck('tags',
"{'bar': 'foo', 'tagName3': 'tagValue3'}")])

# Show by group/managed_instance/database-name
self.cmd('sql midb show -g {} --managed-instance {} -n {}'
.format(resource_group_1, managed_instance_name_1, database_name),
Expand Down

0 comments on commit 415c45b

Please sign in to comment.