Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(walk-through): ignore view for pg alter table (#14937)
rebelicedbbe431f605d
diff --git a/backend/plugin/advisor/catalog/walk_through.go b/backend/plugin/advisor/catalog/walk_through.goindex 68baec4469..f935945287 100644--- a/backend/plugin/advisor/catalog/walk_through.go+++ b/backend/plugin/advisor/catalog/walk_through.go@@ -60,6 +60,8 @@ const (ErrorTypeTableIsReferencedByView = 304// ErrorTypeViewNotExists is the error that view not exists.ErrorTypeViewNotExists = 305+ // ErrorTypeViewExists is the error that view exists.+ ErrorTypeViewExists = 306// 401 ~ 499 column error type.diff --git a/backend/plugin/advisor/catalog/walk_through_for_pg.go b/backend/plugin/advisor/catalog/walk_through_for_pg.goindex 4ec7c0b324..0ecca71e7d 100644--- a/backend/plugin/advisor/catalog/walk_through_for_pg.go+++ b/backend/plugin/advisor/catalog/walk_through_for_pg.go@@ -50,6 +50,8 @@ func (d *DatabaseState) pgChangeState(in ast.Node) (err *WalkThroughError) {return d.pgCreateTable(node)case *ast.CreateIndexStmt:return d.pgCreateIndex(node)+ case *ast.CreateViewStmt:+ return d.pgCreateView(node)case *ast.AlterTableStmt:return d.pgAlterTable(node)case *ast.RenameIndexStmt:@@ -288,7 +290,12 @@ func (d *DatabaseState) pgAlterTable(node *ast.AlterTableStmt) *WalkThroughError}table, err := schema.pgGetTable(node.Table.Name)if err != nil {- return err+ _, err := schema.pgGetView(node.Table.Name)+ if err != nil {+ return err+ }+ // Do nothing for view.+ return nil}for _, item := range node.AlterItemList {@@ -601,6 +608,32 @@ func (d *DatabaseState) pgCreateIndex(node *ast.CreateIndexStmt) *WalkThroughErrreturn schema.pgCreateIndex(node, false /* isPrimary */, false /* isConstraint */)}+func (d *DatabaseState) pgCreateView(node *ast.CreateViewStmt) *WalkThroughError {+ if node.Name.Database != "" && d.name != node.Name.Database {+ return &WalkThroughError{+ Type: ErrorTypeAccessOtherDatabase,+ Content: fmt.Sprintf("Database %q is not the current database %q", node.Name.Database, d.name),+ }+ }++ schema, err := d.getSchema(node.Name.Schema)+ if err != nil {+ return err+ }++ if _, exists := schema.viewSet[node.Name.Name]; exists {+ // TODO: currently we don't check views.+ return nil+ }++ view := &ViewState{+ name: node.Name.Name,+ }+ schema.viewSet[view.name] = view++ return nil+}+func (d *DatabaseState) pgCreateTable(node *ast.CreateTableStmt) *WalkThroughError {if node.Name.Database != "" && d.name != node.Name.Database {return &WalkThroughError{@@ -1031,6 +1064,17 @@ func (d *DatabaseState) getSchema(schemaName string) (*SchemaState, *WalkThroughreturn schema, nil}+func (s *SchemaState) pgGetView(viewName string) (*ViewState, *WalkThroughError) {+ view, exists := s.viewSet[viewName]+ if !exists {+ return nil, &WalkThroughError{+ Type: ErrorTypeViewNotExists,+ Content: fmt.Sprintf("The view %q doesn't exists in schema %q", viewName, s.name),+ }+ }+ return view, nil+}+func (s *SchemaState) pgGetTable(tableName string) (*TableState, *WalkThroughError) {table, exists := s.tableSet[tableName]if !exists {