vitess.io/vitess@v0.16.2/go/vt/schemadiff/errors.go (about)

     1  package schemadiff
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"vitess.io/vitess/go/sqlescape"
     8  )
     9  
    10  var (
    11  	ErrEntityTypeMismatch             = errors.New("mismatched entity type")
    12  	ErrStrictIndexOrderingUnsupported = errors.New("strict index ordering is unsupported")
    13  	ErrUnexpectedDiffAction           = errors.New("unexpected diff action")
    14  	ErrUnexpectedTableSpec            = errors.New("unexpected table spec")
    15  	ErrExpectedCreateTable            = errors.New("expected a CREATE TABLE statement")
    16  	ErrExpectedCreateView             = errors.New("expected a CREATE VIEW statement")
    17  )
    18  
    19  type UnsupportedEntityError struct {
    20  	Entity    string
    21  	Statement string
    22  }
    23  
    24  func (e *UnsupportedEntityError) Error() string {
    25  	return fmt.Sprintf("entity %s is not supported: %s", sqlescape.EscapeID(e.Entity), e.Statement)
    26  }
    27  
    28  type NotFullyParsedError struct {
    29  	Entity    string
    30  	Statement string
    31  }
    32  
    33  func (e *NotFullyParsedError) Error() string {
    34  	return fmt.Sprintf("entity %s is not fully parsed: %s", sqlescape.EscapeID(e.Entity), e.Statement)
    35  }
    36  
    37  type UnsupportedTableOptionError struct {
    38  	Table  string
    39  	Option string
    40  }
    41  
    42  func (e *UnsupportedTableOptionError) Error() string {
    43  	return fmt.Sprintf("unsupported option %s on table %s", e.Option, sqlescape.EscapeID(e.Table))
    44  }
    45  
    46  type UnsupportedStatementError struct {
    47  	Statement string
    48  }
    49  
    50  func (e *UnsupportedStatementError) Error() string {
    51  	return fmt.Sprintf("unsupported statement: %s", e.Statement)
    52  }
    53  
    54  type UnsupportedApplyOperationError struct {
    55  	Statement string
    56  }
    57  
    58  func (e *UnsupportedApplyOperationError) Error() string {
    59  	return fmt.Sprintf("unsupported operation: %s", e.Statement)
    60  }
    61  
    62  type ApplyTableNotFoundError struct {
    63  	Table string
    64  }
    65  
    66  func (e *ApplyTableNotFoundError) Error() string {
    67  	return fmt.Sprintf("table %s not found", sqlescape.EscapeID(e.Table))
    68  }
    69  
    70  type ApplyViewNotFoundError struct {
    71  	View string
    72  }
    73  
    74  func (e *ApplyViewNotFoundError) Error() string {
    75  	return fmt.Sprintf("view %s not found", sqlescape.EscapeID(e.View))
    76  }
    77  
    78  type ApplyKeyNotFoundError struct {
    79  	Table string
    80  	Key   string
    81  }
    82  
    83  func (e *ApplyKeyNotFoundError) Error() string {
    84  	return fmt.Sprintf("key %s not found in table %s", sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
    85  }
    86  
    87  type ApplyColumnNotFoundError struct {
    88  	Table  string
    89  	Column string
    90  }
    91  
    92  func (e *ApplyColumnNotFoundError) Error() string {
    93  	return fmt.Sprintf("column %s not found in table %s", sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Table))
    94  }
    95  
    96  type ApplyColumnAfterNotFoundError struct {
    97  	Table       string
    98  	Column      string
    99  	AfterColumn string
   100  }
   101  
   102  func (e *ApplyColumnAfterNotFoundError) Error() string {
   103  	return fmt.Sprintf("column %s can't be after non-existing column %s in table %s",
   104  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.AfterColumn), sqlescape.EscapeID(e.Table))
   105  }
   106  
   107  type ApplyDuplicateEntityError struct {
   108  	Entity string
   109  }
   110  
   111  func (e *ApplyDuplicateEntityError) Error() string {
   112  	return fmt.Sprintf("duplicate entity %s", sqlescape.EscapeID(e.Entity))
   113  }
   114  
   115  type ApplyDuplicateKeyError struct {
   116  	Table string
   117  	Key   string
   118  }
   119  
   120  func (e *ApplyDuplicateKeyError) Error() string {
   121  	return fmt.Sprintf("duplicate key %s in table %s", sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
   122  }
   123  
   124  type ApplyDuplicateColumnError struct {
   125  	Table  string
   126  	Column string
   127  }
   128  
   129  func (e *ApplyDuplicateColumnError) Error() string {
   130  	return fmt.Sprintf("duplicate column %s in table %s", sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Table))
   131  }
   132  
   133  type ApplyConstraintNotFoundError struct {
   134  	Table      string
   135  	Constraint string
   136  }
   137  
   138  func (e *ApplyConstraintNotFoundError) Error() string {
   139  	return fmt.Sprintf("constraint %s not found in table %s", sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
   140  }
   141  
   142  type ApplyDuplicateConstraintError struct {
   143  	Table      string
   144  	Constraint string
   145  }
   146  
   147  func (e *ApplyDuplicateConstraintError) Error() string {
   148  	return fmt.Sprintf("duplicate constraint %s in table %s", sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
   149  }
   150  
   151  type ApplyPartitionNotFoundError struct {
   152  	Table     string
   153  	Partition string
   154  }
   155  
   156  func (e *ApplyPartitionNotFoundError) Error() string {
   157  	return fmt.Sprintf("partition %s not found in table %s", sqlescape.EscapeID(e.Partition), sqlescape.EscapeID(e.Table))
   158  }
   159  
   160  type ApplyDuplicatePartitionError struct {
   161  	Table     string
   162  	Partition string
   163  }
   164  
   165  func (e *ApplyDuplicatePartitionError) Error() string {
   166  	return fmt.Sprintf("duplicate partition %s in table %s", sqlescape.EscapeID(e.Partition), sqlescape.EscapeID(e.Table))
   167  }
   168  
   169  type ApplyNoPartitionsError struct {
   170  	Table string
   171  }
   172  
   173  func (e *ApplyNoPartitionsError) Error() string {
   174  	return fmt.Sprintf("no partitions in table %s", sqlescape.EscapeID(e.Table))
   175  }
   176  
   177  type InvalidColumnInKeyError struct {
   178  	Table  string
   179  	Column string
   180  	Key    string
   181  }
   182  
   183  type DuplicateKeyNameError struct {
   184  	Table string
   185  	Key   string
   186  }
   187  
   188  func (e *DuplicateKeyNameError) Error() string {
   189  	return fmt.Sprintf("duplicate key %s in table %s", sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
   190  }
   191  
   192  func (e *InvalidColumnInKeyError) Error() string {
   193  	return fmt.Sprintf("invalid column %s referenced by key %s in table %s",
   194  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
   195  }
   196  
   197  type InvalidColumnInGeneratedColumnError struct {
   198  	Table           string
   199  	Column          string
   200  	GeneratedColumn string
   201  }
   202  
   203  func (e *InvalidColumnInGeneratedColumnError) Error() string {
   204  	return fmt.Sprintf("invalid column %s referenced by generated column %s in table %s",
   205  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.GeneratedColumn), sqlescape.EscapeID(e.Table))
   206  }
   207  
   208  type InvalidColumnInPartitionError struct {
   209  	Table  string
   210  	Column string
   211  }
   212  
   213  func (e *InvalidColumnInPartitionError) Error() string {
   214  	return fmt.Sprintf("invalid column %s referenced by partition in table %s",
   215  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Table))
   216  }
   217  
   218  type MissingPartitionColumnInUniqueKeyError struct {
   219  	Table     string
   220  	Column    string
   221  	UniqueKey string
   222  }
   223  
   224  func (e *MissingPartitionColumnInUniqueKeyError) Error() string {
   225  	return fmt.Sprintf("invalid column %s referenced by unique key %s in table %s",
   226  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.UniqueKey), sqlescape.EscapeID(e.Table))
   227  }
   228  
   229  type InvalidColumnInCheckConstraintError struct {
   230  	Table      string
   231  	Constraint string
   232  	Column     string
   233  }
   234  
   235  func (e *InvalidColumnInCheckConstraintError) Error() string {
   236  	return fmt.Sprintf("invalid column %s referenced by check constraint %s in table %s",
   237  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
   238  }
   239  
   240  type ForeignKeyDependencyUnresolvedError struct {
   241  	Table string
   242  }
   243  
   244  func (e *ForeignKeyDependencyUnresolvedError) Error() string {
   245  	return fmt.Sprintf("table %s has unresolved/loop foreign key dependencies",
   246  		sqlescape.EscapeID(e.Table))
   247  }
   248  
   249  type InvalidColumnInForeignKeyConstraintError struct {
   250  	Table      string
   251  	Constraint string
   252  	Column     string
   253  }
   254  
   255  func (e *InvalidColumnInForeignKeyConstraintError) Error() string {
   256  	return fmt.Sprintf("invalid column %s covered by foreign key constraint %s in table %s",
   257  		sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
   258  }
   259  
   260  type InvalidReferencedColumnInForeignKeyConstraintError struct {
   261  	Table            string
   262  	Constraint       string
   263  	ReferencedTable  string
   264  	ReferencedColumn string
   265  }
   266  
   267  func (e *InvalidReferencedColumnInForeignKeyConstraintError) Error() string {
   268  	return fmt.Sprintf("invalid column %s.%s referenced by foreign key constraint %s in table %s",
   269  		sqlescape.EscapeID(e.ReferencedTable), sqlescape.EscapeID(e.ReferencedColumn), sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
   270  }
   271  
   272  type ForeignKeyColumnCountMismatchError struct {
   273  	Table                 string
   274  	Constraint            string
   275  	ColumnCount           int
   276  	ReferencedTable       string
   277  	ReferencedColumnCount int
   278  }
   279  
   280  func (e *ForeignKeyColumnCountMismatchError) Error() string {
   281  	return fmt.Sprintf("mismatching column count %d referenced by foreign key constraint %s in table %s. Expected %d",
   282  		e.ReferencedColumnCount, sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table), e.ColumnCount)
   283  }
   284  
   285  type ForeignKeyColumnTypeMismatchError struct {
   286  	Table            string
   287  	Constraint       string
   288  	Column           string
   289  	ReferencedTable  string
   290  	ReferencedColumn string
   291  }
   292  
   293  func (e *ForeignKeyColumnTypeMismatchError) Error() string {
   294  	return fmt.Sprintf("mismatching column type %s.%s and %s.%s referenced by foreign key constraint %s in table %s",
   295  		sqlescape.EscapeID(e.ReferencedTable),
   296  		sqlescape.EscapeID(e.ReferencedColumn),
   297  		sqlescape.EscapeID(e.Table),
   298  		sqlescape.EscapeID(e.Column),
   299  		sqlescape.EscapeID(e.Constraint),
   300  		sqlescape.EscapeID(e.Table),
   301  	)
   302  }
   303  
   304  type MissingForeignKeyReferencedIndexError struct {
   305  	Table           string
   306  	Constraint      string
   307  	ReferencedTable string
   308  }
   309  
   310  func (e *MissingForeignKeyReferencedIndexError) Error() string {
   311  	return fmt.Sprintf("missing index in referenced table %s for foreign key constraint %s in table %s",
   312  		sqlescape.EscapeID(e.ReferencedTable),
   313  		sqlescape.EscapeID(e.Constraint),
   314  		sqlescape.EscapeID(e.Table),
   315  	)
   316  }
   317  
   318  type IndexNeededByForeignKeyError struct {
   319  	Table string
   320  	Key   string
   321  }
   322  
   323  func (e *IndexNeededByForeignKeyError) Error() string {
   324  	return fmt.Sprintf("key %s needed by a foreign key constraint in table %s",
   325  		sqlescape.EscapeID(e.Key),
   326  		sqlescape.EscapeID(e.Table),
   327  	)
   328  }
   329  
   330  type ViewDependencyUnresolvedError struct {
   331  	View string
   332  }
   333  
   334  func (e *ViewDependencyUnresolvedError) Error() string {
   335  	return fmt.Sprintf("view %s has unresolved/loop dependencies", sqlescape.EscapeID(e.View))
   336  }