コード例 #1
0
        public void When_migrating_down_Then_all_migrations_are_used()
        {
            // Arrange
            BsonDocument document = new BsonDocument
            {
                { "Version", "0.0.2" },
                { "Door", 3 }
            };

            // Act
            _runner.Run(typeof(TestDocumentWithTwoMigration), document);

            // Assert
            document.Names.ToList()[1].Should().Be("Dors");
            document.Values.ToList()[0].AsString.Should().Be("0.0.0");
        }
コード例 #2
0
        public override TDocument Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            // TODO: Performance? LatestVersion, dont do anything
            var document = BsonDocumentSerializer.Instance.Deserialize(context);

            _migrationRunner.Run(typeof(TDocument), document);

            var migratedContext =
                BsonDeserializationContext.CreateRoot(new BsonDocumentReader(document));

            return(base.Deserialize(migratedContext, args));
        }
コード例 #3
0
        public void RunAll()
        {
            var locations = _collectionLocator.GetLocatesOrEmpty();

            foreach (var locate in locations)
            {
                var information       = locate.Value;
                var type              = locate.Key;
                var databaseName      = GetDatabaseOrDefault(information);
                var collectionVersion = _versionService.GetCollectionVersion(type);

                var collection = _client.GetDatabase(databaseName)
                                 .GetCollection <BsonDocument>(information.Collection);

                var bulk = new List <WriteModel <BsonDocument> >();

                var query = CreateQueryForRelevantDocuments(type);

                using (var cursor = collection.FindSync(query))
                {
                    while (cursor.MoveNext())
                    {
                        var batch = cursor.Current;
                        foreach (var document in batch)
                        {
                            _migrationRunner.Run(type, document, collectionVersion);


                            var update = new ReplaceOneModel <BsonDocument>(
                                new BsonDocument {
                                { "_id", document["_id"] }
                            },
                                document
                                );

                            bulk.Add(update);
                        }
                    }
                }

                if (bulk.Count > 0)
                {
                    collection.BulkWrite(bulk);
                }
            }
        }