Exemplo n.º 1
0
        /// <summary>
        ///     Builds commands for the given <see cref="RenameIndexOperation" />
        ///     by making calls on the given <see cref="MigrationCommandListBuilder" />.
        /// </summary>
        /// <param name="operation"> The operation. </param>
        /// <param name="model"> The target model which may be <c>null</c> if the operations exist without a model. </param>
        /// <param name="builder"> The command builder to use to build the commands. </param>
        protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder)
        {
            var index = FindEntityTypes(model, operation.Schema, operation.Table)
                        ?.SelectMany(t => t.GetDeclaredIndexes()).Where(i => i.Relational().Name == operation.NewName)
                        .FirstOrDefault();

            if (index == null)
            {
                throw new NotSupportedException(
                          TaosStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName()));
            }

            var dropOperation = new DropIndexOperation
            {
                Schema = operation.Schema,
                Table  = operation.Table,
                Name   = operation.Name
            };

            dropOperation.AddAnnotations(_migrationsAnnotations.ForRemove(index));

            var createOperation = new CreateIndexOperation
            {
                IsUnique = index.IsUnique,
                Name     = operation.NewName,
                Schema   = operation.Schema,
                Table    = operation.Table,
                Columns  = index.Properties.Select(p => p.Relational().ColumnName).ToArray(),
                Filter   = index.Relational().Filter
            };

            createOperation.AddAnnotations(_migrationsAnnotations.For(index));

            //   Generate(dropOperation, model, builder, terminate: false);
            builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

            Generate(createOperation, model, builder);
        }
Exemplo n.º 2
0
        public override void Generate(RenameIndexOperation renameIndexOperation, IndentedStringBuilder stringBuilder, bool generateIdempotentSql)
        {
            Check.NotNull(renameIndexOperation, "renameIndexOperation");
            Check.NotNull(stringBuilder, "stringBuilder");

            if (generateIdempotentSql)
            {
                GenerateIndexPresenceCheck(
                    renameIndexOperation.TableName,
                    renameIndexOperation.IndexName,
                    negative: false,
                    builder: stringBuilder);

                using (stringBuilder.AppendLine().Indent())
                {
                    base.Generate(renameIndexOperation, stringBuilder, generateIdempotentSql: false);
                }
            }
            else
            {
                base.Generate(renameIndexOperation, stringBuilder, generateIdempotentSql);
            }
        }
Exemplo n.º 3
0
        protected override void Generate(
            [NotNull] RenameIndexOperation operation,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            var qualifiedName = new StringBuilder();

            if (operation.Schema != null)
            {
                qualifiedName
                .Append(operation.Schema)
                .Append(".");
            }
            qualifiedName
            .Append(operation.Table)
            .Append(".")
            .Append(operation.Name);

            Rename(qualifiedName.ToString(), operation.NewName, "INDEX", builder);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Builds commands for the given <see cref="RenameIndexOperation" />
        ///     by making calls on the given <see cref="MigrationCommandListBuilder" />.
        /// </summary>
        /// <param name="operation"> The operation. </param>
        /// <param name="model"> The target model which may be <c>null</c> if the operations exist without a model. </param>
        /// <param name="builder"> The command builder to use to build the commands. </param>
        protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder)
        {
            var index = model.GetRelationalModel().FindTable(operation.Table, operation.Schema)
                        ?.Indexes.FirstOrDefault(i => i.Name == operation.NewName);

            if (index == null)
            {
                throw new NotSupportedException(
                          SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName()));
            }

            var dropOperation = new DropIndexOperation
            {
                Schema = operation.Schema,
                Table  = operation.Table,
                Name   = operation.Name
            };

            dropOperation.AddAnnotations(index.GetAnnotations());

            var createOperation = new CreateIndexOperation
            {
                IsUnique = index.IsUnique,
                Name     = operation.NewName,
                Schema   = operation.Schema,
                Table    = operation.Table,
                Columns  = index.Columns.Select(p => p.Name).ToArray(),
                Filter   = index.Filter
            };

            createOperation.AddAnnotations(index.GetAnnotations());

            Generate(dropOperation, model, builder, terminate: false);
            builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

            Generate(createOperation, model, builder);
        }
        protected override void Generate(
            RenameIndexOperation operation,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            var qualifiedName = new StringBuilder();

            if (operation.Schema != null)
            {
                qualifiedName
                .Append(operation.Schema)
                .Append(".");
            }
            qualifiedName
            .Append(operation.Table)
            .Append(".")
            .Append(operation.Name);

            Rename(qualifiedName.ToString(), operation.NewName, "INDEX", builder);
            EndStatement(builder);
        }
