Skip to content
Open
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 linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3504,3 +3504,11 @@ neon postgres organization:
neon postgres project:
rule_exclusions:
- require_wait_command_if_no_wait

cosmosdb sql softdeleted-database list:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont know why but i kept getting these errors, so i had to exclude

rule_exclusions:
- no_ids_for_list_commands

cosmosdb sql softdeleted-collection list:
rule_exclusions:
- no_ids_for_list_commands
7 changes: 7 additions & 0 deletions src/cosmosdb-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Release History
===============

1.7.0
+++++
* Add support for soft-deleted resource operations for SQL API
* New command group `az cosmosdb sql softdeleted-account` to list, show, delete (purge), and recover soft-deleted accounts
* New command group `az cosmosdb sql softdeleted-database` to list, show, delete (purge), and recover soft-deleted databases
* New command group `az cosmosdb sql softdeleted-collection` to list, show, delete (purge), and recover soft-deleted containers

1.6.1
+++++
* Fix SQL container throughput update to preserve existing throughput buckets when not explicitly specified.
Expand Down
13 changes: 13 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,16 @@ def cf_fleetspace_account(cli_ctx, _):

def cf_fleet_analytics(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).fleet_analytics


# soft-deleted resources
def cf_softdeleted_database_accounts(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).soft_deleted_database_accounts


def cf_softdeleted_sql_databases(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).soft_deleted_sql_databases


def cf_softdeleted_sql_containers(cli_ctx, _):
return cf_cosmosdb_preview(cli_ctx).soft_deleted_sql_containers
128 changes: 128 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@
text: az cosmosdb update --capabilities EnableGremlin --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup
- name: Update an Azure Cosmos DB database account to enable materialized views.
text: az cosmosdb update --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --enable-materialized-views true
- name: Enable soft deletion with 1440 minutes (24 hours) retention.
text: az cosmosdb update --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --enable-soft-deletion true --sd-retention 1440 --min-purge-minutes 60
"""

# restore account
Expand Down Expand Up @@ -1844,3 +1846,129 @@
type: command
short-summary: Delete a Fleet Analytics resource from a Fleet.
"""

helps['cosmosdb sql softdeleted-account'] = """
type: group
short-summary: Manage soft-deleted Azure Cosmos DB accounts.
"""

helps['cosmosdb sql softdeleted-account list'] = """
type: command
short-summary: List soft-deleted Azure Cosmos DB accounts.
examples:
- name: List all soft-deleted Azure Cosmos DB accounts in a subscription.
text: |
az cosmosdb sql softdeleted-account list
- name: List soft-deleted Azure Cosmos DB accounts in a specific location.
text: |
az cosmosdb sql softdeleted-account list --location westus
"""

helps['cosmosdb sql softdeleted-account show'] = """
type: command
short-summary: Show details of a soft-deleted Azure Cosmos DB account.
examples:
- name: Show details of a soft-deleted Azure Cosmos DB account.
text: |
az cosmosdb sql softdeleted-account show --location westus --account-name MyAccount
"""

