protected override void Generate(CreateTableOperation createTableOperation)
        {
            string schema, objectName;
            this.GetNameParts(createTableOperation.Name, out schema, out objectName);
            using (var writer = Writer())
            {
                writer.WriteLine("IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}')\r\nBEGIN", schema, objectName);
                writer.Indent++;
                writer.Write("CREATE TABLE ");
                writer.Write(this.Name(createTableOperation.Name));
                writer.Write(" ( ");
                int i = 0;
                foreach (var column in createTableOperation.Columns)
                {
                    this.AddColumnDefinition(column, writer);
                    writer.WriteLine("{0}", i != createTableOperation.Columns.Count - 1 ? "," : string.Empty);
                    i++;
                }
                writer.Write(" ) ");
                writer.Indent--;
                writer.Write("\r\nEND");

                this.Statement(writer);
            }
        }
        public DropTableOperation(string name, CreateTableOperation inverse, object anonymousArguments = null)
            : this(name, anonymousArguments)
        {
            //Contract.Requires(inverse != null);

            _inverse = inverse;
        }
        public DropTableOperation(string name, CreateTableOperation inverse, object anonymousArguments = null)
            : this(name, anonymousArguments)
        {
            Check.NotNull(inverse, "inverse");

            _inverse = inverse;
        }
