Repository navigation
Support multiple container unique-key constraints - #320
Open
Mike Krüger (mkrueger) wants to merge 1 commit into
Open
Mike Krüger (mkrueger) wants to merge 1 commit into
Mike Krüger (mkrueger) wants to merge 1 commit into
Conversation
Mike Krüger (mkrueger)
requested review from
a team
and
a balanced review from Copilot
November 30, 2026 13:14
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Regression coverage is missing for rejecting --unique_key_policy on item and database targets and their aliases, including empty values, before backend access.
1 open issue
What changed in this PR
Adds full unique-key policy support to container creation, allowing independent and composite constraints through CLI and MCP on data-plane and ARM connections.
Changes:
- Adds
--unique_key_policywith structure and limit validation, while retaining the legacy composite-key argument. - Passes multiple constraints to both backends and rejects policy-bearing requests for existing containers.
- Updates help, documentation, and tests for binding, validation, and backend behavior.
| File | Description |
|---|---|
| l10n/CosmosDBShell.json | Updates generated help and error messages. |
| docs/commands.md | Documents policy syntax and creation-only behavior. |
| CosmosDBShell/lang/en.ftl | Adds localized option descriptions and errors. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ICosmosResourceOperations.cs | Accepts multiple unique-key constraints. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ExistingContainerUniqueKeyPolicyException.cs | Adds a dedicated existing-container error. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/DataPlaneCosmosResourceOperations.cs | Builds multiple constraints and rejects existing containers with policies. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosResourceFacade.cs | Forwards structured constraints to resource operations. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CosmosArmResourceProvider.cs | Builds ARM policies and checks container existence before writing. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ArmCosmosResourceOperations.cs | Passes structured constraints to the ARM provider. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/MakeContainerCommand.cs | Binds and validates policies and translates backend errors. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CreateCommand.cs | Forwards the option and restricts it to container targets. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ContainerUniqueKeyPolicy.cs | Parses legacy and JSON inputs and validates constraints. |
| CosmosDBShell.Tests/McpConfirmationTests.cs | Tests MCP policy binding for both commands. |
| CosmosDBShell.Tests/CommandTests/ServerlessCreationThroughputTests.cs | Tests CLI binding, validation, backend payloads, and existing-container rejection. |
Review effort: Balanced
Comment on lines
+58
to
+60
| if (this.UniqueKeyPolicy is not null && !IsContainer(item)) | ||
| { | ||
| throw CommandException.Usage("create", MessageService.GetString("command-create-error_unique_key_policy_only_for_containers")); |
Code coverage overviewLanguages: C# C# / code-coverage/dotnet
View coverage of the 5 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Add
--unique_key_policytomkconandcreate containerso users can define multiple independent or composite unique-key constraints through the CLI or MCP, on both data-plane and ARM connections. EachuniqueKeysentry defines a separate constraint; multiple paths in one entry form a composite constraint.unique_keyargument still defines one composite constraint and cannot be combined with the new option.existingresult for legacyunique_keycalls. For that idempotent result, omit the policy when re-running against an existing container.Fixes #312