helps['cosmosdb sql softdeleted-account delete'] = """
type: command
short-summary: Permanently delete a soft-deleted Azure Cosmos DB account.
examples:
- name: Permanently delete a soft-deleted Azure Cosmos DB account.
text: |
az cosmosdb sql softdeleted-account delete --location westus --account-name MyAccount --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-account recover'] = """
type: command
short-summary: Recover a soft-deleted Azure Cosmos DB account.
examples:
- name: Recover a soft-deleted Azure Cosmos DB account.
text: |
az cosmosdb sql softdeleted-account recover --location westus --account-name MyAccount --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-database'] = """
type: group
short-summary: Manage soft-deleted databases for Azure Cosmos DB SQL API.
"""

helps['cosmosdb sql softdeleted-database list'] = """
type: command
short-summary: List all soft-deleted databases for an Azure Cosmos DB account.
examples:
- name: List all soft-deleted databases for an Azure Cosmos DB account.
text: |
az cosmosdb sql softdeleted-database list --location westus --account-name MyAccount --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-database show'] = """
type: command
short-summary: Show details of a soft-deleted database.
examples:
- name: Show details of a soft-deleted database.
text: |
az cosmosdb sql softdeleted-database show --location westus --account-name MyAccount --name MyDatabase --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-database delete'] = """
type: command
short-summary: Permanently delete a soft-deleted database.
examples:
- name: Permanently delete a soft-deleted database.
text: |
az cosmosdb sql softdeleted-database delete --location westus --account-name MyAccount --name MyDatabase --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-database recover'] = """
type: command
short-summary: Recover a soft-deleted database.
examples:
- name: Recover a soft-deleted database.
text: |
az cosmosdb sql softdeleted-database recover --location westus --account-name MyAccount --name MyDatabase --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-collection'] = """
type: group
short-summary: Manage soft-deleted collections for Azure Cosmos DB SQL API.
"""

helps['cosmosdb sql softdeleted-collection list'] = """
type: command
short-summary: List all soft-deleted collections in a database.
examples:
- name: List all soft-deleted collections in a database.
text: |
az cosmosdb sql softdeleted-collection list --location westus --account-name MyAccount --database-name MyDatabase --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-collection show'] = """
type: command
short-summary: Show details of a soft-deleted collection.
examples:
- name: Show details of a soft-deleted collection.
text: |
az cosmosdb sql softdeleted-collection show --location westus --account-name MyAccount --database-name MyDatabase --name MyCollection --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-collection delete'] = """
type: command
short-summary: Permanently delete a soft-deleted collection.
examples:
- name: Permanently delete a soft-deleted collection.
text: |
az cosmosdb sql softdeleted-collection delete --location westus --account-name MyAccount --database-name MyDatabase --name MyCollection --resource-group MyResourceGroup
"""

helps['cosmosdb sql softdeleted-collection recover'] = """
type: command
short-summary: Recover a soft-deleted collection.
examples:
- name: Recover a soft-deleted collection.
text: |
az cosmosdb sql softdeleted-collection recover --location westus --account-name MyAccount --database-name MyDatabase --name MyCollection --resource-group MyResourceGroup
"""
75 changes: 75 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ def load_arguments(self, _):

with self.argument_context('cosmosdb update') as c:
c.argument('key_uri', help="The URI of the key vault", is_preview=True)
c.argument('enable_soft_deletion', arg_type=get_three_state_flag(), help="Flag to enable or disable soft deletion on the account.", is_preview=True, arg_group='Soft Delete')
c.argument('soft_deletion_retention_period_in_minutes', options_list=['--soft-deletion-retention-period-in-minutes', '--sd-retention'], type=int, help="Soft deletion retention period in minutes. Must be at least equal to min_minutes_before_permanent_deletion_allowed.", is_preview=True, arg_group='Soft Delete')
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text for soft_deletion_retention_period_in_minutes states "Must be at least equal to min_minutes_before_permanent_deletion_allowed" but uses the internal parameter name. For better user experience, it should reference the user-facing option name: "Must be at least equal to --min-purge-minutes".

Suggested change
c.argument('soft_deletion_retention_period_in_minutes', options_list=['--soft-deletion-retention-period-in-minutes', '--sd-retention'], type=int, help="Soft deletion retention period in minutes. Must be at least equal to min_minutes_before_permanent_deletion_allowed.", is_preview=True, arg_group='Soft Delete')
c.argument('soft_deletion_retention_period_in_minutes', options_list=['--soft-deletion-retention-period-in-minutes', '--sd-retention'], type=int, help="Soft deletion retention period in minutes. Must be at least equal to --min-purge-minutes.", is_preview=True, arg_group='Soft Delete')

Copilot uses AI. Check for mistakes.
c.argument('min_minutes_before_permanent_deletion_allowed', options_list=['--min-minutes-before-permanent-deletion-allowed', '--min-purge-minutes'], type=int, help="Minimum minutes before permanent deletion is allowed for soft-deleted resources.", is_preview=True, arg_group='Soft Delete')

with self.argument_context('cosmosdb restore') as c:
c.argument('target_database_account_name', options_list=['--target-database-account-name', '-n'], help='Name of the new target Cosmos DB database account after the restore')
Expand Down Expand Up @@ -829,6 +832,78 @@ def load_arguments(self, _):
c.argument('scope', options_list=['--scope', '-s'], help="Data plane resource path at which this Role Assignment is being granted.")
c.argument('principal_id', options_list=['--principal-id', '-p'], help="AAD Object ID of the principal to which this Role Assignment is being granted.")

# Soft-deleted Account
with self.argument_context('cosmosdb sql softdeleted-account list') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=False)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-account show') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=True)
c.argument('account_name', options_list=['--account-name', '-n'], help="Name of the soft-deleted Cosmos DB account.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-account delete') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=True)
c.argument('account_name', options_list=['--account-name', '-n'], help="Name of the soft-deleted Cosmos DB account to purge.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-account recover') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=True)
c.argument('account_name', options_list=['--account-name', '-n'], help="Name of the soft-deleted Cosmos DB account to recover.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

# Soft-deleted Database
with self.argument_context('cosmosdb sql softdeleted-database list') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-database show') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--name', '-n'], help="Name of the soft-deleted database.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-database delete') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--name', '-n'], help="Name of the soft-deleted database to purge.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-database recover') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--name', '-n'], help="Name of the soft-deleted database to recover.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

# Soft-deleted Collection
with self.argument_context('cosmosdb sql softdeleted-collection list') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-collection show') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
c.argument('container_name', options_list=['--name', '-n'], help="Name of the soft-deleted container.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-collection delete') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
c.argument('container_name', options_list=['--name', '-n'], help="Name of the soft-deleted container to purge.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

with self.argument_context('cosmosdb sql softdeleted-collection recover') as c:
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
c.argument('container_name', options_list=['--name', '-n'], help="Name of the soft-deleted container to recover.", required=True)
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)

# Cosmos DB Fleet
with self.argument_context('cosmosdb fleet') as c:
c.argument('resource_group', options_list=['--resource-group', '-g'], help='Name of the resource group.', required=True)
Expand Down
48 changes: 47 additions & 1 deletion src/cosmosdb-preview/azext_cosmosdb_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
cf_fleet,
cf_fleetspace,
cf_fleetspace_account,
cf_fleet_analytics
cf_fleet_analytics,
cf_softdeleted_database_accounts,
cf_softdeleted_sql_databases,
cf_softdeleted_sql_containers
)


Expand Down Expand Up @@ -220,6 +223,19 @@ def load_command_table(self, _):
operations_tmpl='azure.mgmt.cosmosdb.operations#RestorableDatabaseAccountsOperations.{}',
client_factory=cf_restorable_database_accounts)

# Soft-deleted resources SDK types
cosmosdb_softdeleted_accounts_sdk = CliCommandType(
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SoftDeletedDatabaseAccountsOperations.{}',
client_factory=cf_softdeleted_database_accounts)

cosmosdb_softdeleted_sql_databases_sdk = CliCommandType(
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SoftDeletedSqlDatabasesOperations.{}',
client_factory=cf_softdeleted_sql_databases)

cosmosdb_softdeleted_sql_containers_sdk = CliCommandType(
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SoftDeletedSqlContainersOperations.{}',
client_factory=cf_softdeleted_sql_containers)

# define commands
# Restorable apis for sql,mongodb,gremlin and table
# Provisioning/migrate Continuous 7 days accounts
Expand Down Expand Up @@ -367,6 +383,36 @@ def load_command_table(self, _):
with self.command_group('cosmosdb table', cosmosdb_table_sdk, client_factory=cf_table_resources) as g:
g.custom_command('restore', 'cli_cosmosdb_table_restore', is_preview=True)

# Soft-deleted Account commands
with self.command_group('cosmosdb sql softdeleted-account',
cosmosdb_softdeleted_accounts_sdk,
client_factory=cf_softdeleted_database_accounts,
is_preview=True) as g:
g.custom_command('list', 'cli_cosmosdb_sql_softdeleted_account_list')
g.custom_show_command('show', 'cli_cosmosdb_sql_softdeleted_account_show')
g.custom_command('delete', 'cli_cosmosdb_sql_softdeleted_account_delete', confirmation=True)
g.custom_command('recover', 'cli_cosmosdb_sql_softdeleted_account_recover')

# Soft-deleted Database commands
with self.command_group('cosmosdb sql softdeleted-database',
cosmosdb_softdeleted_sql_databases_sdk,
client_factory=cf_softdeleted_sql_databases,
is_preview=True) as g:
g.custom_command('list', 'cli_cosmosdb_sql_softdeleted_database_list')
g.custom_show_command('show', 'cli_cosmosdb_sql_softdeleted_database_show')
g.custom_command('delete', 'cli_cosmosdb_sql_softdeleted_database_delete', confirmation=True)
g.custom_command('recover', 'cli_cosmosdb_sql_softdeleted_database_recover')

# Soft-deleted Collection commands
with self.command_group('cosmosdb sql softdeleted-collection',
cosmosdb_softdeleted_sql_containers_sdk,
client_factory=cf_softdeleted_sql_containers,
is_preview=True) as g:
g.custom_command('list', 'cli_cosmosdb_sql_softdeleted_collection_list')
g.custom_show_command('show', 'cli_cosmosdb_sql_softdeleted_collection_show')
g.custom_command('delete', 'cli_cosmosdb_sql_softdeleted_collection_delete', confirmation=True)
g.custom_command('recover', 'cli_cosmosdb_sql_softdeleted_collection_recover')

setup_mongocluster_commands(self)

setup_fleet_commands(self)
Expand Down
Loading
Loading