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

Add Cosmos database resource. #1583

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public override async Task GetOrCreateResourceAsync(
var connectionStrings = context.UserSecrets.Prop("ConnectionStrings");
connectionStrings[resource.Name] = resource.ConnectionString;

var existingDatabases = cosmosResource.GetCosmosDBSqlDatabases().GetAllAsync(cancellationToken);

await foreach (var existingDatabase in existingDatabases)
{
if (!resource.Databases.Any(d => d.Name == existingDatabase.Data.Name))
Copy link
Member

Choose a reason for hiding this comment

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

You could do a single pass over the set of databases but I'm not concerned about performance 😄

{
logger.LogInformation("Deleting database {DatabaseName}", existingDatabase.Data.Name);
await existingDatabase.DeleteAsync(WaitUntil.Completed, cancellationToken).ConfigureAwait(false);
}
}

foreach (var database in resource.Databases)
{
await CreateDatabaseIfNotExists(cosmosResource, database, cancellationToken).ConfigureAwait(false);
Expand Down