Exemple #4
0
        public void PrimaryKey_should_resolve_names_from_column()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Foo",
                        ApiPropertyInfo = typeof(Columns).GetProperty("Foo")
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Bar",
                        ApiPropertyInfo = typeof(Columns).GetProperty("Bar")
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Baz"
                    });

            var tableBuilder = new TableBuilder<Columns>(createTableOperation, new TestMigration());

            tableBuilder.PrimaryKey(
                c => new
                         {
                             c.Bar,
                             c.Foo
                         }, name: "PK_Custom", clustered: false);
        }
        public void ForeignKey_should_create_and_add_fk_model()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Foo"
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Bar"
                    });

            var migration = new TestMigration();
            var tableBuilder = new TableBuilder<Columns>(createTableOperation, migration);

            tableBuilder.ForeignKey(
                "P", c => new
                              {
                                  c.Foo,
                                  c.Bar
                              }, true, "my_fk");

            Assert.Equal(1, migration.Operations.Count());

            var addForeignKeyOperation = migration.Operations.Cast<AddForeignKeyOperation>().Single();

            Assert.Equal("P", addForeignKeyOperation.PrincipalTable);
            Assert.Equal("Foo", addForeignKeyOperation.DependentColumns.First());
            Assert.Equal("Bar", addForeignKeyOperation.DependentColumns.Last());
            Assert.True(addForeignKeyOperation.CascadeDelete);
            Assert.Equal("my_fk", addForeignKeyOperation.Name);
        }
        public void PrimaryKey_should_set_key_columns_and_name()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Foo"
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Bar"
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Baz"
                    });

            var tableBuilder = new TableBuilder<Columns>(createTableOperation, new TestMigration());

            tableBuilder.PrimaryKey(
                c => new
                         {
                             c.Bar,
                             c.Foo
                         }, name: "PK_Custom");

            Assert.Equal(2, createTableOperation.PrimaryKey.Columns.Count());
            Assert.Equal("Bar", createTableOperation.PrimaryKey.Columns.First());
            Assert.Equal("Foo", createTableOperation.PrimaryKey.Columns.Last());
            Assert.Equal("PK_Custom", createTableOperation.PrimaryKey.Name);
        }
        /// <summary>
        ///     Generates SQL for a <see cref = "CreateTableOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name = "createTableOperation">The operation to produce SQL for.</param>
        protected virtual void Generate(CreateTableOperation createTableOperation)
        {
            Contract.Requires(createTableOperation != null);

            var parts = createTableOperation.Name.Split(new[] { '.' }, 2);

            if (parts.Length > 1)
            {
                var schema = parts[0];

                if (!schema.EqualsIgnoreCase("dbo")
                    && !_generatedSchemas.Contains(schema))
                {
                    GenerateCreateSchema(schema);

                    _generatedSchemas.Add(schema);
                }
            }

            using (var writer = Writer())
            {
                writer.WriteLine("CREATE TABLE " + Name(createTableOperation.Name) + " (");
                writer.Indent++;

                var columnCount = createTableOperation.Columns.Count();

                createTableOperation.Columns.Each(
                    (c, i) =>
                        {
                            Generate(c, writer);

                            if (i < columnCount - 1)
                            {
                                writer.WriteLine(",");
                            }
                        });

                if (createTableOperation.PrimaryKey != null)
                {
                    writer.WriteLine(",");
                    writer.Write("CONSTRAINT ");
                    writer.Write(Quote(createTableOperation.PrimaryKey.Name));
                    writer.Write(" PRIMARY KEY (");
                    writer.Write(createTableOperation.PrimaryKey.Columns.Join(Quote));
                    writer.WriteLine(")");
                }
                else
                {
                    writer.WriteLine();
                }

                writer.Indent--;
                writer.Write(")");

                Statement(writer);
            }

            GenerateMakeSystemTable(createTableOperation);
        }
 protected override void Generate(CreateTableOperation cto)
 {
     if (cto.PrimaryKey != null)
     {
         cto.PrimaryKey.Name = GetPrimaryKeyName(cto.PrimaryKey.Table);
     }
     base.Generate(cto);
 }
        protected override void Generate(CreateTableOperation createTableOperation)
        {
            foreach (var columnModel in createTableOperation.Columns) {
                SetDefaultValue(columnModel);
            }

            base.Generate(createTableOperation);
        }
        public void Inverse_should_produce_drop_table_operation()
        {
            var createTableOperation = new CreateTableOperation("Foo");

            var dropTableOperation = (DropTableOperation)createTableOperation.Inverse;

            Assert.Equal("Foo", dropTableOperation.Name);
        }
        public void Can_set_and_get_primary_key()
        {
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation();
            var table = new CreateTableOperation("T") { PrimaryKey = addPrimaryKeyOperation };

            Assert.Same(addPrimaryKeyOperation, table.PrimaryKey);
            Assert.Equal("T", addPrimaryKeyOperation.Table);
        }
 protected override void Generate(CreateTableOperation createTableOperation, IndentedTextWriter writer)
 {
     var isReadonly = ReadonlyEntities.Contains(createTableOperation.Name);
     if (!isReadonly)
     {
         base.Generate(createTableOperation, writer);
     }
 }
        public void Inverse_should_produce_create_table_operation()
        {
            var inverse = new CreateTableOperation("T");
            var dropTableOperation = new DropTableOperation("T", inverse);

            Assert.Equal("T", dropTableOperation.Name);
            Assert.Same(inverse, dropTableOperation.Inverse);
        }
        /// <summary>
        /// Generates code to perform a <see cref="T:System.Data.Entity.Migrations.Model.CreateTableOperation" />.
        /// </summary>
        /// <param name="createTableOperation">The operation to generate code for.</param>
        /// <param name="writer">Text writer to add the generated code to.</param>
        protected override void Generate(System.Data.Entity.Migrations.Model.CreateTableOperation createTableOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer)
        {
            base.Generate(createTableOperation, writer);

            foreach (var column in createTableOperation.Columns)
            {
                GenerateCustomColumnCode(writer, createTableOperation.Name, column.Name);
            }
        }
        public void Annotations_should_return_set_annotations()
        {
            Assert.Empty(new CreateTableOperation("Foo").Annotations);
            Assert.Empty(new CreateTableOperation("Foo", null).Annotations);

            var operation = new CreateTableOperation("Foo", new Dictionary<string, object> { { "A1", "V1" } });

            Assert.Equal("V1", operation.Annotations["A1"]);
        }
        protected override void Generate(CreateTableOperation createTableOperation)
        {
            if ((createTableOperation.PrimaryKey != null)
                && !createTableOperation.PrimaryKey.IsClustered)
            {
                createTableOperation.PrimaryKey.IsClustered = true;
            }

            base.Generate(createTableOperation);
        }
        public void Can_get_and_set_create_table_operation()
        {
            var createTableOperation = new CreateTableOperation("T");

            var dropPrimaryKeyOperation = new DropPrimaryKeyOperation
            {
                CreateTableOperation = createTableOperation
            };

            Assert.Same(createTableOperation, dropPrimaryKeyOperation.CreateTableOperation);
        }
        public void Can_add_and_enumerate_columns()
        {
            var createTableOperation = new CreateTableOperation("Foo");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                    {
                        Name = "Bar",
                        IsNullable = true
                    });

            Assert.NotNull(createTableOperation.Columns.Single());
        }
        public void Inverse_should_return_set_create_table_operation()
        {
            var inverse = new CreateTableOperation("T");
            var operation = new DropTableOperation("T", inverse);

            Assert.Equal("T", operation.Name);
            Assert.Same(inverse, operation.Inverse);

            operation = new DropTableOperation("T", null, null, inverse);

            Assert.Equal("T", operation.Name);
            Assert.Same(inverse, operation.Inverse);
        }
        protected override void Generate(CreateTableOperation createTableOperation)
        {
            if (createTableOperation == null)
            {
                throw new ArgumentNullException("createTableOperation");
            }

            // turn off clustered index for all PKs (except for migration history)
            if (!createTableOperation.Name.Contains("__MigrationHistory"))
            {
                createTableOperation.PrimaryKey.IsClustered = false;
            }

            base.Generate(createTableOperation);
        }
        public void Inverse_should_produce_drop_table_operation()
        {
            var operation = new CreateTableOperation(
                "Foo", new Dictionary<string, object>
                {
                    { "AT1", "VT1" },
                    { "AT2", "VT2" }
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                {
                    Name = "C1",
                    Annotations = new Dictionary<string, AnnotationValues>
                    {
                        { "AC1A", new AnnotationValues(null, "VC1A") },
                        { "AC1B", new AnnotationValues(null, "VC1B") }
                    }
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                {
                    Name = "C2",
                    Annotations = new Dictionary<string, AnnotationValues>
                    {
                        { "AC2A", new AnnotationValues(null, "VC2A") },
                        { "AC2B", new AnnotationValues(null, "VC2B") }
                    }
                });

            var inverse = (DropTableOperation)operation.Inverse;

            Assert.Equal("Foo", inverse.Name);

            Assert.Equal("VT1", inverse.RemovedAnnotations["AT1"]);
            Assert.Equal("VT2", inverse.RemovedAnnotations["AT2"]);

            Assert.Equal("VC1A", inverse.RemovedColumnAnnotations["C1"]["AC1A"]);
            Assert.Equal("VC1B", inverse.RemovedColumnAnnotations["C1"]["AC1B"]);
            Assert.Equal("VC2A", inverse.RemovedColumnAnnotations["C2"]["AC2A"]);
            Assert.Equal("VC2B", inverse.RemovedColumnAnnotations["C2"]["AC2B"]);
        }
        public void Index_should_add_create_index_operation_to_model()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(new ColumnModel(PrimitiveTypeKind.Guid) { Name = "Foo" });
            createTableOperation.Columns.Add(new ColumnModel(PrimitiveTypeKind.Guid) { Name = "Bar" });

            var migration = new TestMigration();
            var tableBuilder = new TableBuilder<Columns>(createTableOperation, migration);

            tableBuilder.Index(c => new { c.Foo, c.Bar }, unique: true);

            Assert.Equal(1, migration.Operations.Count());

            var createIndexOperation
                = migration.Operations.Cast<CreateIndexOperation>().Single();

            Assert.Equal("T", createIndexOperation.Table);
            Assert.True(createIndexOperation.IsUnique);
            Assert.Equal("Foo", createIndexOperation.Columns.First());
            Assert.Equal("Bar", createIndexOperation.Columns.Last());
        }
        protected override void Generate(CreateTableOperation createTableOperation)
        {
            if (createTableOperation == null)
            {
                throw new ArgumentNullException("createTableOperation");
            }

            bool createUpdatedAtTrigger = false;
            string updatedAtColumnName = null;
            string idColumnName = null;
            foreach (ColumnModel column in createTableOperation.Columns)
            {
                TableColumnType tableColumnType = this.GetTableColumnType(column);
                switch (tableColumnType)
                {
                    case TableColumnType.Id:
                        idColumnName = column.Name;
                        break;

                    case TableColumnType.UpdatedAt:
                        createUpdatedAtTrigger = true;
                        updatedAtColumnName = column.Name;
                        break;

                    case TableColumnType.CreatedAt:
                        // If we have this column then use that to create a clustered index for instead of the Id column
                        createTableOperation.PrimaryKey.IsClustered = false;
                        break;
                }
            }

            base.Generate(createTableOperation);

            if (createUpdatedAtTrigger && !string.IsNullOrEmpty(idColumnName) && !string.IsNullOrEmpty(updatedAtColumnName))
            {
                string trigger = this.GetTrigger(createTableOperation.Name, idColumnName, updatedAtColumnName);
                this.Statement(trigger);
            }
        }
Exemple #24
0
        public void PrimaryKey_should_set_key_columns_name_and_clustered()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Foo",
                        ApiPropertyInfo = typeof(Columns).GetProperty("Foo")
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Bar",
                        ApiPropertyInfo = typeof(Columns).GetProperty("Bar")
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Baz"
                    });

            var tableBuilder = new TableBuilder<Columns>(createTableOperation, new TestMigration());

            tableBuilder.PrimaryKey(
                c => new
                         {
                             c.Bar,
                             c.Foo
                         }, name: "PK_Custom", clustered: false);

            Assert.Equal(2, createTableOperation.PrimaryKey.Columns.Count());
            Assert.Equal("Bar", createTableOperation.PrimaryKey.Columns.First());
            Assert.Equal("Foo", createTableOperation.PrimaryKey.Columns.Last());
            Assert.Equal("PK_Custom", createTableOperation.PrimaryKey.Name);
            Assert.False(createTableOperation.PrimaryKey.IsClustered);
        }
 protected virtual IEnumerable<MigrationStatement> Generate(CreateTableOperation operation)
 {
     using (var writer = SqlWriter())
     {
         writer.Write("CREATE TABLE ");
         writer.Write(Quote(operation.Name));
         writer.Write(" (");
         writer.WriteLine();
         writer.Indent++;
         WriteColumns(writer, operation.Columns.Select(Generate), true);
         writer.Indent--;
         writer.WriteLine();
         writer.Write(")");
         yield return Statement(writer);
     }
     if (operation.PrimaryKey != null)
     {
         foreach (var item in Generate(operation.PrimaryKey))
             yield return item;
     }
 }
