diff --git a/go/vt/schemadiff/schema.go b/go/vt/schemadiff/schema.go index 6608dcca942..762b45f2de1 100644 --- a/go/vt/schemadiff/schema.go +++ b/go/vt/schemadiff/schema.go @@ -70,10 +70,8 @@ func NewSchemaFromEntities(entities []Entity) (*Schema, error) { return nil, &UnsupportedEntityError{Entity: c.Name(), Statement: c.Create().CanonicalStatementString()} } } - if err := schema.normalize(); err != nil { - return schema, err - } - return schema, nil + err := schema.normalize() + return schema, err } // NewSchemaFromStatements creates a valid and normalized schema based on list of valid statements @@ -309,7 +307,7 @@ func (s *Schema) normalize() error { // - two or more views have a circular dependency for _, t := range s.tables { if _, ok := dependencyLevels[t.Name()]; !ok { - // We _know_ that in this iteration, at least one view is found unassigned a dependency level. + // We _know_ that in this iteration, at least one foreign key is not found. // We return the first one. return &ForeignKeyDependencyUnresolvedError{Table: t.Name()} } @@ -317,8 +315,10 @@ func (s *Schema) normalize() error { for _, v := range s.views { if _, ok := dependencyLevels[v.Name()]; !ok { // We _know_ that in this iteration, at least one view is found unassigned a dependency level. - // We return the first one. + // We gather all the errors. errs = errors.Join(errs, &ViewDependencyUnresolvedError{View: v.ViewName.Name.String()}) + // We still add it so it shows up in the output if that is used for anything. + s.sorted = append(s.sorted, v) } } } diff --git a/go/vt/schemadiff/schema_test.go b/go/vt/schemadiff/schema_test.go index 0601e8d11d7..a29195366b4 100644 --- a/go/vt/schemadiff/schema_test.go +++ b/go/vt/schemadiff/schema_test.go @@ -114,9 +114,12 @@ func TestNewSchemaFromQueriesUnresolved(t *testing.T) { queries := append(createQueries, "create view v7 as select * from v8, t2", ) - _, err := NewSchemaFromQueries(queries) + schema, err := NewSchemaFromQueries(queries) assert.Error(t, err) assert.EqualError(t, err, (&ViewDependencyUnresolvedError{View: "v7"}).Error()) + v := schema.sorted[len(schema.sorted)-1] + assert.IsType(t, &CreateViewEntity{}, v) + assert.Equal(t, "CREATE VIEW `v7` AS SELECT * FROM `v8`, `t2`", v.Create().CanonicalStatementString()) } func TestNewSchemaFromQueriesUnresolvedAlias(t *testing.T) {