(n *chast.AlterQuery)
| 942 | } |
| 943 | |
| 944 | func (c *cc) convertAlterQuery(n *chast.AlterQuery) ast.Node { |
| 945 | alt := &ast.AlterTableStmt{ |
| 946 | Table: &ast.TableName{ |
| 947 | Name: identifier(n.Table), |
| 948 | }, |
| 949 | Cmds: &ast.List{}, |
| 950 | } |
| 951 | |
| 952 | if n.Database != "" { |
| 953 | alt.Table.Schema = identifier(n.Database) |
| 954 | } |
| 955 | |
| 956 | for _, cmd := range n.Commands { |
| 957 | switch cmd.Type { |
| 958 | case chast.AlterAddColumn: |
| 959 | if cmd.Column != nil { |
| 960 | name := cmd.Column.Name |
| 961 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 962 | Name: &name, |
| 963 | Subtype: ast.AT_AddColumn, |
| 964 | Def: c.convertColumnDeclaration(cmd.Column), |
| 965 | }) |
| 966 | } |
| 967 | case chast.AlterDropColumn: |
| 968 | name := cmd.ColumnName |
| 969 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 970 | Name: &name, |
| 971 | Subtype: ast.AT_DropColumn, |
| 972 | MissingOk: cmd.IfExists, |
| 973 | }) |
| 974 | case chast.AlterModifyColumn: |
| 975 | if cmd.Column != nil { |
| 976 | name := cmd.Column.Name |
| 977 | // Drop and re-add to simulate modify |
| 978 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 979 | Name: &name, |
| 980 | Subtype: ast.AT_DropColumn, |
| 981 | }) |
| 982 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 983 | Name: &name, |
| 984 | Subtype: ast.AT_AddColumn, |
| 985 | Def: c.convertColumnDeclaration(cmd.Column), |
| 986 | }) |
| 987 | } |
| 988 | case chast.AlterRenameColumn: |
| 989 | oldName := cmd.ColumnName |
| 990 | newName := cmd.NewName |
| 991 | return &ast.RenameColumnStmt{ |
| 992 | Table: alt.Table, |
| 993 | Col: &ast.ColumnRef{Name: oldName}, |
| 994 | NewName: &newName, |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | return alt |
| 1000 | } |
| 1001 |
no test coverage detected