github.com/blend/go-sdk@v1.20220411.3/testutil/drop_test_database.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package testutil
     9  
    10  import (
    11  	"context"
    12  	"fmt"
    13  
    14  	"github.com/blend/go-sdk/db"
    15  
    16  	"github.com/blend/go-sdk/db/dbutil"
    17  )
    18  
    19  // DropTestDatabase drops a database.
    20  func DropTestDatabase(ctx context.Context, conn *db.Connection, opts ...db.Option) (err error) {
    21  	var mgmt *db.Connection
    22  	defer func() {
    23  		err = db.PoolCloseFinalizer(mgmt, err)
    24  	}()
    25  
    26  	config, err := conn.Config.Reparse()
    27  	if err != nil {
    28  		return
    29  	}
    30  
    31  	mgmt, err = dbutil.OpenManagementConnection(opts...)
    32  	if err != nil {
    33  		return
    34  	}
    35  
    36  	_, err = mgmt.ExecContext(ctx, fmt.Sprintf("DROP DATABASE %s", config.Database))
    37  	return
    38  }