-
Notifications
You must be signed in to change notification settings - Fork 2k
/
errors.go
478 lines (385 loc) · 13.5 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/*
Copyright 2023 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package schemadiff
import (
"errors"
"fmt"
"strings"
"vitess.io/vitess/go/sqlescape"
)
var (
ErrEntityTypeMismatch = errors.New("mismatched entity type")
ErrStrictIndexOrderingUnsupported = errors.New("strict index ordering is unsupported")
ErrUnexpectedDiffAction = errors.New("unexpected diff action")
ErrUnexpectedTableSpec = errors.New("unexpected table spec")
ErrExpectedCreateTable = errors.New("expected a CREATE TABLE statement")
ErrExpectedCreateView = errors.New("expected a CREATE VIEW statement")
)
type ImpossibleApplyDiffOrderError struct {
UnorderedDiffs []EntityDiff
ConflictingDiffs []EntityDiff
}
func (e *ImpossibleApplyDiffOrderError) Error() string {
var b strings.Builder
conflictingStatements := e.ConflictingStatements()
b.WriteString(fmt.Sprintf("no valid applicable order for diffs. %d diffs found conflicting:", len(conflictingStatements)))
for _, s := range conflictingStatements {
b.WriteString("\n")
b.WriteString(s)
}
return b.String()
}
func (e *ImpossibleApplyDiffOrderError) ConflictingStatements() (result []string) {
for _, diff := range e.ConflictingDiffs {
result = append(result, diff.CanonicalStatementString())
}
return result
}
type UnsupportedEntityError struct {
Entity string
Statement string
}
func (e *UnsupportedEntityError) Error() string {
return fmt.Sprintf("entity %s is not supported: %s", sqlescape.EscapeID(e.Entity), e.Statement)
}
type NotFullyParsedError struct {
Entity string
Statement string
}
func (e *NotFullyParsedError) Error() string {
return fmt.Sprintf("entity %s is not fully parsed: %s", sqlescape.EscapeID(e.Entity), e.Statement)
}
type UnsupportedTableOptionError struct {
Table string
Option string
}
func (e *UnsupportedTableOptionError) Error() string {
return fmt.Sprintf("unsupported option %s on table %s", e.Option, sqlescape.EscapeID(e.Table))
}
type UnsupportedStatementError struct {
Statement string
}
func (e *UnsupportedStatementError) Error() string {
return fmt.Sprintf("unsupported statement: %s", e.Statement)
}
type UnsupportedApplyOperationError struct {
Statement string
}
func (e *UnsupportedApplyOperationError) Error() string {
return fmt.Sprintf("unsupported operation: %s", e.Statement)
}
type ApplyTableNotFoundError struct {
Table string
}
func (e *ApplyTableNotFoundError) Error() string {
return fmt.Sprintf("table %s not found", sqlescape.EscapeID(e.Table))
}
type ApplyViewNotFoundError struct {
View string
}
func (e *ApplyViewNotFoundError) Error() string {
return fmt.Sprintf("view %s not found", sqlescape.EscapeID(e.View))
}
type ApplyKeyNotFoundError struct {
Table string
Key string
}
func (e *ApplyKeyNotFoundError) Error() string {
return fmt.Sprintf("key %s not found in table %s", sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
}
type ApplyColumnNotFoundError struct {
Table string
Column string
}
func (e *ApplyColumnNotFoundError) Error() string {
return fmt.Sprintf("column %s not found in table %s", sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Table))
}
type ApplyColumnAfterNotFoundError struct {
Table string
Column string
AfterColumn string
}
func (e *ApplyColumnAfterNotFoundError) Error() string {
return fmt.Sprintf("column %s can't be after non-existing column %s in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.AfterColumn), sqlescape.EscapeID(e.Table))
}
type ApplyDuplicateEntityError struct {
Entity string
}
func (e *ApplyDuplicateEntityError) Error() string {
return fmt.Sprintf("duplicate entity %s", sqlescape.EscapeID(e.Entity))
}
type ApplyDuplicateKeyError struct {
Table string
Key string
}
func (e *ApplyDuplicateKeyError) Error() string {
return fmt.Sprintf("duplicate key %s in table %s", sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
}
type ApplyDuplicateColumnError struct {
Table string
Column string
}
func (e *ApplyDuplicateColumnError) Error() string {
return fmt.Sprintf("duplicate column %s in table %s", sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Table))
}
type ApplyConstraintNotFoundError struct {
Table string
Constraint string
}
func (e *ApplyConstraintNotFoundError) Error() string {
return fmt.Sprintf("constraint %s not found in table %s", sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
}
type ApplyDuplicateConstraintError struct {
Table string
Constraint string
}
func (e *ApplyDuplicateConstraintError) Error() string {
return fmt.Sprintf("duplicate constraint %s in table %s", sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
}
type ApplyPartitionNotFoundError struct {
Table string
Partition string
}
func (e *ApplyPartitionNotFoundError) Error() string {
return fmt.Sprintf("partition %s not found in table %s", sqlescape.EscapeID(e.Partition), sqlescape.EscapeID(e.Table))
}
type ApplyDuplicatePartitionError struct {
Table string
Partition string
}
func (e *ApplyDuplicatePartitionError) Error() string {
return fmt.Sprintf("duplicate partition %s in table %s", sqlescape.EscapeID(e.Partition), sqlescape.EscapeID(e.Table))
}
type ApplyNoPartitionsError struct {
Table string
}
func (e *ApplyNoPartitionsError) Error() string {
return fmt.Sprintf("no partitions in table %s", sqlescape.EscapeID(e.Table))
}
type InvalidColumnInKeyError struct {
Table string
Column string
Key string
}
type DuplicateKeyNameError struct {
Table string
Key string
}
func (e *DuplicateKeyNameError) Error() string {
return fmt.Sprintf("duplicate key %s in table %s", sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
}
func (e *InvalidColumnInKeyError) Error() string {
return fmt.Sprintf("invalid column %s referenced by key %s in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Key), sqlescape.EscapeID(e.Table))
}
type InvalidColumnInGeneratedColumnError struct {
Table string
Column string
GeneratedColumn string
}
func (e *InvalidColumnInGeneratedColumnError) Error() string {
return fmt.Sprintf("invalid column %s referenced by generated column %s in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.GeneratedColumn), sqlescape.EscapeID(e.Table))
}
type InvalidColumnInPartitionError struct {
Table string
Column string
}
func (e *InvalidColumnInPartitionError) Error() string {
return fmt.Sprintf("invalid column %s referenced by partition in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Table))
}
type MissingPartitionColumnInUniqueKeyError struct {
Table string
Column string
UniqueKey string
}
func (e *MissingPartitionColumnInUniqueKeyError) Error() string {
return fmt.Sprintf("invalid column %s referenced by unique key %s in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.UniqueKey), sqlescape.EscapeID(e.Table))
}
type InvalidColumnInCheckConstraintError struct {
Table string
Constraint string
Column string
}
func (e *InvalidColumnInCheckConstraintError) Error() string {
return fmt.Sprintf("invalid column %s referenced by check constraint %s in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
}
type ForeignKeyDependencyUnresolvedError struct {
Table string
}
func (e *ForeignKeyDependencyUnresolvedError) Error() string {
return fmt.Sprintf("table %s has unresolved foreign key dependencies",
sqlescape.EscapeID(e.Table))
}
type ForeignKeyLoopError struct {
Table string
Loop []string
}
func (e *ForeignKeyLoopError) Error() string {
tableIsInsideLoop := false
escaped := make([]string, len(e.Loop))
for i, t := range e.Loop {
escaped[i] = sqlescape.EscapeID(t)
if t == e.Table {
tableIsInsideLoop = true
}
}
if tableIsInsideLoop {
return fmt.Sprintf("table %s participates in a circular foreign key reference: %s",
sqlescape.EscapeID(e.Table), strings.Join(escaped, ", "))
}
return fmt.Sprintf("table %s references a circular foreign key reference: %s",
sqlescape.EscapeID(e.Table), strings.Join(escaped, ", "))
}
type ForeignKeyNonexistentReferencedTableError struct {
Table string
ReferencedTable string
}
func (e *ForeignKeyNonexistentReferencedTableError) Error() string {
return fmt.Sprintf("table %s foreign key references nonexistent table %s",
sqlescape.EscapeID(e.Table), sqlescape.EscapeID(e.ReferencedTable))
}
type ForeignKeyReferencesViewError struct {
Table string
ReferencedView string
}
func (e *ForeignKeyReferencesViewError) Error() string {
return fmt.Sprintf("table %s foreign key references view %s",
sqlescape.EscapeID(e.Table), sqlescape.EscapeID(e.ReferencedView))
}
type InvalidColumnInForeignKeyConstraintError struct {
Table string
Constraint string
Column string
}
func (e *InvalidColumnInForeignKeyConstraintError) Error() string {
return fmt.Sprintf("invalid column %s covered by foreign key constraint %s in table %s",
sqlescape.EscapeID(e.Column), sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
}
type InvalidReferencedColumnInForeignKeyConstraintError struct {
Table string
Constraint string
ReferencedTable string
ReferencedColumn string
}
func (e *InvalidReferencedColumnInForeignKeyConstraintError) Error() string {
return fmt.Sprintf("invalid column %s.%s referenced by foreign key constraint %s in table %s",
sqlescape.EscapeID(e.ReferencedTable), sqlescape.EscapeID(e.ReferencedColumn), sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table))
}
type ForeignKeyColumnCountMismatchError struct {
Table string
Constraint string
ColumnCount int
ReferencedTable string
ReferencedColumnCount int
}
func (e *ForeignKeyColumnCountMismatchError) Error() string {
return fmt.Sprintf("mismatching column count %d referenced by foreign key constraint %s in table %s. Expected %d",
e.ReferencedColumnCount, sqlescape.EscapeID(e.Constraint), sqlescape.EscapeID(e.Table), e.ColumnCount)
}
type ForeignKeyColumnTypeMismatchError struct {
Table string
Constraint string
Column string
ReferencedTable string
ReferencedColumn string
}
func (e *ForeignKeyColumnTypeMismatchError) Error() string {
return fmt.Sprintf("mismatching column type %s.%s and %s.%s referenced by foreign key constraint %s in table %s",
sqlescape.EscapeID(e.ReferencedTable),
sqlescape.EscapeID(e.ReferencedColumn),
sqlescape.EscapeID(e.Table),
sqlescape.EscapeID(e.Column),
sqlescape.EscapeID(e.Constraint),
sqlescape.EscapeID(e.Table),
)
}
type MissingForeignKeyReferencedIndexError struct {
Table string
Constraint string
ReferencedTable string
}
func (e *MissingForeignKeyReferencedIndexError) Error() string {
return fmt.Sprintf("missing index in referenced table %s for foreign key constraint %s in table %s",
sqlescape.EscapeID(e.ReferencedTable),
sqlescape.EscapeID(e.Constraint),
sqlescape.EscapeID(e.Table),
)
}
type IndexNeededByForeignKeyError struct {
Table string
Key string
}
func (e *IndexNeededByForeignKeyError) Error() string {
return fmt.Sprintf("key %s needed by a foreign key constraint in table %s",
sqlescape.EscapeID(e.Key),
sqlescape.EscapeID(e.Table),
)
}
type ViewDependencyUnresolvedError struct {
View string
}
func (e *ViewDependencyUnresolvedError) Error() string {
return fmt.Sprintf("view %s has unresolved/loop dependencies", sqlescape.EscapeID(e.View))
}
type InvalidColumnReferencedInViewError struct {
View string
Column string
Ambiguous bool
}
func (e *InvalidColumnReferencedInViewError) Error() string {
if e.Ambiguous {
return fmt.Sprintf("view %s references unqualified but non unique column %s", sqlescape.EscapeID(e.View), sqlescape.EscapeID(e.Column))
}
return fmt.Sprintf("view %s references unqualified but non-existent column %s", sqlescape.EscapeID(e.View), sqlescape.EscapeID(e.Column))
}
type InvalidStarExprInViewError struct {
View string
}
func (e *InvalidStarExprInViewError) Error() string {
return fmt.Sprintf("view %s has invalid star expression", sqlescape.EscapeID(e.View))
}
type EntityNotFoundError struct {
Name string
}
func (e *EntityNotFoundError) Error() string {
return fmt.Sprintf("entity %s not found", sqlescape.EscapeID(e.Name))
}
type EnumValueOrdinalChangedError struct {
Table string
Column string
Value string
Ordinal int
NewOrdinal int
}
func (e *EnumValueOrdinalChangedError) Error() string {
return fmt.Sprintf("ordinal of %s changed in enum or set column %s.%s, from %d to %d", e.Value, sqlescape.EscapeID(e.Table), sqlescape.EscapeID(e.Column), e.Ordinal, e.NewOrdinal)
}
type UnknownColumnCharsetCollationError struct {
Column string
Charset string
}
func (e *UnknownColumnCharsetCollationError) Error() string {
return fmt.Sprintf("unable to determine collation for column %s with charset %q", sqlescape.EscapeID(e.Column), e.Charset)
}
type UnknownColumnCollationCharsetError struct {
Column string
Collation string
}
func (e *UnknownColumnCollationCharsetError) Error() string {
return fmt.Sprintf("unable to determine charset for column %s with collation %q", sqlescape.EscapeID(e.Column), e.Collation)
}