示例#1
0
        public void CanMigrateWithPatch()
        {
            using (var store = GetDocumentStore())
            {
                Initialize(store);

                const string FirstName = "Name Test";

                var tablesToWrite = new List <SqlMigrationImportOperation.SqlMigrationTable>
                {
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Customer")
                    {
                        Patch = $"this.{nameof(FirstName)} = '{FirstName}'"
                    }
                };

                var operation = new SqlMigrationImportOperation(ConnectionStringName, tablesToWrite, binaryToAttachment: true, trimStrings: true, skipUnsupportedTypes: false, batchSize: 5);

                var result = store.Maintenance.Send(operation);

                Assert.True(result.Success);

                using (var session = store.OpenSession())
                {
                    var customer = session.Load <Customer>("dbo.Customer/3");
                    Assert.Equal(customer.FirstName, FirstName);
                }
            }
        }
示例#2
0
        public void CanMigrateWithQuery()
        {
            using (var store = GetDocumentStore())
            {
                Initialize(store);
                var tablesToWrite = new List <SqlMigrationImportOperation.SqlMigrationTable>
                {
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Customer")
                    {
                        Query = "select * from [dbo].[Customer] where Id = 3"
                    }
                };

                var operation = new SqlMigrationImportOperation(ConnectionStringName, tablesToWrite, binaryToAttachment: true, trimStrings: true, skipUnsupportedTypes: false, batchSize: 5);

                var result = store.Maintenance.Send(operation);

                Assert.True(result.Success);

                using (var session = store.OpenSession())
                {
                    Assert.True(session.Advanced.Exists("dbo.Customer/3"));
                    Assert.False(session.Advanced.Exists("dbo.Customer/1"));
                }
            }
        }
示例#3
0
        public void CanMigrateSqlDatabase()
        {
            using (var store = GetDocumentStore())
            {
                Initialize(store);

                var tablesToWrite = new List <SqlMigrationImportOperation.SqlMigrationTable>
                {
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Customer")
                    {
                        EmbeddedTables = new List <SqlMigrationImportOperation.SqlMigrationTable>
                        {
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Order")
                            {
                                EmbeddedTables = new List <SqlMigrationImportOperation.SqlMigrationTable>
                                {
                                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.OrderItem")
                                    {
                                        EmbeddedTables = new List <SqlMigrationImportOperation.SqlMigrationTable>
                                        {
                                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Details")
                                        }
                                    }
                                }
                            },
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Photo")
                        }
                    }
                };
                var operation = new SqlMigrationImportOperation(ConnectionStringName, tablesToWrite, binaryToAttachment: true, trimStrings: true, skipUnsupportedTypes: false, batchSize: 5);

                var result = store.Maintenance.Send(operation);

                Assert.True(result.Success);

                using (var session = store.OpenSession())
                {
                    var customer = session.Load <Customer>("dbo.Customer/5");

                    Assert.NotNull(customer);

                    var attachmentsCount = session.Advanced.Attachments.GetNames(customer).Length;
                    Assert.Equal(attachmentsCount, 2);

                    Assert.Equal(customer.Photos.Count, 2);
                    Assert.Equal(customer.Orders.Count, 1);

                    var order = customer.Orders[0];
                    Assert.Equal(order.OrderItems.Count, 2);

                    foreach (var orderItem in order.OrderItems)
                    {
                        Assert.Equal(orderItem.Details.Count, 1);
                    }
                }
            }
        }
示例#4
0
        public void ReturnsCorrectErrors()
        {
            using (var store = GetDocumentStore())
            {
                Initialize(store);
                var tablesToWrite = new List <SqlMigrationImportOperation.SqlMigrationTable>
                {
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Order")
                    {
                        EmbeddedTables = new List <SqlMigrationImportOperation.SqlMigrationTable>
                        {
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.OrderItem")
                            {
                                NewName = "Foo"
                            },
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.OrderItem") // duplicate property
                            {
                                NewName = "Foo"
                            },
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.OrderItem")
                            {
                                Query = "Invalid query"
                            },
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.NotExists"),
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Product"), // cannot embed into 'Order'
                            new SqlMigrationImportOperation.SqlMigrationTable("")
                        }
                    },
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Product"),
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Product"), // duplicate table
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Details")
                    {
                        Query = "select * from [dbo].[Details] OrDer bY Id"
                    },
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Photo")
                    {
                        Query = "select Pic from [dbo].[Photo]" // query doesn't contain all primary keys
                    },
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.Customer")
                    {
                        EmbeddedTables = new List <SqlMigrationImportOperation.SqlMigrationTable>
                        {
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Order"),
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Order"), // duplicate embedded table
                            new SqlMigrationImportOperation.SqlMigrationTable("dbo.Photo")
                            {
                                Query = "select Id from [dbo].[Photo]" // query doesn't contain all referential keys
                            }
                        }
                    },
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.NoPkTable"),
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.UnsupportedTable"), // table contains unsupported type column
                    new SqlMigrationImportOperation.SqlMigrationTable("dbo.OrderItem")
                    {
                        Patch = "Invalid patch script"
                    }
                };

                var operation = new SqlMigrationImportOperation(ConnectionStringName, tablesToWrite, binaryToAttachment: true, trimStrings: true, skipUnsupportedTypes: false, batchSize: 5);

                var result = store.Maintenance.Send(operation);

                Assert.False(result.Success);
                Assert.True(result.Errors[0].Message.Contains("Couldn't find table 'dbo.NotExists' in the SQL database (Table name must include schema name)"));
                Assert.True(result.Errors[1].Message.Contains("A table is missing a name"));
                Assert.True(result.Errors[2].Message.Contains("Duplicate parent table 'dbo.Product'"));
                Assert.True(result.Errors[3].Message.Contains("Duplicate name 'Foo'"));
                Assert.True(result.Errors[4].Message.Contains("Duplicate name 'dbo.Order'"));
                Assert.True(result.Errors[6].Message.Contains("Table 'dbo.Product' cannot embed into 'dbo.Order'"));
                Assert.True(result.Errors[7].Message.Contains("Query cannot contain an 'ORDER BY' clause (dbo.Details)"));
                Assert.True(result.Errors[8].Message.Contains("Query for table 'dbo.Photo' must select all primary keys"));
            }
        }