Exemple #1
0
                        IList <ContainerProperties> containersToDelete) SplitContainers(
            MigratableDatabase requestedDatabase, IList <ContainerProperties> cloudContainers)
        {
            var containersToCreate = requestedDatabase.Containers
                                     .Where(c => cloudContainers.All(cc => cc.Id != c.Id))
                                     .ToList();

            var containersToUpdate = requestedDatabase.Containers
                                     .Where(c => cloudContainers.Any(cc => cc.Id == c.Id))
                                     .ToList();

            var containersToDelete = cloudContainers
                                     .Where(c => !containersToCreate.Any(cc => cc.Id == c.Id))
                                     .Where(c => !containersToUpdate.Any(cc => cc.Id == c.Id))
                                     .ToList();

            return(containersToCreate, containersToUpdate, containersToDelete);
        }
Exemple #2
0
        private async Task <Database> CreateOrGetDatabase(CosmosClient client, MigratableDatabase requestedDatabase)
        {
            var response =
                await client.CreateDatabaseIfNotExistsAsync(requestedDatabase.Id, requestedDatabase.Throughput);

            var cloudDatabase = response.Database;

            if (response.StatusCode != HttpStatusCode.Created && requestedDatabase.Throughput.HasValue)
            {
                _logger.LogInformation("Database already exists, replacing throughput");
                await cloudDatabase.ReplaceThroughputAsync(requestedDatabase.Throughput.Value);
            }
            else
            {
                _logger.LogInformation("Created new database");
            }

            return(cloudDatabase);
        }