public void CollectionNamespace_get_should_return_expected_result() { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var result = subject.CollectionNamespace; result.Should().BeSameAs(_collectionNamespace); }
public void constructor_with_collectionNamespace_indexName_messageEncoderSettings_should_initialize_subject() { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace); subject.IndexName.Should().Be(indexName); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); }
/// <summary> /// 删除索引。 /// </summary> /// <param name="operation">操作实例。</param> /// <param name="builder"><see cref="MigrationCommandListBuilder"/>实例对象。</param> protected override void Generate( DropIndexOperation operation, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("DROP INDEX ") .Append(SqlHelper.DelimitIdentifier(operation.Name)) .Append(" ON ") .Append(operation.Table); }
protected override void Generate(DropIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { ThrowIf.Argument.IsNull(operation, "DropIndexOperation"); ThrowIf.Argument.IsNull(model, "model"); ThrowIf.Argument.IsNull(builder, "builder"); builder .Append("DROP INDEX ") .Append(operation.Name) .Append(" ON " + operation.Table) .AppendLine(_sqlGenerationHelper.StatementTerminator); EndStatement(builder); }
/// <summary> /// Builds commands for the given <see cref="DropIndexOperation" /> /// 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> /// <param name="terminate"> Indicates whether or not to terminate the command after generating SQL for the operation. </param> protected override void Generate([NotNull] DropIndexOperation operation, [CanBeNull] IModel model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("DROP INDEX ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name)); builder .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator) .EndCommand(); }
protected internal void DropIndex(string table, string[] columns, string schema = "dbo", object anonymousArguments = null) { RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)"); RuntimeFailureMethods.Requires(columns != null, null, "columns != null"); table = string.Format("{0}.{1}", schema, table); var dropIndexOperation = new DropIndexOperation(anonymousArguments) { Table = table }; columns.Each(c => dropIndexOperation.Columns.Add(c) ); AddOperation(dropIndexOperation); }
private void Generate(DropIndexOperation op) { using (var tw = Format.CreateIndentedTextWriter()) { var indexName = op.HasDefaultName ? string.Format(CultureInfo.InvariantCulture, "{0}_{1}", op.Name, Format.ReservedWord(Format.RemoveDbo(op.Table))) : op.Name; tw.Write("DROP INDEX "); tw.Write(indexName); AddSqlStatement(tw); } }
protected override void Generate(DropIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("ALTER TABLE ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) .Append(" DROP INDEX ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Name)) .AppendLine(SqlGenerationHelper.StatementTerminator); EndStatement(builder); }
/// <summary> /// 删除索引。 /// </summary> /// <typeparam name="TEntity">实体类型。</typeparam> /// <param name="name">索引名称(全名,包含IX_)。</param> /// <returns>返回迁移实例。</returns> public virtual OperationBuilder <DropIndexOperation> DropIndex <TEntity>(string name) { Check.NotEmpty(name, nameof(name)); var operation = new DropIndexOperation { Table = typeof(TEntity).GetTableName(), Name = name }; Operations.Add(operation); return(new OperationBuilder <DropIndexOperation>(operation)); }
protected override void Generate( DropIndexOperation operation, IModel model, RelationalCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("DROP INDEX ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Name)) .Append(" ON ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)); }
public override void Generate( [NotNull] DropIndexOperation operation, [CanBeNull] IModel model, [NotNull] SqlBatchBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("DROP INDEX ") .Append(_sql.DelimitIdentifier(operation.Name)) .Append(" ON ") .Append(_sql.DelimitIdentifier(operation.Table, operation.Schema)); }
/// <summary> /// Generates SQL for a <see cref="DropIndexOperation" />. /// Generated SQL should be added using the Statement method. /// </summary> /// <param name="dropIndexOperation"> The operation to produce SQL for. </param> protected virtual void Generate(DropIndexOperation dropIndexOperation) { Check.NotNull(dropIndexOperation, "dropIndexOperation"); using (var writer = Writer()) { writer.Write("DROP INDEX "); writer.Write(Name(dropIndexOperation.Table)); writer.Write("."); writer.Write(Quote(dropIndexOperation.Name)); Statement(writer); } }
protected override void Generate( DropIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { ThrowIf.Argument.IsNull(operation, "operation"); ThrowIf.Argument.IsNull(builder, "builder"); builder .Append("DROP INDEX ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Name)) .Append(" ON ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) .AppendLine(SqlGenerationHelper.StatementTerminator); }
private void Generate(DropIndexOperation dropIndexOperation) { ArgumentUtility.CheckNotNull("dropIndexOperation", dropIndexOperation); throw new NotImplementedException("DropIndexOperation"); //using (var writer = Writer()) { // writer.Write("DROP INDEX "); // writer.Write(Quote(dropIndexOperation.Name)); // writer.Write(" ON "); // writer.Write(Name(dropIndexOperation.Table)); // Statement(writer); //} }
public virtual OperationBuilder <DropIndexOperation> DropIndex(string name, string table = null, string schema = null) { Check.NotEmpty(name, nameof(name)); var operation = new DropIndexOperation { Schema = schema, Table = table, Name = name }; Operations.Add(operation); return(new OperationBuilder <DropIndexOperation>(operation)); }
/// <summary> /// 删除索引。 /// </summary> /// <typeparam name="TEntity">实体类型。</typeparam> /// <param name="columns">列表达式。</param> /// <returns>返回迁移实例。</returns> public virtual OperationBuilder <DropIndexOperation> DropIndex <TEntity>( Expression <Func <TEntity, object> > columns) { Check.NotNull(columns, nameof(columns)); var operation = new DropIndexOperation { Table = typeof(TEntity).GetTableName() }; operation.Name = OperationHelper.GetName(NameType.Index, operation.Table, columns.GetPropertyNames()); Operations.Add(operation); return(new OperationBuilder <DropIndexOperation>(operation)); }
protected internal void DropIndex( string table, string name, object anonymousArguments = null) { Check.NotEmpty(table, "table"); Check.NotEmpty(name, "name"); var dropIndexOperation = new DropIndexOperation(anonymousArguments) { Table = table, Name = name, }; AddOperation(dropIndexOperation); }
protected virtual void Generate( DropIndexOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate) { builder .Append("DROP INDEX ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name)); if (terminate) { builder .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator) .EndCommand(); } }
public void Visit_with_drop_index_operation() { var model = new DatabaseModel(); var column = new Column("Foo", typeof(int)); var table = new Table("dbo.MyTable", new[] { column }); var index = new Index("IX", new[] { column }, isUnique: true, isClustered: true); var operation = new DropIndexOperation("dbo.MyTable", "IX"); model.AddTable(table); table.AddIndex(index); Assert.Equal(1, table.Indexes.Count); operation.Accept(new DatabaseModelModifier(), model); Assert.Equal(0, table.Indexes.Count); }
/// <inheritdoc /> protected override void Generate(DropIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { if (!operation.IfExistsCheckRequired()) { base.Generate(operation, model, builder); return; } builder.AppendLine($"IF(IndexProperty(OBJECT_ID('{DelimitIdentifier(operation.Table, operation.Schema)}'), {GenerateSqlLiteral(operation.Name)}, 'IndexId') IS NOT NULL)") .AppendLine("BEGIN"); using (builder.Indent()) { base.Generate(operation, model, builder, false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } builder.AppendLine("END") .EndCommand(); }
protected virtual void DropIndexes( [NotNull] IEnumerable <IIndex> indexes, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(indexes, nameof(indexes)); Check.NotNull(builder, nameof(builder)); foreach (var index in indexes) { var operation = new DropIndexOperation { Schema = index.DeclaringEntityType.Relational().Schema, Table = index.DeclaringEntityType.Relational().TableName, Name = index.Relational().Name }; operation.AddAnnotations(_migrationsAnnotations.ForRemove(index)); Generate(operation, index.DeclaringEntityType.Model, builder, terminate: false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } }
protected virtual void Generate( [NotNull] DropIndexOperation operation, [CanBeNull] IModel model, [NotNull] MigrationCommandListBuilder builder, bool terminate) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("DROP INDEX ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name)) .Append(" ON ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)); if (terminate) { builder .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator) .EndCommand(); } }
/// <summary> /// Generates SQL to drop the given indexes. /// </summary> /// <param name="indexes"> The indexes to drop. </param> /// <param name="builder"> The command builder to use to build the commands. </param> protected virtual void DropIndexes( [NotNull] IEnumerable <ITableIndex> indexes, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(indexes, nameof(indexes)); Check.NotNull(builder, nameof(builder)); foreach (var index in indexes) { var table = index.Table; var operation = new DropIndexOperation { Schema = table.Schema, Table = table.Name, Name = index.Name }; operation.AddAnnotations(index.GetAnnotations()); Generate(operation, table.Model.Model, builder, terminate: false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } }
/// <summary> /// Generates code to perform a <see cref="DropIndexOperation" />. /// </summary> /// <param name="dropIndexOperation"> The operation to generate code for. </param> /// <param name="writer"> Text writer to add the generated code to. </param> protected virtual void Generate(DropIndexOperation dropIndexOperation, IndentedTextWriter writer) { Check.NotNull(dropIndexOperation, "dropIndexOperation"); Check.NotNull(writer, "writer"); writer.Write("DropIndex("); writer.Write(Quote(dropIndexOperation.Table)); writer.Write(", "); if (!dropIndexOperation.HasDefaultName) { writer.Write(Quote(dropIndexOperation.Name)); } else { writer.Write("New String() { "); writer.Write(dropIndexOperation.Columns.Join(Quote)); writer.Write(" }"); } writer.WriteLine(")"); }
/// <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( SqliteStrings.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); }
protected internal void DropIndex( string table, string[] columns, object anonymousArguments = null) { Check.NotEmpty(table, "table"); Check.NotNull(columns, "columns"); if (!columns.Any()) { throw new ArgumentException(Strings.CollectionEmpty("columns", "DropIndex")); } var dropIndexOperation = new DropIndexOperation(anonymousArguments) { Table = table, }; columns.Each(c => dropIndexOperation.Columns.Add(c)); AddOperation(dropIndexOperation); }
public override void Generate(DropIndexOperation dropIndexOperation, IndentedStringBuilder stringBuilder, bool generateIdempotentSql) { Check.NotNull(dropIndexOperation, "dropIndexOperation"); Check.NotNull(stringBuilder, "stringBuilder"); if (generateIdempotentSql) { GenerateIndexPresenceCheck( dropIndexOperation.TableName, dropIndexOperation.IndexName, negative: false, builder: stringBuilder); using (stringBuilder.AppendLine().Indent()) { base.Generate(dropIndexOperation, stringBuilder, generateIdempotentSql: false); } } else { base.Generate(dropIndexOperation, stringBuilder, generateIdempotentSql); } }
/// <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 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 override void Generate( DropIndexOperation operation, IModel model, MigrationCommandListBuilder builder) => Generate(operation, model, builder, terminate: true);
public void Execute_should_throw_when_a_write_concern_error_occurs( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet); EnsureIndexExists(); var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings) { WriteConcern = new WriteConcern(9) }; var exception = Record.Exception(() => ExecuteOperation(subject, async)); exception.Should().BeOfType<MongoWriteConcernException>(); }
public void CreateCommand_should_return_expectedResult() { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var expectedResult = new BsonDocument { { "dropIndexes", _collectionNamespace.CollectionName }, { "index", indexName } }; var result = subject.CreateCommand(null); result.Should().Be(expectedResult); }
public async Task ExecuteAsync_should_throw_when_binding_is_null() { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var ex = await CatchAsync<ArgumentNullException>(() => subject.ExecuteAsync(null, CancellationToken.None)); ex.ParamName.Should().Be("binding"); }
protected override void Generate(DropIndexOperation operation, IModel model, RelationalCommandListBuilder builder) { }
public override Task DropAllAsync(CancellationToken cancellationToken) { var operation = new DropIndexOperation(_collection._collectionNamespace, "*", _collection._messageEncoderSettings); return(_collection.ExecuteWriteOperation(operation, cancellationToken)); }
public void Execute_should_not_throw_when_collection_does_not_exist( [Values(false, true)] bool async) { RequireServer.Check(); DropCollection(); using (var binding = CoreTestConfiguration.GetReadWriteBinding()) { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); ExecuteOperation(subject, async); // should not throw } }
public void CreateCommand_should_return_expectedResult_when_WriteConcern_is_set( [Values(null, 1, 2)] int? w, [Values(false, true)] bool isWriteConcernSupported) { var indexName = "x_1"; var writeConcern = w.HasValue ? new WriteConcern(w.Value) : null; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings) { WriteConcern = writeConcern }; var serverVersion = Feature.CommandsThatWriteAcceptWriteConcern.SupportedOrNotSupportedVersion(isWriteConcernSupported); var result = subject.CreateCommand(serverVersion); var expectedResult = new BsonDocument { { "dropIndexes", _collectionNamespace.CollectionName }, { "index", indexName }, { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null && isWriteConcernSupported } }; result.Should().Be(expectedResult); }
public async Task ExecuteAsync_should_not_throw_when_collection_does_not_exist() { using (var binding = CoreTestConfiguration.GetReadWriteBinding()) { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); await subject.ExecuteAsync(binding, CancellationToken.None); // should not throw } }
public void constructor_with_collectionNamespace_keys_messageEncoderSettings_should_initialize_subject() { var keys = new BsonDocument { { "x", 1 } }; var expectedIndexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, keys, _messageEncoderSettings); subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace); subject.IndexName.Should().Be(expectedIndexName); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); }
public async Task ExecuteAsync_should_return_expected_result() { using (var binding = CoreTestConfiguration.GetReadWriteBinding()) { var keys = new BsonDocument("x", 1); var requests = new[] { new CreateIndexRequest(keys) }; var createIndexOperation = new CreateIndexesOperation(_collectionNamespace, requests, _messageEncoderSettings); await createIndexOperation.ExecuteAsync(binding, CancellationToken.None); var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var result = await subject.ExecuteAsync(binding, CancellationToken.None); result["ok"].ToBoolean().Should().BeTrue(); } }
public void WriteConcern_get_and_set_should_work( [Values(null, 1, 2)] int? w) { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var value = w.HasValue ? new WriteConcern(w.Value) : null; subject.WriteConcern = value; var result = subject.WriteConcern; result.Should().BeSameAs(value); }
public void Execute_should_return_expected_result( [Values(false, true)] bool async) { var keys = new BsonDocument("x", 1); var requests = new[] { new CreateIndexRequest(keys) }; var createIndexOperation = new CreateIndexesOperation(_collectionNamespace, requests, _messageEncoderSettings); ExecuteOperation(createIndexOperation, async); var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var result = ExecuteOperation(subject, async); result["ok"].ToBoolean().Should().BeTrue(); }
public void Execute_should_throw_when_binding_is_null( [Values(false, true)] bool async) { var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); Action action = () => ExecuteOperation(subject, null, async); var ex = action.ShouldThrow<ArgumentNullException>().Subject.Single(); ex.ParamName.Should().Be("binding"); }
public void Execute_should_return_expected_result( [Values(false, true)] bool async) { RequireServer.Check(); EnsureIndexExists(); var indexName = "x_1"; var subject = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings); var result = ExecuteOperation(subject, async); result["ok"].ToBoolean().Should().BeTrue(); }