vitess.io/vitess@v0.16.2/go/vt/vtgate/engine/dbddl_plugin.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 engine
    18  
    19  import (
    20  	"context"
    21  
    22  	"vitess.io/vitess/go/vt/vterrors"
    23  )
    24  
    25  type failDBDDL struct{}
    26  
    27  // CreateDatabase implements the DropCreateDB interface
    28  func (failDBDDL) CreateDatabase(context.Context, string) error {
    29  	return vterrors.VT12001("create database by failDBDDL")
    30  }
    31  
    32  // DropDatabase implements the DropCreateDB interface
    33  func (failDBDDL) DropDatabase(context.Context, string) error {
    34  	return vterrors.VT12001("drop database by failDBDDL")
    35  }
    36  
    37  type noOp struct{}
    38  
    39  // CreateDatabase implements the DropCreateDB interface
    40  func (noOp) CreateDatabase(context.Context, string) error {
    41  	return nil
    42  }
    43  
    44  // DropDatabase implements the DropCreateDB interface
    45  func (noOp) DropDatabase(context.Context, string) error {
    46  	return nil
    47  }
    48  
    49  const (
    50  	faildbDDL          = "fail"
    51  	noOpdbDDL          = "noop"
    52  	defaultDBDDLPlugin = faildbDDL
    53  )
    54  
    55  func init() {
    56  	DBDDLRegister(faildbDDL, failDBDDL{})
    57  	DBDDLRegister(noOpdbDDL, noOp{})
    58  }