public async Task Attachments(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, "actor", "Actors") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "actor_movie", RelationType.OneToMany, new List <string> { "a_id" }, "Movies") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "movie", RelationType.ManyToOne, new List <string> { "m_id" }, "Movie") } } } } } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings, true); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { var actor32 = session.Load <JObject>("Actors/32"); Assert.False(actor32.ContainsKey("Photo")); Assert.False(actor32.ContainsKey("photo")); var attachments = session.Advanced.Attachments.GetNames(actor32) .Select(x => x.Name) .OrderBy(x => x) .ToArray(); Assert.Equal(new[] { "Movies_0_Movie_File", "Movies_1_Movie_File", "Photo" }, attachments); var actor34 = session.Load <JObject>("Actors/34"); Assert.False(actor34.ContainsKey("Photo")); Assert.False(actor34.ContainsKey("photo")); Assert.Equal(0, session.Advanced.Attachments.GetNames(actor34).Length); } } } }
protected void ExecuteSqlQuery(MigrationProvider provider, string connectionString, string query) { switch (provider) { case MigrationProvider.MySQL: { using (var connection = new MySqlConnection(connectionString)) { connection.Open(); using (var cmd = new MySqlCommand(query, connection)) { cmd.ExecuteNonQuery(); } } break; } case MigrationProvider.MsSQL: using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var cmd = new SqlCommand(query, connection)) { cmd.ExecuteNonQuery(); } } break; default: throw new InvalidOperationException("Unable to run query. Unsupported provider: " + provider); } }
public async Task CanLimitRows(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, "movie", "Movies") }, MaxRowsPerTable = 2 }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { Assert.Equal(2, session.Advanced.LoadStartingWith <JObject>("Movies/").Length); } } } }
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 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 CanEmbedOnParent(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, tableName, collectionName) { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, tableName, RelationType.ManyToOne, new List <string> { "parent_group_id" }, "Parent") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, tableName, RelationType.ManyToOne, new List <string> { "parent_group_id" }, "Grandparent") } } } } } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { var group = session.Load <JObject>($"{collectionName}/53"); Assert.Equal("G1.1.1.1", group["Name"]); var parent = group["Parent"]; Assert.NotNull(parent); Assert.Equal("G1.1.1", parent["Name"]); var grandparent = parent["Grandparent"]; Assert.NotNull(grandparent); Assert.Equal("G1.1", grandparent["Name"]); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(7, collectionStatistics.CountOfDocuments); } } }
public async Task CanMigrateEmbedOnParent(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var collection = new RootCollection(schemaName, "order", "Orders") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "order_item", RelationType.OneToMany, new List <string> { "order_id" }, "Items") } }; var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationSettings { Collections = new List <RootCollection> { collection } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context, token : cts.Token); } using (var session = store.OpenSession()) { var order = session.Load <JObject>("Orders/1"); Assert.NotNull(order); // total and metadata, Id (Orders/1), Items Assert.Equal(4, order.Properties().Count()); Assert.Equal("Orders", order["@metadata"]["@collection"]); Assert.Equal(440, order["Total"]); Assert.Equal("Orders/1", order["Id"]); var firstItem = order["Items"][0]; Assert.Equal(110, firstItem["Price"]); Assert.Equal(1, firstItem.Count()); var secondItem = order["Items"][1]; Assert.Equal(330, secondItem["Price"]); Assert.Equal(1, secondItem.Count()); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(1, collectionStatistics.CountOfDocuments); } } }
public void CanCreateSqlEtlTransformScriptWithGuidWhenTableTypeGuid(MigrationProvider provider) { using (var store = GetDocumentStore()) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, dataSet: null, includeData: false)) { GetCreateTableWithUniqueType(provider, connectionString); CheckCount(provider, connectionString, 0); var sqlEtlConfigurationName = "test_" + Guid.NewGuid(); var connectionStringName = $"test_{store.Database}"; var operation = new PutConnectionStringOperation <SqlConnectionString>(new SqlConnectionString { Name = connectionStringName, FactoryName = GetFactoryName(provider), ConnectionString = connectionString }); store.Maintenance.Send(operation); var etlDone = new ManualResetEventSlim(); var configuration = new SqlEtlConfiguration { Name = sqlEtlConfigurationName, ConnectionStringName = connectionStringName, SqlTables = { new SqlEtlTable { TableName = "TestGuidEtls", DocumentIdColumn = "Id" }, },
public async Task CanMigrateEmbedOnChild(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var collection = new RootCollection(schemaName, "order_item", "OrderItems") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "order", RelationType.ManyToOne, new List <string> { "order_id" }, "Order") } }; var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationSettings { Collections = new List <RootCollection> { collection } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { var orderItem = session.Load <JObject>("OrderItems/10"); Assert.NotNull(orderItem); // price and metadata, Id (OrderItems/10), Order Assert.Equal(4, orderItem.Properties().Count()); Assert.Equal("OrderItems", orderItem["@metadata"]["@collection"]); Assert.Equal(110, orderItem["Price"]); Assert.Equal("OrderItems/10", orderItem["Id"]); var nestedOrder = orderItem["Order"]; Assert.NotNull(nestedOrder); Assert.Equal(1, nestedOrder.Count()); Assert.Equal(440, nestedOrder["Total"]); var orderItem2 = session.Load <JObject>("OrderItems/11"); Assert.NotNull(orderItem2); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(2, collectionStatistics.CountOfDocuments); } } }
public async Task BinaryAsNoAttachment(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, "actor", "Actors") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "actor_movie", RelationType.OneToMany, new List <string> { "a_id" }, "Movies") { NestedCollections = new List <EmbeddedCollection> { new EmbeddedCollection(schemaName, "movie", RelationType.ManyToOne, new List <string> { "m_id" }, "Movie") } } } } } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings, binaryToAttachment: false); await driver.Migrate(settings, schema, db, context, token : cts.Token); } using (var session = store.OpenSession()) { var actor32 = session.Load <JObject>("Actors/32"); Assert.Equal(0, session.Advanced.Attachments.GetNames(actor32).Length); Assert.Equal("MzI=", actor32["Photo"]); Assert.Equal("MjE=", actor32["Movies"][0]["Movie"]["File"]); Assert.Equal("MjM=", actor32["Movies"][1]["Movie"]["File"]); Assert.Equal(JTokenType.Null, actor32["Movies"][2]["Movie"]["File"].Type); var actor34 = session.Load <JObject>("Actors/34"); Assert.Equal(0, session.Advanced.Attachments.GetNames(actor34).Length); Assert.Equal(JTokenType.Null, actor34["Photo"].Type); } } } }
public async Task CanHandleMissingParentLink(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); var query = provider.Equals(MigrationProvider.Oracle) == false ? "update order_item set order_id = null" : "update \"order_item\" set \"order_id\" = null"; ExecuteSqlQuery(provider, connectionString, query); using (var store = GetDocumentStore()) { var orderItemCollection = new RootCollection(schemaName, "order_item", "OrderItems") { LinkedCollections = new List <LinkedCollection> { new LinkedCollection(schemaName, "order", RelationType.ManyToOne, new List <string> { "order_id" }, "ParentOrder") } }; var orderCollection = new RootCollection(schemaName, "order", "Orders"); var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationSettings { Collections = new List <RootCollection> { orderItemCollection, orderCollection } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { var orderItem = session.Load <JObject>("OrderItems/10"); Assert.NotNull(orderItem); Assert.True(orderItem.ContainsKey("ParentOrder")); Assert.Equal(JTokenType.Null, orderItem["ParentOrder"].Type); } } } }
public async Task CanLinkOnParent(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 Databases.GetDocumentDatabaseInstanceFor(store); var settings = new MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, tableName, collectionName) { LinkedCollections = new List <LinkedCollection> { new LinkedCollection(schemaName, tableName, RelationType.ManyToOne, new List <string> { "parent_group_id" }, "Parent") } } } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context, token : cts.Token); } using (var session = store.OpenSession()) { var g1111 = session.Load <JObject>($"{collectionName}/53"); Assert.Equal("G1.1.1.1", g1111["Name"]); var g111 = session.Load <JObject>(g1111["Parent"].ToString()); Assert.Equal("G1.1.1", g111["Name"]); var g11 = session.Load <JObject>(g111["Parent"].ToString()); Assert.Equal("G1.1", g11["Name"]); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(7, collectionStatistics.CountOfDocuments); } } }
public static IDatabaseDriver CreateDriver(MigrationProvider provider, string connectionString) { switch (provider) { case MigrationProvider.MsSQL: return(new MsSqlDatabaseMigrator(connectionString)); case MigrationProvider.MySQL: return(new MySqlDatabaseMigrator(connectionString)); default: throw new InvalidOperationException("Provider " + provider + " is not yet supported"); } }
public TsdbClient( IDynamicStorageSelector <TKey, TEntry> dynamicStorageSelector, IVolumeStorageSelector <TKey, TEntry> volumeStorageSelector, IPublishSubscribe <TKey, TEntry> remotePublishSubscribe, ITemporaryStorage <TKey, TEntry> temporaryStorage, ITsdbLogger logger) { _dynamicStorageSelector = dynamicStorageSelector; _volumeStorageSelector = volumeStorageSelector; _remotePublishSubscribe = remotePublishSubscribe; _temporaryStorage = temporaryStorage; _localPublishSubscribe = new DefaultPublishSubscribe <TKey, TEntry>(false); _logger = logger; _migrations = new MigrationProvider <TKey, TEntry>(_dynamicStorageSelector, _volumeStorageSelector); }
protected DisposableAction WithSqlDatabase(MigrationProvider provider, out string connectionString, out string schemaName, string dataSet = "northwind", bool includeData = true) { switch (provider) { case MigrationProvider.MySQL: return(WithMySqlDatabase(out connectionString, out schemaName, dataSet, includeData)); case MigrationProvider.MsSQL: schemaName = "dbo"; return(WithMsSqlDatabase(out connectionString, out string databaseName, dataSet, includeData)); default: throw new InvalidOperationException("Unhandled provider: " + provider); } }
public async Task CanLinkOnChild(MigrationProvider provider) { var tableName = "groups1"; var 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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, tableName, collectionName) { LinkedCollections = new List <LinkedCollection> { new LinkedCollection(schemaName, tableName, RelationType.OneToMany, new List <string> { "parent_group_id" }, "NestedGroups") } } } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { var g11 = session.Load <JObject>($"{collectionName}/51"); Assert.Equal(2, g11["NestedGroups"].Count()); Assert.Equal($"{collectionName}/52", g11["NestedGroups"][0]); Assert.Equal($"{collectionName}/54", g11["NestedGroups"][1]); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(7, collectionStatistics.CountOfDocuments); } } }
protected virtual void Run(CommandContext context) { Assert.ArgumentNotNull(context, "context"); Assert.ArgumentNotNull(context.Items, "context.Items"); Assert.ArgumentNotNull(context.Parameters, "context.Parameters"); Item item = context.Items[0]; bool deep = MainUtil.GetBool(context.Parameters["deep"], false); MigrationProvider provider = MigrationManager.Providers[context.Parameters["provider"]]; if (provider != null) { provider.MigrateContent(item, deep); } }
public async Task CanMigrateSkipOnChild(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var collection = new RootCollection(schemaName, "order_item", "OrderItems"); var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationSettings { Collections = new List <RootCollection> { collection } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context, token : cts.Token); } using (var session = store.OpenSession()) { var orderItem = session.Load <JObject>("OrderItems/10"); Assert.NotNull(orderItem); // price and metadata, Id (OrderItems/1) Assert.Equal(3, orderItem.Properties().Count()); Assert.Equal("OrderItems", orderItem["@metadata"]["@collection"]); Assert.Equal(110, orderItem["Price"]); Assert.Equal("OrderItems/10", orderItem["Id"]); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(2, collectionStatistics.CountOfDocuments); } } }
public async Task CanMigrateSkipOnParent(MigrationProvider provider) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, "basic")) { var driver = DatabaseDriverDispatcher.CreateDriver(provider, connectionString); using (var store = GetDocumentStore()) { var collection = new RootCollection(schemaName, "order", "Orders"); var db = await GetDocumentDatabaseInstanceFor(store); var settings = new MigrationSettings { Collections = new List <RootCollection> { collection } }; using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context); } using (var session = store.OpenSession()) { var order = session.Load <JObject>("Orders/1"); Assert.NotNull(order); // total and metadata, Id (Orders/1) Assert.Equal(3, order.Properties().Count()); Assert.Equal("Orders", order["@metadata"]["@collection"]); Assert.Equal(440, order["Total"]); Assert.Equal("Orders/1", order["Id"]); } var collectionStatistics = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(1, collectionStatistics.CountOfDocuments); } } }
private static MigrationProvider <string, BasicEntry> CreateMigrationProvider() { var dynamics = new MyDynamicStorageSelector <string, BasicEntry>( new[] { new StorageSelection <string, BasicEntry, IDynamicStorage <string, BasicEntry> >(null, new DateTime(2017, 1, 1), new DateTime(2020, 1, 1)), new StorageSelection <string, BasicEntry, IDynamicStorage <string, BasicEntry> >(null, new DateTime(2011, 1, 1), new DateTime(2014, 1, 1)), }); var volumes = new MyVolumeStorageSelector <string, BasicEntry>( new[] { new StorageSelection <string, BasicEntry, IVolumeStorage <string, BasicEntry> >(null, new DateTime(2010, 1, 1), new DateTime(2021, 1, 1)), }); var provider = new MigrationProvider <string, BasicEntry>(dynamics, volumes); return(provider); }
public async Task CanImportWithRelationToNonPrimaryKey(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, "orders2", "Orders2") } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); var customersSchema = schema.GetTable(schemaName, "customers2"); // vat id -> should not be reference! Assert.Equal(0, customersSchema.References.Count); Assert.True(customersSchema.Columns.Any(x => x.Name == "vatid")); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context, token : cts.Token); } using (var session = store.OpenSession()) { JObject[] objects = session.Advanced.LoadStartingWith <JObject>("Orders2/"); foreach (var jObject in objects) { Assert.True(jObject.GetValue("Customer_vatid").Value <int>() == 55555 || jObject.GetValue("Customer_vatid").Value <int>() == 44444); } } } } }
public async Task SupportsDocumentSkip(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, "order_item", "OrderItems") { Patch = "if (this.Price < 200) throw 'skip';" } } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); var result = new MigrationResult(settings); await driver.Migrate(settings, schema, db, context, result, token : cts.Token); Assert.Equal(2, result.PerCollectionCount["OrderItems"].ReadCount); Assert.Equal(0, result.PerCollectionCount["OrderItems"].ErroredCount); Assert.Equal(1, result.PerCollectionCount["OrderItems"].SkippedCount); } using (var session = store.OpenSession()) { Assert.Equal(1, session.Advanced.LoadStartingWith <JObject>("OrderItems/").Length); } } } }
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); } } } }
public async Task SimplePatch(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 MigrationSettings { Collections = new List <RootCollection> { new RootCollection(schemaName, "order", "Orders") { Patch = "this.NewField = 5;" } } }; using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1))) using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var schema = driver.FindSchema(); ApplyDefaultColumnNamesMapping(schema, settings); await driver.Migrate(settings, schema, db, context, token : cts.Token); } using (var session = store.OpenSession()) { var order = session.Load <JObject>("Orders/1"); Assert.NotNull(order); Assert.Equal(5, order["NewField"]); } } } }
private static void Main(string[] args) { Console.WriteLine("Initializing..."); #region Startup // Create service collection var serviceCollection = new ServiceCollection(); _configureServices = Startup.ConfigureServices(serviceCollection); // Create service provider IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); #endregion #region initiatlize _sourceOptionsBuilder = new DbContextOptionsBuilder <TilesCornerDbContext>(); _sourceOptionsBuilder.UseSqlServer(_configureServices.GetConnectionString("SourceConnection")); Console.WriteLine( $"Connected source database....{_configureServices.GetConnectionString("SourceConnection")}"); _destinationOptionsBuilder = new DbContextOptionsBuilder <TilesPadDbContext>(); _destinationOptionsBuilder.UseSqlServer(_configureServices.GetConnectionString("DestinationConnection")); Console.WriteLine( $"Connected target database....{_configureServices.GetConnectionString("DestinationConnection")}"); Migrator.Initialize(new TilesCornerDbContext(_sourceOptionsBuilder.Options), new TilesPadDbContext(_destinationOptionsBuilder.Options)); StartInit: Console.WriteLine("Enter you tenancy name to start the operation"); var tenancyName = Console.ReadLine(); var tenantId = MigrationProvider.GetTenantId(tenancyName, _destinationOptionsBuilder); if (string.IsNullOrWhiteSpace(tenantId)) { goto StartInit; } var companyId = MigrationProvider.GetCompanyId(tenantId, _destinationOptionsBuilder); Migrator.Setup(tenantId, companyId); Console.WriteLine($"{tenancyName} is found on SaaS database. What do you want to do now?"); Console.WriteLine("1. Migrate \n2. Clean\n3. Exit"); var action = Console.ReadLine(); #endregion if (action == "1" || action?.ToLower() == "migrate") { Console.WriteLine("Please enter the source database name..."); while (true) { var sourceDatabaseName = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(sourceDatabaseName)) { var connectionString = _configureServices.GetConnectionString("SourceConnection"); var strings = connectionString.Split(";"); var database = strings.FirstOrDefault(x => x.StartsWith("Database")); var databaseIndex = strings.IndexOf(database); var split = database.Split("="); split[1] = sourceDatabaseName; strings[databaseIndex] = $"{split[0]}={split[1]}"; connectionString = string.Join(";", strings); _sourceOptionsBuilder.UseSqlServer(connectionString); Console.WriteLine($"Connecting to source database....{connectionString}"); Migrator.Initialize(new TilesCornerDbContext(_sourceOptionsBuilder.Options), new TilesPadDbContext(_destinationOptionsBuilder.Options)); if (Migrator.IsDatabaseExist(Migrator.SourceContext)) { Console.WriteLine("Database found....connection success...."); break; } } Console.WriteLine( "Could not find the database with given key, please enter another name to continue....."); } StartMigration: Console.WriteLine( $"All are set now, are you sure you want to start migration of {tenancyName} now???....."); Console.WriteLine("\n1. Yes \t2. No \t0. Exit"); var confirm = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(confirm)) { if (confirm.ToLower() == "yes" || confirm == "1") { DoMigration(tenantId, companyId); } else if (confirm.ToLower() == "no" || confirm == "2") { } else if (confirm.ToLower() == "exit" || confirm == "0") { action = "3"; } else { Console.WriteLine("Wrong input...."); goto StartMigration; } } else { Console.WriteLine("Wrong input...."); goto StartMigration; } } if (action == "2" || action?.ToLower() == "clean") { StartDeletion: Console.WriteLine($"Are you sure you want to delete all data from {tenancyName}???....."); Console.WriteLine("\n1. Yes \t2. No \t0. Exit"); var confirm = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(confirm)) { if (confirm.ToLower() == "yes" || confirm == "1") { DoClean(tenantId, companyId); } else if (confirm.ToLower() == "no" || confirm == "2") { action = "3"; } else if (confirm.ToLower() == "exit" || confirm == "0") { action = "3"; } else { Console.WriteLine("Wrong input...."); goto StartDeletion; } } else { Console.WriteLine("Wrong input...."); goto StartDeletion; } } if (action == "3" || action?.ToLower() == "exit") { Console.WriteLine($"Operation exit for {tenancyName}"); } Console.WriteLine($"Operation finished for {tenancyName}"); OperationReInit: Console.WriteLine($"\nDo you wish to continue with another tenant?\n\n1. Yes \t0. Exit"); action = Console.ReadLine(); if (action == "1" || action?.ToLower() == "yes") { goto StartInit; } if (action == "0" || action?.ToLower() == "exit") { Console.WriteLine("Operation exit...."); } else { Console.WriteLine("Wrong input...."); goto OperationReInit; } }
public Startup(IConfiguration configuration, IWebHostEnvironment environment) { Configuration = configuration; Environment = environment; MigrationProvider.Register(Configuration.GetSection("ConnectionStrings:DbContext").Value); }
public Startup(IConfiguration configuration) { Configuration = configuration; MigrationProvider.Register(Configuration.GetSection("ConnectionStrings:DbContext").Value); }
public Migrator(string migrationsAssemblyName, string connectionString) { dbQuery = new DbQuery(connectionString); migrationProvider = new MigrationProvider(migrationsAssemblyName); gatewayFinder = new GatewayFinder(dbQuery); }