public async Task CanTestWithSkip(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationTestSettings { Collection = new RootCollection(schemaName, "order", "Orders") { Patch = "throw 'skip';" } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings.Collection, settings.BinaryToAttachment); var exception = Assert.Throws <InvalidOperationException>(() => { driver.Test(settings, schema, context); }); Assert.True(exception.Message.StartsWith("Document was skipped")); } } } }
public async Task CanTestWithPrimaryKeyValues(MigrationProvider provider) { const string tableName = "groups1"; const string collectionName = "Groups1"; using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationTestSettings { Collection = new RootCollection(schemaName, tableName, collectionName), Mode = MigrationTestMode.ByPrimaryKey, PrimaryKeyValues = new[] { "52" } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings.Collection, settings.BinaryToAttachment); var(document, id) = driver.Test(settings, schema, context); Assert.Equal($"{collectionName}/52", id); Assert.True(document.TryGet("Name", out string name)); Assert.Equal("G1.1.1", name); } } } }
public (BlittableJsonReaderObject Document, string Id) Test(MigrationTestSettings settings, DatabaseSchema dbSchema, DocumentsOperationContext context) { using (var enumerationConnection = OpenConnection()) using (var referencesConnection = OpenConnection()) { var collectionToImport = settings.Collection; var tableSchema = dbSchema.GetTable(collectionToImport.SourceTableSchema, collectionToImport.SourceTableName); var specialColumns = dbSchema.FindSpecialColumns(collectionToImport.SourceTableSchema, collectionToImport.SourceTableName); string CollectionNameProvider(string schema, string name) => settings.CollectionsMapping.Single(x => x.TableSchema == schema && x.TableName == name).CollectionName; using (var patcher = new JsPatcher(collectionToImport, context)) { var references = ResolveReferences(collectionToImport, dbSchema, CollectionNameProvider); InitializeDataProviders(references, referencesConnection); try { Dictionary <string, object> queryParameters = null; var queryToUse = settings.Mode == MigrationTestMode.First ? GetQueryForCollection(collectionToImport) // we limit rows count internally by passing rowsLimit: 1 : GetQueryByPrimaryKey(collectionToImport, tableSchema.PrimaryKeyColumns, settings.PrimaryKeyValues, out queryParameters); foreach (var doc in EnumerateTable(queryToUse, collectionToImport.ColumnsMapping, specialColumns, collectionToImport.AttachmentNameMapping, enumerationConnection, rowsLimit: 1, queryParameters: queryParameters)) { doc.SetCollection(collectionToImport.Name); var id = GenerateDocumentId(doc.Collection, GetColumns(doc.SpecialColumnsValues, tableSchema.PrimaryKeyColumns)); FillDocumentFields(doc.Object, doc.SpecialColumnsValues, references, "", doc.Attachments); return(patcher.Patch(doc.ToBlittable(context)), id); } } catch (JavaScriptException e) { if (e.InnerException is Jint.Runtime.JavaScriptException innerException && string.Equals(innerException.Message, "skip", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("Document was skipped", e); }
public async Task CanTestWithEmbed(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationTestSettings { Collection = new RootCollection(schemaName, "order", "Orders") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "order_item", RelationType.OneToMany, new List <string> { "order_id" }, "Items") } } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings.Collection, settings.BinaryToAttachment); var(document, id) = driver.Test(settings, schema, context); Assert.Equal("Orders/1", id); Assert.True(document.TryGet("Total", out double total)); Assert.Equal(440, total); var items = document["Items"] as BlittableJsonReaderArray; Assert.NotNull(items); Assert.Equal(2, items.Length); } } } }