(n *pcast.AlterTableStmt)
| 35 | } |
| 36 | |
| 37 | func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node { |
| 38 | alt := &ast.AlterTableStmt{ |
| 39 | Table: parseTableName(n.Table), |
| 40 | Cmds: &ast.List{}, |
| 41 | } |
| 42 | for _, spec := range n.Specs { |
| 43 | switch spec.Tp { |
| 44 | case pcast.AlterTableAddColumns: |
| 45 | for _, def := range spec.NewColumns { |
| 46 | name := def.Name.String() |
| 47 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 48 | Name: &name, |
| 49 | Subtype: ast.AT_AddColumn, |
| 50 | Def: convertColumnDef(def), |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | case pcast.AlterTableDropColumn: |
| 55 | name := spec.OldColumnName.String() |
| 56 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 57 | Name: &name, |
| 58 | Subtype: ast.AT_DropColumn, |
| 59 | MissingOk: spec.IfExists, |
| 60 | }) |
| 61 | |
| 62 | case pcast.AlterTableChangeColumn: |
| 63 | oldName := spec.OldColumnName.String() |
| 64 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 65 | Name: &oldName, |
| 66 | Subtype: ast.AT_DropColumn, |
| 67 | }) |
| 68 | |
| 69 | for _, def := range spec.NewColumns { |
| 70 | name := def.Name.String() |
| 71 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 72 | Name: &name, |
| 73 | Subtype: ast.AT_AddColumn, |
| 74 | Def: convertColumnDef(def), |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | case pcast.AlterTableModifyColumn: |
| 79 | for _, def := range spec.NewColumns { |
| 80 | name := def.Name.String() |
| 81 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 82 | Name: &name, |
| 83 | Subtype: ast.AT_DropColumn, |
| 84 | }) |
| 85 | alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{ |
| 86 | Name: &name, |
| 87 | Subtype: ast.AT_AddColumn, |
| 88 | Def: convertColumnDef(def), |
| 89 | }) |
| 90 | } |
| 91 | |
| 92 | case pcast.AlterTableAlterColumn: |
| 93 | // spew.Dump("alter column", spec) |
| 94 |
no test coverage detected