Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sql] az sql midb update: Add update command #22790

Merged
merged 6 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -920,6 +920,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 @@ -2099,13 +2099,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 @@ -4688,6 +4688,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 @@ -5164,6 +5164,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