Exemple #26
0
        public void Generate_can_output_create_index_statement_clustered()
        {
            var createTableOperation = new CreateTableOperation("Customers");
            var idColumn = new ColumnModel(PrimitiveTypeKind.Int32)
                               {
                                   Name = "Id",
                                   IsNullable = true,
                                   IsIdentity = true
                               };
            createTableOperation.Columns.Add(idColumn);
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                    {
                        Name = "Name",
                        IsNullable = false
                    });
            createTableOperation.PrimaryKey = new AddPrimaryKeyOperation();
            createTableOperation.PrimaryKey.Columns.Add(idColumn.Name);

            var migrationSqlGenerator = new SqlCeMigrationSqlGenerator();

            var createIndexOperation = new CreateIndexOperation
                                           {
                                               Table = createTableOperation.Name,
                                               IsUnique = true,
                                               IsClustered = true
                                           };

            createIndexOperation.Columns.Add(idColumn.Name);

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

            Assert.Contains(
                @"CREATE UNIQUE CLUSTERED INDEX [IX_Id] ON [Customers]([Id])", sql);
        }
Exemple #27
0
        public void Generate_can_output_create_table_statement_with_non_clustered_pk()
        {
            var createTableOperation = new CreateTableOperation("foo.Customers");
            var idColumn = new ColumnModel(PrimitiveTypeKind.Int32)
                               {
                                   Name = "Id",
                                   IsNullable = true,
                                   IsIdentity = true
                               };
            createTableOperation.Columns.Add(idColumn);
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                    {
                        Name = "Name",
                        IsNullable = false
                    });

            createTableOperation.PrimaryKey
                = new AddPrimaryKeyOperation
                      {
                          IsClustered = false
                      };

            createTableOperation.PrimaryKey.Columns.Add(idColumn.Name);

            var migrationSqlGenerator = new SqlCeMigrationSqlGenerator();

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

            Assert.Contains(
                @"CREATE TABLE [Customers] (
    [Id] [int] IDENTITY,
    [Name] [ntext] NOT NULL,
    CONSTRAINT [PK_foo.Customers] PRIMARY KEY NONCLUSTERED ([Id])
)", sql);
        }
