vitess.io/vitess@v0.16.2/go/vt/schemadiff/types.go (about) 1 /* 2 Copyright 2022 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 schemadiff 18 19 import ( 20 "vitess.io/vitess/go/vt/sqlparser" 21 ) 22 23 // Entity stands for a database object we can diff: 24 // - A table 25 // - A view 26 type Entity interface { 27 // Name of entity, ie table name, view name, etc. 28 Name() string 29 // Diff returns an entitty diff given another entity. The diff direction is from this entity and to the other entity. 30 Diff(other Entity, hints *DiffHints) (diff EntityDiff, err error) 31 // Create returns an entity diff that describes how to create this entity 32 Create() EntityDiff 33 // Drop returns an entity diff that describes how to drop this entity 34 Drop() EntityDiff 35 // Clone returns a deep copy of the entity. 36 Clone() Entity 37 } 38 39 // EntityDiff represents the diff between two entities 40 type EntityDiff interface { 41 // IsEmpty returns true when the two entities are considered identical 42 IsEmpty() bool 43 // Entities returns the two diffed entitied, aka "from" and "to" 44 Entities() (from Entity, to Entity) 45 // Statement returns a valid SQL statement that applies the diff, e.g. an ALTER TABLE ... 46 // It returns nil if the diff is empty 47 Statement() sqlparser.Statement 48 // StatementString "stringifies" this diff's Statement(). It returns an empty string if the diff is empty 49 StatementString() string 50 // CanonicalStatementString "stringifies" this diff's Statement() to a canonical string. It returns an empty string if the diff is empty 51 CanonicalStatementString() string 52 // SubsequentDiff returns a followup diff to this one, if exists 53 SubsequentDiff() EntityDiff 54 // SetSubsequentDiff updates the existing subsequent diff to the given one 55 SetSubsequentDiff(EntityDiff) 56 } 57 58 const ( 59 AutoIncrementIgnore int = iota 60 AutoIncrementApplyHigher 61 AutoIncrementApplyAlways 62 ) 63 64 const ( 65 RangeRotationFullSpec = iota 66 RangeRotationDistinctStatements 67 RangeRotationIgnore 68 ) 69 70 const ( 71 ConstraintNamesIgnoreVitess = iota 72 ConstraintNamesIgnoreAll 73 ConstraintNamesStrict 74 ) 75 76 const ( 77 ColumnRenameAssumeDifferent = iota 78 ColumnRenameHeuristicStatement 79 ) 80 81 const ( 82 TableRenameAssumeDifferent = iota 83 TableRenameHeuristicStatement 84 ) 85 86 const ( 87 FullTextKeyDistinctStatements = iota 88 FullTextKeyUnifyStatements 89 ) 90 91 const ( 92 TableCharsetCollateStrict int = iota 93 TableCharsetCollateIgnoreEmpty 94 TableCharsetCollateIgnoreAlways 95 ) 96 97 const ( 98 AlterTableAlgorithmStrategyNone int = iota 99 AlterTableAlgorithmStrategyInstant 100 AlterTableAlgorithmStrategyInplace 101 AlterTableAlgorithmStrategyCopy 102 ) 103 104 // DiffHints is an assortment of rules for diffing entities 105 type DiffHints struct { 106 StrictIndexOrdering bool 107 AutoIncrementStrategy int 108 RangeRotationStrategy int 109 ConstraintNamesStrategy int 110 ColumnRenameStrategy int 111 TableRenameStrategy int 112 FullTextKeyStrategy int 113 TableCharsetCollateStrategy int 114 AlterTableAlgorithmStrategy int 115 }