vitess.io/vitess@v0.16.2/go/cmd/vtcombo/plugin_dbddl.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"context"
    21  
    22  	"vitess.io/vitess/go/vt/servenv"
    23  	"vitess.io/vitess/go/vt/vtgate/engine"
    24  
    25  	vttestpb "vitess.io/vitess/go/vt/proto/vttest"
    26  )
    27  
    28  var globalCreateDb func(ctx context.Context, ks *vttestpb.Keyspace) error
    29  var globalDropDb func(ctx context.Context, ksName string) error
    30  
    31  // DBDDL doesn't need to store any state - we use the global variables above instead
    32  type DBDDL struct{}
    33  
    34  // CreateDatabase implements the engine.DBDDLPlugin interface
    35  func (plugin *DBDDL) CreateDatabase(ctx context.Context, name string) error {
    36  	ks := &vttestpb.Keyspace{
    37  		Name: name,
    38  		Shards: []*vttestpb.Shard{{
    39  			Name: "0",
    40  		}},
    41  	}
    42  	return globalCreateDb(ctx, ks)
    43  }
    44  
    45  // DropDatabase implements the engine.DBDDLPlugin interface
    46  func (plugin *DBDDL) DropDatabase(ctx context.Context, name string) error {
    47  	return globalDropDb(ctx, name)
    48  }
    49  
    50  func init() {
    51  	servenv.OnRun(func() {
    52  		engine.DBDDLRegister("vttest", &DBDDL{})
    53  	})
    54  }