Created
December 2, 2019 08:00
-
-
Save beeender/97c2fc55f9b82434595c6882ec0f2f22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Conn struct { | |
dbconn *dbconn.DBConn | |
} | |
type ConnPair struct { | |
src *Conn | |
dest *Conn | |
} | |
type ConnInfo struct { | |
host string | |
port int | |
user string | |
} | |
type ConnActions interface { | |
CreateSchema(ctx context.Context, name string) | |
} | |
func WithWorkerID(parent context.Context, workerID int) context.Context { | |
return context.WithValue(parent, "wokerid", workerID) | |
} | |
func MakeConn(info *ConnInfo, dbName string) *Conn { | |
conn := utils.NewDBConn(dbName, info.host, info.port, info.user) | |
return &Conn{dbconn: conn} | |
} | |
func MakeConnPair(srcInfo *ConnInfo, srcDb string, destInfo *ConnInfo, destDb string) *ConnPair { | |
s := MakeConn(srcInfo, srcDb) | |
d := MakeConn(destInfo, destDb) | |
return &ConnPair{src: s, dest: d} | |
} | |
func (conn *Conn) CreateSchema(ctx context.Context, name string) { | |
workerID := ctx.Value("workerid").(int) | |
query := fmt.Sprintf("CREATE SCHEMA \"%s\"", utils.QuoteIdent(name)) | |
gplog.Info("Creating schema \"%s\"", name) | |
conn.dbconn.MustExec(query, workerID) | |
} | |
func doCopy(workerID int) { | |
ctx := context.Background() | |
ctx = WithWorkerID(ctx, workerID) | |
connPair := MakeConnPair(nil, "srcDb", nil, "descDb") | |
connPair.src.CreateSchema(ctx, "newSchema") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment