github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/table_copy_tables_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"path"
    10  	"testing"
    11  
    12  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
    13  	"github.com/ydb-platform/ydb-go-sdk/v3/table"
    14  	"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
    15  )
    16  
    17  func TestCopyTables(t *testing.T) {
    18  	var (
    19  		ctx        = xtest.Context(t)
    20  		scope      = newScope(t)
    21  		db         = scope.Driver()
    22  		fromPath   = scope.TablePath()
    23  		dirPath, _ = path.Split(fromPath)
    24  		toPath     = path.Join(dirPath, "renamed")
    25  	)
    26  	// copy tables
    27  	err := db.Table().Do(ctx,
    28  		func(ctx context.Context, s table.Session) (err error) {
    29  			return s.CopyTables(ctx,
    30  				options.CopyTablesItem(
    31  					fromPath,
    32  					toPath,
    33  					true,
    34  				),
    35  			)
    36  		},
    37  		table.WithIdempotent(),
    38  	)
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	// describe table in destination path
    43  	err = db.Table().Do(ctx,
    44  		func(ctx context.Context, s table.Session) (err error) {
    45  			d, err := s.DescribeTable(ctx, toPath)
    46  			if err != nil {
    47  				return err
    48  			}
    49  			fmt.Printf("Table `%s`:\n", toPath)
    50  			for _, c := range d.Columns {
    51  				fmt.Printf(" - `%s` %s\n", c.Name, c.Type.Yql())
    52  			}
    53  			return nil
    54  		},
    55  		table.WithIdempotent(),
    56  	)
    57  	if err != nil {
    58  		t.Fatal(err)
    59  	}
    60  }