Beispiel #1
0
// PreflightSchema is part of the tmclient.TabletManagerClient interface
func (client *Client) PreflightSchema(ctx context.Context, tablet *topo.TabletInfo, change string) (*myproto.SchemaChangeResult, error) {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return nil, err
	}
	defer cc.Close()
	response, err := c.PreflightSchema(ctx, &pb.PreflightSchemaRequest{
		Change: change,
	})
	if err != nil {
		return nil, err
	}
	return &myproto.SchemaChangeResult{
		BeforeSchema: myproto.ProtoToSchemaDefinition(response.BeforeSchema),
		AfterSchema:  myproto.ProtoToSchemaDefinition(response.AfterSchema),
	}, err
}
Beispiel #2
0
func (s *server) ApplySchema(ctx context.Context, request *pb.ApplySchemaRequest) (*pb.ApplySchemaResponse, error) {
	ctx = callinfo.GRPCCallInfo(ctx)
	response := &pb.ApplySchemaResponse{}
	return response, s.agent.RPCWrapLockAction(ctx, actionnode.TabletActionApplySchema, request, response, true, func() error {
		scr, err := s.agent.ApplySchema(ctx, &myproto.SchemaChange{
			Sql:              request.Sql,
			Force:            request.Force,
			AllowReplication: request.AllowReplication,
			BeforeSchema:     myproto.ProtoToSchemaDefinition(request.BeforeSchema),
			AfterSchema:      myproto.ProtoToSchemaDefinition(request.AfterSchema),
		})
		if err == nil {
			response.BeforeSchema = myproto.SchemaDefinitionToProto(scr.BeforeSchema)
			response.AfterSchema = myproto.SchemaDefinitionToProto(scr.AfterSchema)
		}
		return err
	})
}
Beispiel #3
0
// ApplySchema is part of the tmclient.TabletManagerClient interface
func (client *Client) ApplySchema(ctx context.Context, tablet *topo.TabletInfo, change *myproto.SchemaChange) (*myproto.SchemaChangeResult, error) {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return nil, err
	}
	defer cc.Close()
	response, err := c.ApplySchema(ctx, &pb.ApplySchemaRequest{
		Sql:              change.Sql,
		Force:            change.Force,
		AllowReplication: change.AllowReplication,
		BeforeSchema:     myproto.SchemaDefinitionToProto(change.BeforeSchema),
		AfterSchema:      myproto.SchemaDefinitionToProto(change.AfterSchema),
	})
	if err != nil {
		return nil, err
	}
	return &myproto.SchemaChangeResult{
		BeforeSchema: myproto.ProtoToSchemaDefinition(response.BeforeSchema),
		AfterSchema:  myproto.ProtoToSchemaDefinition(response.AfterSchema),
	}, nil
}
Beispiel #4
0
// GetSchema is part of the tmclient.TabletManagerClient interface
func (client *Client) GetSchema(ctx context.Context, tablet *topo.TabletInfo, tables, excludeTables []string, includeViews bool) (*myproto.SchemaDefinition, error) {
	cc, c, err := client.dial(ctx, tablet)
	if err != nil {
		return nil, err
	}
	defer cc.Close()
	response, err := c.GetSchema(ctx, &pb.GetSchemaRequest{
		Tables:        tables,
		ExcludeTables: excludeTables,
		IncludeViews:  includeViews,
	})
	if err != nil {
		return nil, err
	}
	return myproto.ProtoToSchemaDefinition(response.SchemaDefinition), nil
}