public void RenameWithDifferentPrimaryKeyTypeAndDropRecreateWorks() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf <Post>(); var to = new MutableConfiguration(ConnectionString).AddNamespaceOf <RenamePkTypeChange.Entry>(); var migrator = MakeMigrator(from); IEnumerable <string> warnings; IEnumerable <string> errors; var answerProvider = new Mock <IAnswerProvider>(); answerProvider.Setup(a => a.GetMultipleChoiceAnswer(It.IsAny <string>(), It.IsAny <IEnumerable <MultipleChoice <string> > >())) .Returns(new MultipleChoice <string> { Choice = "Entry", DisplayString = "Entry" }); answerProvider.Setup(a => a.GetBooleanAnswer(It.IsAny <string>())).Returns(false); // change the pk name to.GetMap <RenamePkTypeChange.Entry>().PrimaryKey.Name = "EntryId"; to.GetMap <RenamePkTypeChange.Entry>().PrimaryKey.DbName = "EntryId"; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock <ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal( Regex.Replace( Regex.Replace(@"EXEC sp_RENAME [Posts], [Entries]; declare @OBDCommande51728c6d92c4851aa3b01e8a5a12adb nvarchar(1000); select @OBDCommande51728c6d92c4851aa3b01e8a5a12adb = 'ALTER TABLE [Posts] drop constraint ' + d.name from sys.tables t join sys.default_constraints d on d.parent_object_id = t.object_id join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id where t.name = 'Posts' and c.name = 'Id'; execute(@OBDCommande51728c6d92c4851aa3b01e8a5a12adb); alter table [Posts] drop column [Id]; alter table [Entries] add [EntryId] uniqueidentifier not null DEFAULT NEWSEQUENTIALID() primary key; alter table [PostComments] drop constraint [fk_PostComment_Post_Post]; declare @OBDCommand934ba0aed0634856ab81048df9205176 nvarchar(1000); select @OBDCommand934ba0aed0634856ab81048df9205176 = 'ALTER TABLE [PostComments] drop constraint ' + d.name from sys.tables t join sys.default_constraints d on d.parent_object_id = t.object_id join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id where t.name = 'PostComments' and c.name = 'PostId'; execute(@OBDCommand934ba0aed0634856ab81048df9205176); alter table [PostComments] drop column [PostId]; alter table [PostComments] add [PostId] uniqueidentifier null; alter table [PostComments] add constraint fk_PostComment_Entry_Post foreign key ([PostId]) references [Entries]([EntryId]);", @"@\w+\b", "@Foo"), @"(?<!\r)\n", Environment.NewLine), Regex.Replace(script.Trim(), @"@\w+\b", "@Foo")); }
public void RenameWithDifferentPrimaryKeyWorks() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf<Post>(); var to = new MutableConfiguration(ConnectionString).AddNamespaceOf<Entry>(); var migrator = MakeMigrator(from); IEnumerable<string> warnings; IEnumerable<string> errors; var answerProvider = new Mock<IAnswerProvider>(); answerProvider.Setup(a => a.GetMultipleChoiceAnswer(It.IsAny<string>(), It.IsAny<IEnumerable<MultipleChoice<string>>>())) .Returns(new MultipleChoice<string> { Choice = "Entry", DisplayString = "Entry" }); // change the pk name to.GetMap<Entry>().PrimaryKey.Name = "EntryId"; to.GetMap<Entry>().PrimaryKey.DbName = "EntryId"; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock<ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal( Regex.Replace( @"EXEC sp_RENAME [Posts], [Entries]; EXEC sp_RENAME 'Entries.Id', 'EntryId', 'COLUMN'; alter table [PostComments] drop constraint [fk_PostComment_Post_Post]; alter table [PostComments] add constraint fk_PostComment_Entry_Post foreign key ([PostId]) references [Entries]([EntryId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); }
public void ForeignKeyIndexesAddedAutomatically() { var config = new MutableConfiguration() .AddNamespaceOf <Post>(); var postMap = config.GetMap <Post>(); var blogMap = config.GetMap <Blog>(); Assert.Equal(2, postMap.ForeignKeys.Count()); Assert.Equal(2, postMap.Indexes.Count()); Assert.Equal("Blog", postMap.Indexes.Last().Columns.First().Name); }
public void ForeignKeyIndexesAddedAutomatically() { var config = new MutableConfiguration( new ConnectionStringSettings("Default", "Data Source=(localdb)\\v11.0;Integrated Security=true", "System.Data.SqlClient")) .AddNamespaceOf<Post>(); var postMap = config.GetMap<Post>(); var blogMap = config.GetMap<Blog>(); Assert.Equal(2, postMap.ForeignKeys.Count()); Assert.Equal(2, postMap.Indexes.Count()); Assert.Equal("Blog", postMap.Indexes.Last().Columns.First().Name); }
public void ForeignKeyIndexesAddedAutomatically() { var config = new MutableConfiguration( new ConnectionStringSettings("Default", "Data Source=(localdb)\\v11.0;Integrated Security=true", "System.Data.SqlClient")) .AddNamespaceOf <Post>(); var postMap = config.GetMap <Post>(); var blogMap = config.GetMap <Blog>(); Assert.Equal(2, postMap.ForeignKeys.Count()); Assert.Equal(2, postMap.Indexes.Count()); Assert.Equal("Blog", postMap.Indexes.Last().Columns.First().Name); }
public void RenameWithDifferentPrimaryKeyTypeAndAttemptChangeWorks() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf <Post>(); var to = new MutableConfiguration(ConnectionString).AddNamespaceOf <RenamePkTypeChange.Entry>(); var migrator = MakeMigrator(from); IEnumerable <string> warnings; IEnumerable <string> errors; var answerProvider = new Mock <IAnswerProvider>(); answerProvider.Setup(a => a.GetMultipleChoiceAnswer(It.IsAny <string>(), It.IsAny <IEnumerable <MultipleChoice <string> > >())) .Returns(new MultipleChoice <string> { Choice = "Entry", DisplayString = "Entry" }); answerProvider.Setup(a => a.GetBooleanAnswer(It.IsAny <string>())).Returns(true); // change the pk name to.GetMap <RenamePkTypeChange.Entry>().PrimaryKey.Name = "EntryId"; to.GetMap <RenamePkTypeChange.Entry>().PrimaryKey.DbName = "EntryId"; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock <ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal( Regex.Replace( @"EXEC sp_RENAME [Posts], [Entries]; EXEC sp_RENAME 'Entries.Id', 'EntryId', 'COLUMN'; alter table [Entries] alter column [EntryId] uniqueidentifier not null DEFAULT NEWSEQUENTIALID() primary key; alter table [PostComments] drop constraint [fk_PostComment_Post_Post]; alter table [PostComments] alter column [PostId] uniqueidentifier null; alter table [PostComments] add constraint fk_PostComment_Entry_Post foreign key ([PostId]) references [Entries]([EntryId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); Assert.NotEmpty(warnings); Assert.Equal("Changing DB Type is not guaranteed to work: Post on PostComment", warnings.First()); }
public void ExistingIndexNotRecreated() { var config = new MutableConfiguration( new ConnectionStringSettings("Default", "Data Source=(localdb)\\v11.0;Integrated Security=true", "System.Data.SqlClient")) .AddNamespaceOf<Post>(); var postMap = config.GetMap<Post>(); postMap.Index(p => new { p.Blog }); Assert.Equal(2, postMap.ForeignKeys.Count()); Assert.Equal(2, postMap.Indexes.Count()); Assert.Equal("Blog", postMap.Indexes.First().Columns.First().Name); }
public void ExistingIndexNotRecreated() { var config = new MutableConfiguration() .AddNamespaceOf <Post>(); var postMap = config.GetMap <Post>(); postMap.Index(p => new { p.Blog }); Assert.Equal(2, postMap.ForeignKeys.Count()); Assert.Equal(2, postMap.Indexes.Count()); Assert.Equal("Blog", postMap.Indexes.First().Columns.First().Name); }
public void RenameWithDifferentPrimaryKeyWorks() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf <Post>(); var to = new MutableConfiguration(ConnectionString).AddNamespaceOf <Entry>(); var migrator = MakeMigrator(from); IEnumerable <string> warnings; IEnumerable <string> errors; var answerProvider = new Mock <IAnswerProvider>(); answerProvider.Setup(a => a.GetMultipleChoiceAnswer(It.IsAny <string>(), It.IsAny <IEnumerable <MultipleChoice <string> > >())) .Returns(new MultipleChoice <string> { Choice = "Entry", DisplayString = "Entry" }); // change the pk name to.GetMap <Entry>().PrimaryKey.Name = "EntryId"; to.GetMap <Entry>().PrimaryKey.DbName = "EntryId"; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock <ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal( Regex.Replace( @"EXEC sp_RENAME [Posts], [Entries]; EXEC sp_RENAME 'Entries.Id', 'EntryId', 'COLUMN'; alter table [PostComments] drop constraint [fk_PostComment_Post_Post]; alter table [PostComments] add constraint fk_PostComment_Entry_Post foreign key ([PostId]) references [Entries]([EntryId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); }
public void ExistingIndexNotRecreated() { var config = new MutableConfiguration( new ConnectionStringSettings("Default", "Data Source=(localdb)\\v11.0;Integrated Security=true", "System.Data.SqlClient")) .AddNamespaceOf <Post>(); var postMap = config.GetMap <Post>(); postMap.Index(p => new { p.Blog }); Assert.Equal(2, postMap.ForeignKeys.Count()); Assert.Equal(2, postMap.Indexes.Count()); Assert.Equal("Blog", postMap.Indexes.First().Columns.First().Name); }
public void RenameWithDifferentPrimaryKeyTypeAndAttemptChangeWorks() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf<Post>(); var to = new MutableConfiguration(ConnectionString).AddNamespaceOf<RenamePkTypeChange.Entry>(); var migrator = MakeMigrator(from); IEnumerable<string> warnings; IEnumerable<string> errors; var answerProvider = new Mock<IAnswerProvider>(); answerProvider.Setup(a => a.GetMultipleChoiceAnswer(It.IsAny<string>(), It.IsAny<IEnumerable<MultipleChoice<string>>>())) .Returns(new MultipleChoice<string> { Choice = "Entry", DisplayString = "Entry" }); answerProvider.Setup(a => a.GetBooleanAnswer(It.IsAny<string>())).Returns(true); // change the pk name to.GetMap<RenamePkTypeChange.Entry>().PrimaryKey.Name = "EntryId"; to.GetMap<RenamePkTypeChange.Entry>().PrimaryKey.DbName = "EntryId"; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock<ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal( Regex.Replace( @"EXEC sp_RENAME [Posts], [Entries]; EXEC sp_RENAME 'Entries.Id', 'EntryId', 'COLUMN'; alter table [Entries] alter column [EntryId] uniqueidentifier not null NEWSEQUENTIALID() primary key; alter table [PostComments] drop constraint [fk_PostComment_Post_Post]; alter table [PostComments] alter column [PostId] uniqueidentifier null; alter table [PostComments] add constraint fk_PostComment_Entry_Post foreign key ([PostId]) references [Entries]([EntryId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); Assert.NotEmpty(warnings); Assert.Equal("Changing DB Type is not guaranteed to work: Post on PostComment", warnings.First()); }
public void RenameWithDifferentPrimaryKeyTypeAndDropRecreateWorks() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf<Post>(); var to = new MutableConfiguration(ConnectionString).AddNamespaceOf<RenamePkTypeChange.Entry>(); var migrator = MakeMigrator(from); IEnumerable<string> warnings; IEnumerable<string> errors; var answerProvider = new Mock<IAnswerProvider>(); answerProvider.Setup(a => a.GetMultipleChoiceAnswer(It.IsAny<string>(), It.IsAny<IEnumerable<MultipleChoice<string>>>())) .Returns(new MultipleChoice<string> { Choice = "Entry", DisplayString = "Entry" }); answerProvider.Setup(a => a.GetBooleanAnswer(It.IsAny<string>())).Returns(false); // change the pk name to.GetMap<RenamePkTypeChange.Entry>().PrimaryKey.Name = "EntryId"; to.GetMap<RenamePkTypeChange.Entry>().PrimaryKey.DbName = "EntryId"; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock<ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal( Regex.Replace( Regex.Replace(@"EXEC sp_RENAME [Posts], [Entries]; declare @OBDCommande51728c6d92c4851aa3b01e8a5a12adb nvarchar(1000); select @OBDCommande51728c6d92c4851aa3b01e8a5a12adb = 'ALTER TABLE [Posts] drop constraint ' + d.name from sys.tables t join sys.default_constraints d on d.parent_object_id = t.object_id join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id where t.name = 'Posts' and c.name = 'Id'; execute(@OBDCommande51728c6d92c4851aa3b01e8a5a12adb); alter table [Posts] drop column [Id]; alter table [Entries] add [EntryId] uniqueidentifier not null NEWSEQUENTIALID() primary key; alter table [PostComments] drop constraint [fk_PostComment_Post_Post]; declare @OBDCommand934ba0aed0634856ab81048df9205176 nvarchar(1000); select @OBDCommand934ba0aed0634856ab81048df9205176 = 'ALTER TABLE [PostComments] drop constraint ' + d.name from sys.tables t join sys.default_constraints d on d.parent_object_id = t.object_id join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id where t.name = 'PostComments' and c.name = 'PostId'; execute(@OBDCommand934ba0aed0634856ab81048df9205176); alter table [PostComments] drop column [PostId]; alter table [PostComments] add [PostId] uniqueidentifier null; alter table [PostComments] add constraint fk_PostComment_Entry_Post foreign key ([PostId]) references [Entries]([EntryId]);", @"@\w+\b", "@Foo"), @"(?<!\r)\n", Environment.NewLine), Regex.Replace(script.Trim(), @"@\w+\b", "@Foo")); }