public void Can_get_and_set_rename_properties()
        {
            var renameTableOperation = new RenameTableOperation("N", "N'");

            Assert.Equal("N", renameTableOperation.Name);
            Assert.Equal("N'", renameTableOperation.NewName);
        }
Exemplo n.º 2
0
        public void Inverse_should_produce_rename_column_operation()
        {
            var renameTableOperation
                = new RenameTableOperation("dbo.Foo", "dbo.Bar")
                      {
                          IsSystem = true
                      };

            var inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);
            Assert.True(inverse.IsSystem);

            renameTableOperation = new RenameTableOperation("dbo.Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);

            renameTableOperation = new RenameTableOperation("Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);
        }
        public void Can_get_and_set_rename_properties()
        {
            var renameTableOperation = new RenameTableOperation("N", "N'");

            Assert.Equal("N", renameTableOperation.Name);
            Assert.Equal("N'", renameTableOperation.NewName);
        }
Exemplo n.º 4
0
        public void Inverse_should_produce_rename_column_operation()
        {
            var renameTableOperation
                = new RenameTableOperation("dbo.Foo", "dbo.Bar")
                {
                IsSystem = true
                };

            var inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);
            Assert.True(inverse.IsSystem);

            renameTableOperation = new RenameTableOperation("dbo.Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);

            renameTableOperation = new RenameTableOperation("Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);
        }
        public void Inverse_should_produce_rename_column_operation()
        {
            var renameTableOperation = new RenameTableOperation("N", "N'");

            var inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("N'", inverse.Name);
            Assert.Equal("N", inverse.NewName);
        }
        /// <inheritdoc />
        protected override void Generate(RenameTableOperation renameTableOperation)
        {
            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(renameTableOperation.Name.Split(new[] { '.' }, 2).Last());
                writer.Write("', @newname = N'");
                writer.Write(renameTableOperation.NewName);
                writer.Write("', @objtype = N'OBJECT'");

                Statement(writer);
            }
        }
        /// <inheritdoc />
        protected override void Generate(RenameTableOperation renameTableOperation)
        {
            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(renameTableOperation.Name.ToDatabaseName().Name);
                writer.Write("', @newname = N'");
                writer.Write(renameTableOperation.NewName);
                writer.Write("', @objtype = N'OBJECT'");

                Statement(writer);
            }
        }
        public void Inverse_should_produce_rename_table_operation()
        {
            var renameTableOperation
                = new RenameTableOperation("dbo.Foo", "dbo.Bar");

            var inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);

            renameTableOperation = new RenameTableOperation("dbo.Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);

            renameTableOperation = new RenameTableOperation("Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);
        }
        public void Inverse_should_produce_rename_table_operation()
        {
            var renameTableOperation
                = new RenameTableOperation("dbo.Foo", "dbo.Bar");

            var inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);

            renameTableOperation = new RenameTableOperation("dbo.Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("dbo.Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);

            renameTableOperation = new RenameTableOperation("Foo", "Bar");

            inverse = (RenameTableOperation)renameTableOperation.Inverse;

            Assert.Equal("Bar", inverse.Name);
            Assert.Equal("Foo", inverse.NewName);
        }
        private void Generate(HistoryRebuildOperationSequence sequence)
        {
            DebugCheck.NotNull(sequence);

            var createTableOperationSource = sequence.DropPrimaryKeyOperation.CreateTableOperation;
            var createTableOperationTarget = ResolveNameConflicts(createTableOperationSource);
            var renameTableOperation = new RenameTableOperation(
                createTableOperationTarget.Name, HistoryContext.DefaultTableName);

            using (var writer = Writer())
            {
                WriteCreateTable(createTableOperationTarget, writer);
                writer.WriteLine();

                // Copy the data from the original table into the new table.
                writer.Write("INSERT INTO ");
                writer.WriteLine(Name(createTableOperationTarget.Name));
                writer.Write("SELECT ");

                var first = true;
                foreach (var column in createTableOperationSource.Columns)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(", ");
                    }

                    writer.Write(
                        (column.Name == sequence.AddColumnOperation.Column.Name)
                            ? Generate((string)sequence.AddColumnOperation.Column.DefaultValue)
                            : (column.Type == PrimitiveTypeKind.String)
                                  ? "LEFT(" + Name(column.Name) + ", " + column.MaxLength + ")"
                                  : Name(column.Name));
                }

                writer.Write(" FROM ");
                writer.WriteLine(Name(createTableOperationSource.Name));

                writer.Write("DROP TABLE ");
                writer.WriteLine(Name(createTableOperationSource.Name));

                WriteRenameTable(renameTableOperation, writer);

                Statement(writer);
            }
        }
 private void Convert(RenameTableOperation renameTableOperation)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("ALTER TABLE ");
     AppendTableName(renameTableOperation.Name, sql);
     sql.Append(" RENAME TO ");
     AppendTableName(renameTableOperation.NewName, sql);
     AddStatment(sql);
 }
        public void Generate_can_output_rename_table_statements()
        {
            var renameTableOperation = new RenameTableOperation("dbo.Foo", "Bar");

            var migrationSqlGenerator = new SqlServerMigrationSqlGenerator();

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

            Assert.Contains(
                @"EXECUTE sp_rename @objname = N'dbo.Foo', @newname = N'Bar', @objtype = N'OBJECT'
IF object_id('[PK_dbo.Foo]') IS NOT NULL BEGIN
    EXECUTE sp_rename @objname = N'[PK_dbo.Foo]', @newname = N'PK_dbo.Bar', @objtype = N'OBJECT'
END", sql);
        }
        /// <summary>
        ///     Generates code to perform a <see cref = "RenameTableOperation" />.
        /// </summary>
        /// <param name = "renameTableOperation">The operation to generate code for.</param>
        /// <param name = "writer">Text writer to add the generated code to.</param>
        protected virtual void Generate(RenameTableOperation renameTableOperation, IndentedTextWriter writer)
        {
            Contract.Requires(renameTableOperation != null);
            Contract.Requires(writer != null);

            writer.Write("RenameTable(name := ");
            writer.Write(Quote(renameTableOperation.Name));
            writer.Write(", newName := ");
            writer.Write(Quote(renameTableOperation.NewName));
            writer.WriteLine(")");
        }
        /// <summary>
        ///     Generates SQL for a <see cref = "RenameTableOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name = "renameTableOperation">The operation to produce SQL for.</param>
        protected virtual void Generate(RenameTableOperation renameTableOperation)
        {
            Contract.Requires(renameTableOperation != null);

            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(renameTableOperation.Name);
                writer.Write("', @newname = N'");
                writer.Write(renameTableOperation.NewName);
                writer.Write("', @objtype = N'OBJECT'");

                Statement(writer);
            }
        }
        public void Generate_can_output_rename_table_statements()
        {
            var renameTableOperation = new RenameTableOperation("dbo.Foo", "Bar");

            var migrationSqlGenerator = new SqlCeMigrationSqlGenerator();

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

            Assert.Contains(
                @"EXECUTE sp_rename @objname = N'Foo', @newname = N'Bar', @objtype = N'OBJECT'", sql);
        }
        protected virtual MigrationStatement Generate(RenameTableOperation op)
        {
            if (op == null) return null;

              StringBuilder sb = new StringBuilder();
              sb.AppendFormat("rename table `{0}` to `{1}`", op.Name, op.NewName);
              return new MigrationStatement { Sql = sb.ToString() };
        }
        /// <summary>
        /// Generates code to perform a <see cref="RenameTableOperation" />.
        /// </summary>
        /// <param name="renameTableOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(RenameTableOperation renameTableOperation, IndentedTextWriter writer)
        {
            Check.NotNull(renameTableOperation, "renameTableOperation");
            Check.NotNull(writer, "writer");

            writer.Write("RenameTable(name := ");
            writer.Write(Quote(renameTableOperation.Name));
            writer.Write(", newName := ");
            writer.Write(Quote(renameTableOperation.NewName));
            writer.WriteLine(")");
        }
        /// <summary>
        /// Generates SQL for a <see cref="RenameTableOperation" />.
        /// Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="renameTableOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(RenameTableOperation renameTableOperation)
        {
            Check.NotNull(renameTableOperation, "renameTableOperation");

            using (var writer = Writer())
            {
                WriteRenameTable(renameTableOperation, writer);

                // rename the PK constraint
                var oldPkName = PrimaryKeyOperation.BuildDefaultName(renameTableOperation.Name);
                var newPkName = PrimaryKeyOperation.BuildDefaultName(((RenameTableOperation)renameTableOperation.Inverse).Name);

                writer.WriteLine();
                writer.Write("IF object_id('");
                writer.Write(Escape(Quote(oldPkName)));
                writer.WriteLine("') IS NOT NULL BEGIN");
                writer.Indent++;
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(Escape(Quote(oldPkName)));
                writer.Write("', @newname = N'");
                writer.Write(Escape(newPkName));
                writer.WriteLine("', @objtype = N'OBJECT'"); 
                writer.Indent--;
                writer.Write("END");

                Statement(writer);
            }
        }
 /// <summary>
 /// Gera SQL para uma operação <see cref="RenameTableOperation" />.
 /// </summary>
 /// <param name="opeRenameTable"> The operation to produce SQL for. </param>
 protected virtual void Generate(RenameTableOperation opeRenameTable)
 {
     //throw new NotSupportedException();
 }
 private static void WriteRenameTable(RenameTableOperation renameTableOperation, IndentedTextWriter writer)
 {
     writer.Write("EXECUTE sp_rename @objname = N'");
     writer.Write(Escape(renameTableOperation.Name));
     writer.Write("', @newname = N'");
     writer.Write(Escape(renameTableOperation.NewName));
     writer.Write("', @objtype = N'OBJECT'");
 }
        /// <summary>
        ///     Generates SQL for a <see cref="RenameTableOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="renameTableOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(RenameTableOperation renameTableOperation)
        {
            Check.NotNull(renameTableOperation, "renameTableOperation");

            using (var writer = Writer())
            {
                WriteRenameTable(renameTableOperation, writer);

                Statement(writer);
            }
        }
 protected override void Generate(RenameTableOperation renameTableOperation, IndentedTextWriter writer)
 {
     var rename = new RenameTableOperation(TrimSchemaPrefix(renameTableOperation.Name), renameTableOperation.NewName);
       base.Generate(rename, writer);
 }
		protected virtual IEnumerable<MigrationStatement> Generate(RenameTableOperation operation)
		{
			throw new NotSupportedException("Renaming table is not supported by Firebird.");
		}
 protected virtual IEnumerable<MigrationStatement> Generate(RenameTableOperation operation)
 {
     using (var writer = SqlWriter())
     {
         writer.Write("RENAME TABLE ");
         writer.Write(Quote(operation.Name));
         writer.Write(" TO ");
         writer.Write(Quote(operation.NewName));
         yield return Statement(writer);
     }
 }
        /// <summary>
        ///     Generates SQL for a <see cref="RenameTableOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="renameTableOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(RenameTableOperation renameTableOperation)
        {
            Check.NotNull(renameTableOperation, "renameTableOperation");

            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(Escape(DatabaseName.Parse(renameTableOperation.Name).Name));
                writer.Write("', @newname = N'");
                writer.Write(Escape(renameTableOperation.NewName));
                writer.Write("', @objtype = N'OBJECT'");

                Statement(writer);
            }
        }