public void Visit_with_drop_table_operation() { var model = new DatabaseModel(); var operation = new DropTableOperation("dbo.MyTable"); model.AddTable(new Table("dbo.MyTable")); Assert.Equal(1, model.Tables.Count); operation.Accept(new DatabaseModelModifier(), model); Assert.Equal(0, model.Tables.Count); }
protected virtual IEnumerable <MigrationOperation> Remove(IEntityType source, ModelDifferContext diffContext) { var sourceExtensions = MetadataExtensions.Extensions(source); var operation = new DropTableOperation { Schema = sourceExtensions.Schema, Name = sourceExtensions.Table }; diffContext.AddDrop(source, operation); yield return(operation); }
protected virtual IEnumerable <MigrationOperation> Remove(IEntityType source, DiffContext diffContext) { var sourceAnnotations = Annotations.For(source); var operation = new DropTableOperation { Schema = sourceAnnotations.Schema, Name = sourceAnnotations.TableName }; diffContext.AddDrop(source, operation); yield return(operation); }
protected virtual void Generate( [NotNull] DropTableOperation operation, [CanBeNull] IModel model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("DROP TABLE ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)); EndStatement(builder); }
public virtual OperationBuilder <DropTableOperation> DropTable(string name, string schema = null) { Check.NotEmpty(name, nameof(name)); var operation = new DropTableOperation { Schema = schema, Name = name }; Operations.Add(operation); return(new OperationBuilder <DropTableOperation>(operation)); }
protected override void Generate(DropTableOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) { string tableName = operation.Name; string schema = operation.Schema ?? "dbo"; bool isEntityTemporalInDatabase = tableHelper.IsTableTemporal(tableName, schema); if (isEntityTemporalInDatabase) { ITemporalTableSqlGenerator temporalTableSqlGenerator = new DropTemporalTableGenerator(tableName, schema); string temporalTableSql = temporalTableSqlGenerator.Generate(); builder.AppendLine(temporalTableSql); } base.Generate(operation, model, builder, terminate); }
public void Process_with_drop_table_operation_drops_foreign_keys_referencing_the_table() { var sourceModel = new Model(); var sourceModelBuilder = new BasicModelBuilder(sourceModel); sourceModelBuilder.Entity("A", b => { b.Property <int>("Id"); b.Key("Id"); }); sourceModelBuilder.Entity("B", b => { b.Property <int>("Id"); b.Key("Id"); }); sourceModelBuilder.Entity("C", b => { b.Property <int>("Id"); b.Property <int>("P1"); b.Property <int>("P2"); b.Key("Id"); b.ForeignKey("A", "P1").ForRelational().Name("FKA"); b.ForeignKey("B", "P2").ForRelational().Name("FKB"); }); var inOperations = new MigrationOperationCollection(); var dropTableOperation = new DropTableOperation("A"); inOperations.Add(dropTableOperation); var operations = Process(inOperations, sourceModel); Assert.Equal(2, operations.Count); Assert.IsType <DropForeignKeyOperation>(operations[0]); Assert.Same(dropTableOperation, operations[1]); var dropForeignKeyOperation = (DropForeignKeyOperation)operations[0]; Assert.Equal("C", dropForeignKeyOperation.TableName); Assert.Equal("FKA", dropForeignKeyOperation.ForeignKeyName); Assert.Same(dropTableOperation, operations[1]); }
public override void Generate(DropTableOperation dropTableOperation, IndentedStringBuilder stringBuilder, bool generateIdempotentSql) { Check.NotNull(dropTableOperation, "dropTableOperation"); Check.NotNull(stringBuilder, "stringBuilder"); if (generateIdempotentSql) { GenerateTablePresenceCheck(dropTableOperation.TableName, negative: false, builder: stringBuilder); using (stringBuilder.AppendLine().Indent()) { base.Generate(dropTableOperation, stringBuilder, generateIdempotentSql: false); } } else { base.Generate(dropTableOperation, stringBuilder, generateIdempotentSql); } }
public void Visit_with_drop_table_operation_drops_foreign_keys_referencing_the_table() { var modelBuilder = new BasicModelBuilder(); modelBuilder.Entity("A", b => { b.Property <int>("Id"); b.Key("Id"); }); modelBuilder.Entity("B", b => { b.Property <int>("Id"); b.Key("Id"); }); modelBuilder.Entity("C", b => { b.Property <int>("Id"); b.Property <int>("P1"); b.Property <int>("P2"); b.Key("Id"); b.ForeignKey("A", "P1").ForRelational().Name("FKA"); b.ForeignKey("B", "P2").ForRelational().Name("FKB"); }); var dropTableOperation = new DropTableOperation("A"); var operations = PreProcess(modelBuilder, dropTableOperation); Assert.Equal(2, operations.Count); Assert.IsType <DropForeignKeyOperation>(operations[0]); Assert.IsType <DropTableOperation>(operations[1]); var dropForeignKeyOperation = (DropForeignKeyOperation)operations[0]; Assert.Equal("C", dropForeignKeyOperation.TableName); Assert.Equal("FKA", dropForeignKeyOperation.ForeignKeyName); Assert.Same(dropTableOperation, operations[1]); }
public override void Visit(DropTableOperation dropTableOperation, Context context) { Check.NotNull(dropTableOperation, "dropTableOperation"); Check.NotNull(context, "context"); var compositeOperation = new CompositeOperation(); var database = context.Generator.Database; var table = database.GetTable(dropTableOperation.TableName); compositeOperation.AddOperations( database.Tables .SelectMany(t => t.ForeignKeys) .Where(fk => ReferenceEquals(fk.ReferencedTable, table)) .Select(fk => new DropForeignKeyOperation(fk.Table.Name, fk.Name))); compositeOperation.AddOperation(dropTableOperation); context.HandleCompositeOperation(compositeOperation); }
public void When_Drop_Table_Then_CQL_Is_Returned() { var dropTableOperation = new DropTableOperation { Name = "applicants", Schema = "cv" }; var fakeDbContext = (IInfrastructure <IServiceProvider>) new FakeDbContext((modelBuilder) => { modelBuilder.Entity <Applicant>() .ToTable("applicants") .HasKey(p => p.Id); }); var migrationsSqlGenerator = (IMigrationsSqlGenerator)fakeDbContext.Instance.GetService(typeof(IMigrationsSqlGenerator)); var sql = migrationsSqlGenerator.Generate(new[] { dropTableOperation }); Assert.Equal("DROP TABLE \"cv\".\"applicants\";\r\n", sql.First().CommandText); }
protected override IEnumerable <MigrationOperation> Remove(TableMapping source, DiffContext diffContext) { var type = source.GetRootType(); MigrationOperation operation; if (!type.IsUserDefinedType()) { var dropOperation = new DropTableOperation { Schema = source.Schema, Name = source.Name }; diffContext.AddDrop(source, dropOperation); operation = dropOperation; } else { operation = new DropUserDefinedTypeOperation { Schema = source.Schema, Name = source.Name }; } operation.AddAnnotations(MigrationsAnnotations.ForRemove(source.EntityTypes[0])); yield return(operation); }
protected override List <MigrationOperation> GetOperations() { List <MigrationOperation> operations = new List <MigrationOperation>(); #region operations if (Indexes != null) { foreach (var index in Indexes) { var _DropIndexOperation = new DropIndexOperation(); _DropIndexOperation.Table = this.Table.Name.ToLower(); _DropIndexOperation.Name = EF_CreateTable_Action.GetIndexName(index.Keys.Split(','), this.Table.id.Value); operations.Add(_DropIndexOperation); } } var _DropTableOperation = new DropTableOperation() { Name = this.Table.Name.ToLower() }; operations.Add(_DropTableOperation); #endregion return(operations); }
protected virtual void Generate( [NotNull] DropTableOperation operation, [CanBeNull] IModel model, [NotNull] MigrationCommandListBuilder builder) => Generate(operation, model, builder, terminate: true);
protected override void Generate(DropTableOperation dropTableOperation, IndentedTextWriter writer) { var drop = new DropTableOperation(TrimSchemaPrefix(dropTableOperation.Name)); base.Generate(drop, writer); }
private void Generate(DropTableOperation dropTableOperation) { throw new NotImplementedException(); }
public virtual void AddDrop([NotNull] IEntityType source, [NotNull] DropTableOperation operation) { _dropTableOperations.Add(source, operation); _removedEntityTypes.Add(operation, source); }
public override void Visit(DropTableOperation operation, IndentedStringBuilder builder) { builder.Append("Drop").Append(operation.TableName).Append("Sql"); }
protected override void Generate(DropTableOperation operation, IModel model, MigrationCommandListBuilder builder) => base.Generate(operation, model, builder);
protected override void Generate(DropTableOperation dropTableOperation, IndentedTextWriter writer) { base.Generate(dropTableOperation, writer); }
protected override void Generate(DropTableOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) => base.Generate(operation, model, builder, terminate);
public virtual void Visit(DropTableOperation dropTableOperation, DatabaseModel databaseModel) { databaseModel.RemoveTable(dropTableOperation.TableName); }