Exemple #28
0
        public void Generate_can_output_timestamp_column()
        {
            var migrationSqlGenerator = new SqlCeMigrationSqlGenerator();

            var createTableOperation = new CreateTableOperation("Customers");
            var column = new ColumnModel(PrimitiveTypeKind.Binary)
                             {
                                 Name = "Version",
                                 IsTimestamp = true
                             };
            createTableOperation.Columns.Add(column);

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

            Assert.Contains(@"[Version] rowversion", sql);
        }
        public void Generate_can_output_create_table_statement()
        {
            var createTableOperation = new CreateTableOperation("Customers");
            var idColumn = new ColumnModel(PrimitiveTypeKind.Int32)
                               {
                                   Name = "Id",
                                   IsNullable = true,
                                   IsIdentity = true
                               };
            createTableOperation.Columns.Add(idColumn);
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                    {
                        Name = "Name",
                        IsNullable = false
                    });
            createTableOperation.PrimaryKey = new AddPrimaryKeyOperation
                                                  {
                                                      Name = "MyPK"
                                                  };
            createTableOperation.PrimaryKey.Columns.Add(idColumn.Name);

            var codeGenerator = new VisualBasicMigrationCodeGenerator();

            var addForeignKeyOperation = new AddForeignKeyOperation
                                             {
                                                 DependentTable = "Customers",
                                                 PrincipalTable = "Blogs",
                                                 CascadeDelete = true
                                             };
            addForeignKeyOperation.DependentColumns.Add("Blog_Id");
            addForeignKeyOperation.PrincipalColumns.Add("Id");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            createTableOperation,
                            addForeignKeyOperation,
                            addForeignKeyOperation.CreateCreateIndexOperation()
                        },
                    "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()
            CreateTable(
                ""Customers"",
                Function(c) New With
                    {
                        .Id = c.Int(identity := True),
                        .Name = c.String(nullable := False)
                    }) _
                .PrimaryKey(Function(t) t.Id, name := ""MyPK"") _
                .ForeignKey(""Blogs"", Function(t) t.Blog_Id, cascadeDelete := True) _
                .Index(Function(t) t.Blog_Id)
            
        End Sub
        
        Public Overrides Sub Down()
            DropIndex(""Customers"", New String() { ""Blog_Id"" })
            DropForeignKey(""Customers"", ""Blog_Id"", ""Blogs"")
            DropTable(""Customers"")
        End Sub
    End Class
