public void Can_get_and_set_table_and_column()
        {
            var dropColumnOperation = new DropColumnOperation("T", "c");

            Assert.Equal("T", dropColumnOperation.Table);
            Assert.Equal("c", dropColumnOperation.Name);
        }
        public void Can_get_and_set_table_and_column()
        {
            var dropColumnOperation = new DropColumnOperation("T", "c");

            Assert.Equal("T", dropColumnOperation.Table);
            Assert.Equal("c", dropColumnOperation.Name);
            Assert.Empty(dropColumnOperation.RemovedAnnotations);
            Assert.Null(dropColumnOperation.Inverse);

            dropColumnOperation = new DropColumnOperation("T", "c", (IDictionary<string, object>)null);

            Assert.Equal("T", dropColumnOperation.Table);
            Assert.Equal("c", dropColumnOperation.Name);
            Assert.Empty(dropColumnOperation.RemovedAnnotations);
            Assert.Null(dropColumnOperation.Inverse);

            dropColumnOperation = new DropColumnOperation("T", "c", (AddColumnOperation)null);

            Assert.Equal("T", dropColumnOperation.Table);
            Assert.Equal("c", dropColumnOperation.Name);
            Assert.Empty(dropColumnOperation.RemovedAnnotations);
            Assert.Null(dropColumnOperation.Inverse);

            dropColumnOperation = new DropColumnOperation("T", "c", null, null);

            Assert.Equal("T", dropColumnOperation.Table);
            Assert.Equal("c", dropColumnOperation.Name);
            Assert.Empty(dropColumnOperation.RemovedAnnotations);
            Assert.Null(dropColumnOperation.Inverse);
        }
        public void Inverse_should_produce_drop_column_operation()
        {
            var inverse = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
            var dropColumnOperation = new DropColumnOperation("T", "c", inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);
        }
        public void Inverse_should_return_given_AddColumnOperation()
        {
            var inverse = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
            var dropColumnOperation = new DropColumnOperation("T", "c", inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);

            dropColumnOperation = new DropColumnOperation("T", "c", null, inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);
        }
        public void Inverse_should_return_given_AddColumnOperation()
        {
            var inverse             = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
            var dropColumnOperation = new DropColumnOperation("T", "c", inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);

            dropColumnOperation = new DropColumnOperation("T", "c", null, inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);
        }
        /// <inheritdoc />
        protected override void Generate(DropColumnOperation dropColumnOperation)
        {
            using (var writer = Writer())
            {
                writer.Write("ALTER TABLE ");
                writer.Write(Name(dropColumnOperation.Table));
                writer.Write(" DROP COLUMN ");
                writer.Write(Quote(dropColumnOperation.Name));

                Statement(writer);
            }
        }
        public void Can_get_set_set_annotations()
        {
            Assert.Empty(new CreateTableOperation("Foo").Annotations);
            Assert.Empty(new CreateTableOperation("Foo", null).Annotations);

            var operation = new DropColumnOperation("T", "c", new Dictionary<string, object> { { "A1", "V1" } });

            Assert.Equal("V1", operation.RemovedAnnotations["A1"]);

            operation = new DropColumnOperation("T", "c", new Dictionary<string, object> { { "A1", "V1" } }, null);

            Assert.Equal("V1", operation.RemovedAnnotations["A1"]);
        }
        public void Can_get_set_set_annotations()
        {
            Assert.Empty(new CreateTableOperation("Foo").Annotations);
            Assert.Empty(new CreateTableOperation("Foo", null).Annotations);

            var operation = new DropColumnOperation("T", "c", new Dictionary <string, object> {
                { "A1", "V1" }
            });

            Assert.Equal("V1", operation.RemovedAnnotations["A1"]);

            operation = new DropColumnOperation("T", "c", new Dictionary <string, object> {
                { "A1", "V1" }
            }, null);

            Assert.Equal("V1", operation.RemovedAnnotations["A1"]);
        }
        public void Generate_can_output_drop_column()
        {
            var codeGenerator = new VisualBasicMigrationCodeGenerator();

            var dropColumnOperation = new DropColumnOperation("Customers", "Foo");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { dropColumnOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"Imports System
Imports System.Data.Entity.Migrations

Namespace Foo
    Public Partial Class Bar
        Inherits DbMigration
    
        Public Overrides Sub Up()
            DropColumn(""Customers"", ""Foo"")
        End Sub
        
        Public Overrides Sub Down()
        End Sub
    End Class
End Namespace
",
                generatedMigration.UserCode);
        }
 protected override void Generate(DropColumnOperation dropColumnOperation, IndentedTextWriter writer)
 {
     var drop = new DropColumnOperation(TrimSchemaPrefix(dropColumnOperation.Table), dropColumnOperation.Name);
       base.Generate(drop, writer);
 }
        protected virtual MigrationStatement Generate(DropColumnOperation op)
        {
            if (op == null) return null;

              MigrationStatement stmt = new MigrationStatement();
              StringBuilder sb = new StringBuilder();
              stmt.Sql = string.Format("alter table `{0}` drop column `{1}`",
            op.Table, op.Name);
              return stmt;
        }
        /// <summary>
        /// Generates SQL for a <see cref="DropColumnOperation" />.
        /// Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="dropColumnOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(DropColumnOperation dropColumnOperation)
        {
            Check.NotNull(dropColumnOperation, "dropColumnOperation");

            using (var writer = Writer())
            {
                DropDefaultConstraint(dropColumnOperation.Table, dropColumnOperation.Name, writer);

                writer.Write("ALTER TABLE ");
                writer.Write(Name(dropColumnOperation.Table));
                writer.Write(" DROP COLUMN ");
                writer.Write(Quote(dropColumnOperation.Name));

                Statement(writer);
            }
        }
        /// <summary>
        /// Generates code to perform a <see cref="DropColumnOperation" />.
        /// </summary>
        /// <param name="dropColumnOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(DropColumnOperation dropColumnOperation, IndentedTextWriter writer)
        {
            Check.NotNull(dropColumnOperation, "dropColumnOperation");
            Check.NotNull(writer, "writer");

            writer.Write("DropColumn(");
            writer.Write(Quote(dropColumnOperation.Table));
            writer.Write(", ");
            writer.Write(Quote(dropColumnOperation.Name));

            if (dropColumnOperation.RemovedAnnotations.Any())
            {
                writer.Indent++;

                writer.WriteLine(",");
                writer.Write("removedAnnotations := ");
                GenerateAnnotations(dropColumnOperation.RemovedAnnotations, writer);

                writer.Indent--;
            }

            writer.WriteLine(")");
        }
        /// <summary>
        ///     Generates code to perform a <see cref="DropColumnOperation" />.
        /// </summary>
        /// <param name="dropColumnOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(DropColumnOperation dropColumnOperation, IndentedTextWriter writer)
        {
            Check.NotNull(dropColumnOperation, "dropColumnOperation");
            Check.NotNull(writer, "writer");

            writer.Write("DropColumn(");
            writer.Write(Quote(dropColumnOperation.Table));
            writer.Write(", ");
            writer.Write(Quote(dropColumnOperation.Name));
            writer.WriteLine(")");
        }
 private void Convert(DropColumnOperation dropColumnOperation)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("ALTER TABLE ");
     AppendTableName(dropColumnOperation.Table, sql);
     sql.Append(" DROP COLUMN \"");
     sql.Append(dropColumnOperation.Name);
     sql.Append('"');
     AddStatment(sql);
 }
        /// <summary>
        ///     Generates code to perform a <see cref = "DropColumnOperation" />.
        /// </summary>
        /// <param name = "dropColumnOperation">The operation to generate code for.</param>
        /// <param name = "writer">Text writer to add the generated code to.</param>
        protected virtual void Generate(DropColumnOperation dropColumnOperation, IndentedTextWriter writer)
        {
            Contract.Requires(dropColumnOperation != null);
            Contract.Requires(writer != null);

            writer.Write("DropColumn(");
            writer.Write(Quote(dropColumnOperation.Table));
            writer.Write(", ");
            writer.Write(Quote(dropColumnOperation.Name));
            writer.WriteLine(")");
        }
        public void Generate_can_output_drop_column()
        {
            var migrationProvider = new SqlServerMigrationSqlGenerator();

            var dropColumnOperation = new DropColumnOperation("Customers", "Foo");

            var sql = migrationProvider.Generate(new[] { dropColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);

            Assert.True(sql.Contains("ALTER TABLE [Customers] DROP COLUMN [Foo]"));
        }
        /// <summary>
        ///     Generates SQL for a <see cref = "DropColumnOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name = "dropColumnOperation">The operation to produce SQL for.</param>
        protected virtual void Generate(DropColumnOperation dropColumnOperation)
        {
            Contract.Requires(dropColumnOperation != null);

            using (var writer = Writer())
            {
                var variable = "@var" + _variableCounter++;

                writer.Write("DECLARE ");
                writer.Write(variable);
                writer.WriteLine(" nvarchar(128)");
                writer.Write("SELECT ");
                writer.Write(variable);
                writer.WriteLine(" = name");
                writer.WriteLine("FROM sys.default_constraints");
                writer.Write("WHERE parent_object_id = object_id(N'");
                writer.Write(dropColumnOperation.Table);
                writer.WriteLine("')");
                writer.Write("AND col_name(parent_object_id, parent_column_id) = '");
                writer.Write(dropColumnOperation.Name);
                writer.WriteLine("';");
                writer.Write("IF ");
                writer.Write(variable);
                writer.WriteLine(" IS NOT NULL");
                writer.Indent++;
                writer.Write("EXECUTE('ALTER TABLE ");
                writer.Write(Name(dropColumnOperation.Table));
                writer.Write(" DROP CONSTRAINT ' + ");
                writer.Write(variable);
                writer.WriteLine(")");
                writer.Indent--;

                writer.Write("ALTER TABLE ");
                writer.Write(Name(dropColumnOperation.Table));
                writer.Write(" DROP COLUMN ");
                writer.Write(Quote(dropColumnOperation.Name));

                Statement(writer);
            }
        }
Beispiel #19
0
        public void Generate_can_output_drop_column()
        {
            var migrationSqlGenerator = new SqlCeMigrationSqlGenerator();

            var dropColumnOperation = new DropColumnOperation("Customers", "Foo");

            var sql = migrationSqlGenerator.Generate(new[] { dropColumnOperation }, "4.0").Join(s => s.Sql, Environment.NewLine);

            Assert.Contains("ALTER TABLE [Customers] DROP COLUMN [Foo]", sql);
        }
        /// <summary>
        /// Gera SQL para uma operação <see cref="DropColumnOperation" />.
        /// </summary>
        /// <param name="opeRemoveColuna"> The operation to produce SQL for. </param>
        protected virtual void Generate(DropColumnOperation opeRemoveColuna)
        {
            using (var ltextWriter = TextWriter())
            {
                ltextWriter.Write("ALTER TABLE ");
                ltextWriter.Write(RemoveDBO(opeRemoveColuna.Table));
                ltextWriter.Write(" DROP COLUMN ");
                ltextWriter.Write(opeRemoveColuna.Name);

                ComandoSQL(ltextWriter);
            }
        }
        public void Generate_can_output_drop_column()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var dropColumnOperation = new DropColumnOperation("Customers", "Foo");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { dropColumnOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            DropColumn(""Customers"", ""Foo"");
        }
        
        public override void Down()
        {
        }
    }
}
",
                generatedMigration.UserCode);
        }
        protected override void Generate(DropColumnOperation dropColumnOperation)
        {
            Contract.Requires(dropColumnOperation != null);

            using (var writer = Writer())
            {
                writer.Write("ALTER TABLE ");
                writer.Write(Name(dropColumnOperation.Table));
                writer.Write(" DROP COLUMN ");
                writer.Write(Name(dropColumnOperation.Name));

                Statement(writer);
            }
        }
 protected virtual IEnumerable<MigrationStatement> Generate(DropColumnOperation operation)
 {
     using (var writer = SqlWriter())
     {
         writer.Write("ALTER TABLE ");
         writer.Write(Quote(operation.Table));
         writer.Write(" DROP COLUMN ");
         writer.Write(Quote(operation.Name));
         yield return Statement(writer);
     }
 }
        public void GenerateCanOutputDropColumn()
        {
            var migrationSqlGenerator = new PostgreSqlMigrationSqlGenerator();

            var dropColumnOperation = new DropColumnOperation("Customers", "Foo");

            var sql = migrationSqlGenerator.Generate(new[] { dropColumnOperation }, "9.2").Join(s => s.Sql, Environment.NewLine);

            Assert.True(sql.Contains("ALTER TABLE \"Customers\" DROP COLUMN \"Foo\""));
        }