Exemplo n.º 6
0
 /// <summary>
 /// 重命名索引。
 /// </summary>
 /// <param name="operation">操作实例。</param>
 /// <param name="builder"><see cref="MigrationCommandListBuilder"/>实例对象。</param>
 protected virtual void Generate(
     RenameIndexOperation operation,
     MigrationCommandListBuilder builder)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public abstract void Generate([NotNull] RenameIndexOperation renameIndexOperation, [NotNull] IndentedStringBuilder stringBuilder);
Exemplo n.º 8
0
 public virtual void Generate([NotNull] RenameIndexOperation renameIndexOperation, [NotNull] IndentedStringBuilder stringBuilder)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 private string GenerateSqlStatementConcrete(RenameIndexOperation migrationOperation)
 {
     throw new NotSupportedException("Cannot rename objects with Jet");
 }
 protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder)
 => throw new NotSupportedException("Renaming index is not supported by Firebird.");
 /// <summary>
 /// Generates SQL for a <see cref="RenameIndexOperation" />.
 /// Generated SQL should be added using the Statement method.
 /// </summary>
 /// <param name="renameIndexOperation"> The operation to produce SQL for. </param>
 protected virtual void Generate(RenameIndexOperation renameIndexOperation)
 {
     throw Error.SqlCeIndexRenameNotSupported();
 }
 protected override void Generate(RenameIndexOperation operation, IModel model, RelationalCommandListBuilder builder)
 {
 }
 protected virtual IEnumerable <MigrationStatement> Generate(RenameIndexOperation operation)
 {
     throw new NotSupportedException("'RenameIndexOperation' is not supported.");
 }
Exemplo n.º 14
0
 protected override void Generate(RenameIndexOperation operation, IModel model, RelationalCommandListBuilder builder)
 {
     throw new NotSupportedException(SqliteStrings.InvalidMigrationOperation);
 }
 protected override void Generate(RenameIndexOperation renameIndexOperation, IndentedTextWriter writer)
 {
     base.Generate(renameIndexOperation, writer);
 }
 public override void Generate(RenameIndexOperation renameIndexOperation, IndentedStringBuilder stringBuilder)
 {
     // TODO: Rebuild index
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
 public override void Generate(RenameIndexOperation renameIndexOperation, SqlBatchBuilder batchBuilder)
 {
 }
 protected override void Generate(RenameIndexOperation operation, IModel model, SqlBatchBuilder builder)
 {
     throw new NotSupportedException(Strings.InvalidMigrationOperation);
 }
Exemplo n.º 19
0
 public abstract void Generate(
     [NotNull] RenameIndexOperation operation,
     [CanBeNull] IModel model,
     [NotNull] SqlBatchBuilder builder);
Exemplo n.º 20
0
 public override void Generate(RenameIndexOperation operation, IModel model, SqlBatchBuilder builder)
 {
     throw new NotImplementedException();
 }
 protected virtual IEnumerable <MigrationStatement> Generate(RenameIndexOperation operation)
 {
     throw new NotSupportedException("Renaming index is not supported by Firebird.");
 }
 protected override void Generate(RenameIndexOperation operation, IModel model, SqlBatchBuilder builder)
 {
 }
Exemplo n.º 23
0
 protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder)
 {
     throw new NotSupportedException(SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName()));
 }
Exemplo n.º 24
0
 private void Generate(RenameIndexOperation renameIndexOperation)
 {
     throw new NotImplementedException();
 }
 protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder)
 => throw new NotImplementedException("The RenameIndexOperation feature is not yet implemented.");
 public abstract void Generate([NotNull] RenameIndexOperation renameIndexOperation, [NotNull] SqlBatchBuilder batchBuilder);