Skip to content

Support multiple container unique-key constraints - #320

Open
Mike Krüger (mkrueger) wants to merge 3 commits into
mainfrom
dev/mkrueger/fix/312-unique-key-policy
Open

Mike Krüger (mkrueger) wants to merge 3 commits into
mainfrom
dev/mkrueger/fix/312-unique-key-policy

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Add --unique_key_policy to mkcon and create container so users can define multiple independent or composite unique-key constraints through the CLI or MCP, on both data-plane and ARM connections. Each uniqueKeys entry defines a separate constraint; multiple paths in one entry form a composite constraint.

  • Pass the policy as a JSON string. The shell validates its structure and limits before issuing a write. The existing comma-separated unique_key argument still defines one composite constraint and cannot be combined with the new option.
  • When either input supplies a policy, an existing container now produces an error. On the data plane, this replaces the previous existing result for legacy unique_key calls. For that idempotent result, omit the policy when re-running against an existing container.
  • ARM checks for an existing container before calling create-or-update. The check is not atomic; avoid concurrent creation attempts for the same name.

Fixes #312

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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_policy with 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

@github-code-quality

github-code-quality Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 39b7be3 dev/mkrueger/fix/312... 0c528c2 +/-
76% 76% 0%
View coverage of the 5 most impacted files.
File main 39b7be3 dev/mkrueger/fix/312... 0c528c2 +/-
D:\a\CosmosDBSh...ainerCommand.cs 89% 88% -1%
D:\a\CosmosDBSh...ceOperations.cs 57% 58% +1%
D:\a\CosmosDBSh...urceProvider.cs 65% 66% +1%
D:\a\CosmosDBSh...reateCommand.cs 79% 81% +2%
D:\a\CosmosDBSh...queKeyPolicy.cs 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated December 01, 2026 11:00 UTC

Copilot AI balanced review requested due to automatic review settings December 1, 2026 10:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the unique-key policy changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple independent unique-key constraints during container creation

3 participants