End Namespace
",
                generatedMigration.UserCode);

            Assert.Equal(
                @"' <auto-generated />
Imports System.Data.Entity.Migrations
Imports System.Data.Entity.Migrations.Infrastructure
Imports System.Resources

Namespace Foo
    Public NotInheritable Partial Class Bar
        Implements IMigrationMetadata
    
        Private ReadOnly Resources As New ResourceManager(GetType(Bar))
        
        Private ReadOnly Property IMigrationMetadata_Id() As String Implements IMigrationMetadata.Id
            Get
                Return ""Migration""
            End Get
        End Property
        
        Private ReadOnly Property IMigrationMetadata_Source() As String Implements IMigrationMetadata.Source
            Get
                Return Resources.GetString(""Source"")
            End Get
        End Property
        
        Private ReadOnly Property IMigrationMetadata_Target() As String Implements IMigrationMetadata.Target
            Get
                Return Resources.GetString(""Target"")
            End Get
        End Property
    End Class
End Namespace
",
                generatedMigration.DesignerCode);

            Assert.Equal("vb", generatedMigration.Language);
            Assert.Equal(2, generatedMigration.Resources.Count);
            Assert.Equal("Source", generatedMigration.Resources["Source"]);
            Assert.Equal("Target", generatedMigration.Resources["Target"]);
        }
        public void Generate_can_output_timestamp_column()
        {
            var codeGenerator = new VisualBasicMigrationCodeGenerator();

            var createTableOperation = new CreateTableOperation("Customers");
            var column = new ColumnModel(PrimitiveTypeKind.Binary)
                             {
                                 Name = "Version",
                                 IsTimestamp = true
                             };
            createTableOperation.Columns.Add(column);

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { createTableOperation },
                    "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()
            CreateTable(
                ""Customers"",
                Function(c) New With
                    {
                        .Version = c.Binary(timestamp := True)
                    })
            
        End Sub
        
        Public Overrides Sub Down()
            DropTable(""Customers"")
        End Sub
    End Class
End Namespace
",
                generatedMigration.UserCode);
        }
        protected virtual MigrationStatement Generate(CreateTableOperation op)
        {
            StringBuilder sb = new StringBuilder();

              if (_generatedTables == null)
            _generatedTables = new List<string>();

              if (!_generatedTables.Contains(op.Name))
              {
            _generatedTables.Add(op.Name);
              }
              sb.Append("create table " + "`" + op.Name + "`" + " (");

              _tableName = op.Name;
              //columns
              sb.Append(string.Join(",", op.Columns.Select(c => "`" + c.Name + "` " + Generate(c))));

              if (op.PrimaryKey != null && !sb.ToString().Contains("primary key"))
              {
            sb.Append(",");
            sb.Append("primary key ( " + string.Join(",", op.PrimaryKey.Columns.Select(c => "`" + c + "`")) + ") ");
              }

              sb.Append(") engine=InnoDb auto_increment=0");

              return new MigrationStatement() { Sql = sb.ToString() };
        }