public override void Generate( DropDatabaseOperation dropDatabaseOperation, IndentedStringBuilder stringBuilder) { throw new NotSupportedException(Strings.FormatMigrationOperationNotSupported( GetType(), dropDatabaseOperation.GetType())); }
public void Create_and_initialize_operation() { var dropDatabaseOperation = new DropDatabaseOperation("MyDatabase"); Assert.Equal("MyDatabase", dropDatabaseOperation.DatabaseName); Assert.True(dropDatabaseOperation.IsDestructiveChange); }
public virtual void Generate( [NotNull] DropDatabaseOperation operation, [CanBeNull] IModel model, [NotNull] SqlBatchBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); var dbName = _sql.DelimitIdentifier(operation.Name); builder // TODO: The following revokes connection only for the public role, what about other connecting roles? .Append("REVOKE CONNECT ON DATABASE ") .Append(dbName) .Append(" FROM PUBLIC") .EndBatch() // TODO: For PG <= 9.1, the column name is prodpic, not pid (see http://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it) .Append( "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '") .Append(dbName) .Append("'") .EndBatch() .Append("DROP DATABASE ") .Append(dbName); }
public void constructor_should_initialize_subject() { var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings); subject.DatabaseNamespace.Should().BeSameAs(_databaseNamespace); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); }
// methods public Task DropAsync(TimeSpan?timeout, CancellationToken cancellationToken) { var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(_databaseNamespace, messageEncoderSettings); return(ExecuteWriteOperation(operation, timeout, cancellationToken)); }
private void ClearData(ICluster cluster) { using (var binding = new WritableServerBinding(cluster, NoCoreSession.NewHandle())) { var commandOp = new DropDatabaseOperation(_collection.DatabaseNamespace, _messageEncoderSettings); commandOp.Execute(binding, CancellationToken.None); } }
private async Task ClearData(ICluster cluster) { using (var binding = new WritableServerBinding(cluster)) { var commandOp = new DropDatabaseOperation(_collection.DatabaseNamespace, _messageEncoderSettings); await commandOp.ExecuteAsync(binding, CancellationToken.None); } }
public void Generate_with_drop_database_not_supported() { var operation = new DropDatabaseOperation("Bronies"); Assert.Equal( Strings.FormatMigrationOperationNotSupported(typeof(SQLiteMigrationOperationSqlGenerator), operation.GetType()), Assert.Throws <NotSupportedException>(() => Generate(operation)).Message); }
public virtual void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] IndentedStringBuilder stringBuilder, bool generateIdempotentSql) { Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation"); stringBuilder .Append("DROP DATABASE ") .Append(DelimitIdentifier(dropDatabaseOperation.DatabaseName)); }
private async static Task ClearData(ICluster cluster) { using (var binding = new WritableServerBinding(cluster)) { var commandOp = new DropDatabaseOperation(_database); await commandOp.ExecuteAsync(binding); } }
public virtual void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] SqlBatchBuilder batchBuilder) { Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation"); Check.NotNull(batchBuilder, "batchBuilder"); batchBuilder .Append("DROP DATABASE ") .Append(DelimitIdentifier(dropDatabaseOperation.DatabaseName)); }
// methods private void DropDatabase() { var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings); using (var binding = GetReadWriteBinding()) { operation.Execute(binding); } }
// methods private static void DropDatabase() { var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings); using (var binding = GetReadWriteBinding()) { operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult(); } }
/// <summary> /// Drops a database. /// </summary> /// <param name="databaseName">The name of the database to be dropped.</param> /// <returns>A <see cref="CommandResult"/>.</returns> public virtual CommandResult DropDatabase(string databaseName) { var databaseNamespace = new DatabaseNamespace(databaseName); var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(databaseNamespace, messageEncoderSettings); var response = ExecuteWriteOperation(operation); return(new CommandResult(response)); }
private static void DropDatabase() { var operation = new DropDatabaseOperation(__databaseNamespace.Value, __messageEncoderSettings); using (var session = StartSession()) using (var binding = CreateReadWriteBinding(session)) { operation.Execute(binding, CancellationToken.None); } }
// public methods /// <inheritdoc/> public sealed override async Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) { var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings); using (var binding = new WritableServerBinding(_cluster)) { await _operationExecutor.ExecuteWriteOperationAsync(binding, operation, cancellationToken).ConfigureAwait(false); } }
public void Dispatches_visitor() { var dropDatabaseOperation = new DropDatabaseOperation("MyDatabase"); var mockVisitor = new Mock <MigrationOperationSqlGenerator>(new RelationalTypeMapper()); var builder = new Mock <IndentedStringBuilder>(); dropDatabaseOperation.GenerateSql(mockVisitor.Object, builder.Object); mockVisitor.Verify(g => g.Generate(dropDatabaseOperation, builder.Object), Times.Once()); }
public override void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] IndentedStringBuilder stringBuilder) { Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation"); Check.NotNull(stringBuilder, "stringBuilder"); stringBuilder .Append("DropDatabase(") .Append(GenerateLiteral(dropDatabaseOperation.DatabaseName)) .Append(")"); }
public void Generate_when_drop_database_operation() { var operation = new DropDatabaseOperation("MyDatabase"); Assert.Equal( @"DropDatabase(""MyDatabase"")", CSharpMigrationCodeGenerator.Generate(operation)); GenerateAndValidateCode(operation); }
// public methods /// <inheritdoc/> public sealed override void DropDatabase(string name, CancellationToken cancellationToken = default(CancellationToken)) { var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings); using (var binding = new WritableServerBinding(_cluster)) { _operationExecutor.ExecuteWriteOperation(binding, operation, cancellationToken); } }
public void Dispatches_visitor() { var dropDatabaseOperation = new DropDatabaseOperation("MyDatabase"); var mockVisitor = MigrationsTestHelpers.MockSqlGenerator(); var builder = new Mock <SqlBatchBuilder>(); dropDatabaseOperation.GenerateSql(mockVisitor.Object, builder.Object); mockVisitor.Verify(g => g.Generate(dropDatabaseOperation, builder.Object), Times.Once()); }
private static void DropDatabase() { var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings); var session = CoreTestConfiguration.StartSession(); using (var binding = GetReadWriteBinding(session)) { operation.Execute(binding, CancellationToken.None); } }
/// <inheritdoc/> public sealed override Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(session, nameof(session)); var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings) { WriteConcern = _settings.WriteConcern }; return(ExecuteWriteOperationAsync(session, operation, cancellationToken)); }
private CommandResult DropDatabase(IClientSessionHandle session, string databaseName) { var databaseNamespace = new DatabaseNamespace(databaseName); var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(databaseNamespace, messageEncoderSettings) { WriteConcern = _settings.WriteConcern }; var response = ExecuteWriteOperation(session, operation); return(new CommandResult(response)); }
protected override void Given() { // Ensure database exists var op = new BulkInsertOperation( new CollectionNamespace(DatabaseNamespace, "temp"), new [] { new InsertRequest(new BsonDocument("x", 1)) }, MessageEncoderSettings); ExecuteOperation(op); _subject = new DropDatabaseOperation(DatabaseNamespace, MessageEncoderSettings); }
public void CreateCommand_should_return_expected_result() { var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings); var expectedResult = new BsonDocument { { "dropDatabase", 1 } }; var result = subject.CreateCommand(); result.Should().Be(expectedResult); }
private void DropDatabase() { var operation = new DropDatabaseOperation( new DatabaseNamespace(__databaseName), new MessageEncoderSettings()); using (var binding = new WritableServerBinding(__cluster)) { operation.ExecuteAsync(binding, TimeSpan.FromSeconds(10), CancellationToken.None) .GetAwaiter() .GetResult(); } }
public async Task ExecuteAsync_should_return_expected_result() { using (var binding = CoreTestConfiguration.GetReadWriteBinding()) { EnsureDatabaseExists(binding); var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings); var result = await subject.ExecuteAsync(binding, CancellationToken.None); result["ok"].ToBoolean().Should().BeTrue(); result["dropped"].ToString().Should().Be(_databaseNamespace.DatabaseName); } }
public virtual void Generate( [NotNull] DropDatabaseOperation operation, [CanBeNull] IModel model, [NotNull] SqlBatchBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("IF SERVERPROPERTY('EngineEdition') <> 5 EXECUTE sp_executesql N'ALTER DATABASE ") .Append(_sql.DelimitIdentifier(operation.Name)) .Append(" SET SINGLE_USER WITH ROLLBACK IMMEDIATE'") .EndBatch() .Append("DROP DATABASE ") .Append(_sql.DelimitIdentifier(operation.Name)); }
public override void Generate(DropDatabaseOperation dropDatabaseOperation, SqlBatchBuilder batchBuilder) { batchBuilder .Append("IF SERVERPROPERTY('EngineEdition') <> 5 EXECUTE sp_executesql N") .Append( GenerateLiteral( string.Concat( "ALTER DATABASE ", DelimitIdentifier(dropDatabaseOperation.DatabaseName), " SET SINGLE_USER WITH ROLLBACK IMMEDIATE"))); batchBuilder.EndBatch(); base.Generate(dropDatabaseOperation, batchBuilder); batchBuilder.EndBatch(); }
public override void Generate(DropDatabaseOperation dropDatabaseOperation, IndentedStringBuilder stringBuilder, bool generateIdempotentSql) { Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation"); Check.NotNull(stringBuilder, "stringBuilder"); if (generateIdempotentSql) { GenerateDatabasePresenceCheck(dropDatabaseOperation.DatabaseName, negative: false, builder: stringBuilder); using (stringBuilder.AppendLine().Indent()) { base.Generate(dropDatabaseOperation, stringBuilder, generateIdempotentSql: false); } } else { base.Generate(dropDatabaseOperation, stringBuilder, generateIdempotentSql); } }
public void ExecuteAsync_should_throw_when_binding_is_null() { var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings); Func<Task> action = () => subject.ExecuteAsync(null, CancellationToken.None); action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("binding"); }
public Task DropDatabaseAsync(IWriteBinding binding) { var operation = new DropDatabaseOperation(_collectionNamespace.DatabaseNamespace, _messageEncoderSettings); return operation.ExecuteAsync(binding, CancellationToken.None); }
public override void Generate( DropDatabaseOperation dropDatabaseOperation, IndentedStringBuilder stringBuilder) { throw new NotSupportedException(); }
public abstract void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] IndentedStringBuilder stringBuilder);
// public methods /// <inheritdoc/> public sealed override void DropDatabase(string name, CancellationToken cancellationToken = default(CancellationToken)) { var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings) { WriteConcern = _settings.WriteConcern }; using (var binding = new WritableServerBinding(_cluster)) { _operationExecutor.ExecuteWriteOperation(binding, operation, cancellationToken); } }
/// <inheritdoc/> public sealed override async Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) { var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings) { WriteConcern = _settings.WriteConcern }; using (var binding = new WritableServerBinding(_cluster)) { await _operationExecutor.ExecuteWriteOperationAsync(binding, operation, cancellationToken).ConfigureAwait(false); } }
public void DropDatabase(bool async) { var operation = new DropDatabaseOperation(_collectionNamespace.DatabaseNamespace, _messageEncoderSettings); ExecuteOperation(operation, async); }
public void MessageEncoderSettings_get_should_return_expected_result() { var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings); var result = subject.MessageEncoderSettings; result.Should().BeSameAs(_messageEncoderSettings); }