Skip to content

Commit dc97e56

Browse files
authored
alec/handle-mysql-renames (#613)
1 parent 1b4c47b commit dc97e56

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

internal/mysql/schema.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ func (s *Schema) Add(ddl *sqlparser.DDL) error {
6363
return fmt.Errorf("failed to parse table \"%s\" schema", name)
6464
}
6565
s.tables[name] = ddl.TableSpec.Columns
66+
case "rename":
67+
if len(ddl.FromTables) != 1 || len(ddl.ToTables) != 1 {
68+
return fmt.Errorf("rename without one 'from' table and one 'to' table: %#v", ddl)
69+
}
70+
from := ddl.FromTables[0].Name.String()
71+
to := ddl.ToTables[0].Name.String()
72+
cols, ok := s.tables[from]
73+
if !ok {
74+
return fmt.Errorf("unknown existing table %q", from)
75+
}
76+
delete(s.tables, from)
77+
s.tables[to] = cols
6678
}
6779
return nil
6880
}

0 commit comments

Comments
 (0)