(out *strings.Builder, tableDiff *schema.TableDiff)
| 1110 | } |
| 1111 | |
| 1112 | func writeAlterTableDiff(out *strings.Builder, tableDiff *schema.TableDiff) error { |
| 1113 | for _, columnDiff := range tableDiff.ColumnChanges { |
| 1114 | if columnDiff.Action == schema.MetadataDiffActionDrop { |
| 1115 | continue |
| 1116 | } |
| 1117 | if err := writeColumnDiff(out, tableDiff.SchemaName, tableDiff.TableName, columnDiff); err != nil { |
| 1118 | return err |
| 1119 | } |
| 1120 | } |
| 1121 | for _, partitionDiff := range tableDiff.PartitionChanges { |
| 1122 | if partitionDiff.Action == schema.MetadataDiffActionCreate { |
| 1123 | if err := writeCreatePartitionDiff(out, tableDiff.SchemaName, tableDiff.TableName, tableDiff.NewTable.GetColumns(), partitionDiff.NewPartition); err != nil { |
| 1124 | return err |
| 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | for _, primaryKeyDiff := range tableDiff.PrimaryKeyChanges { |
| 1129 | if primaryKeyDiff.Action == schema.MetadataDiffActionCreate || primaryKeyDiff.Action == schema.MetadataDiffActionAlter { |
| 1130 | if err := writePrimaryKey(out, tableDiff.SchemaName, tableDiff.TableName, primaryKeyDiff.NewPrimaryKey); err != nil { |
| 1131 | return err |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | for _, uniqueConstraintDiff := range tableDiff.UniqueConstraintChanges { |
| 1136 | if uniqueConstraintDiff.Action == schema.MetadataDiffActionCreate || uniqueConstraintDiff.Action == schema.MetadataDiffActionAlter { |
| 1137 | if err := writeUniqueKey(out, tableDiff.SchemaName, tableDiff.TableName, uniqueConstraintDiff.NewUniqueConstraint); err != nil { |
| 1138 | return err |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | for _, checkDiff := range tableDiff.CheckConstraintChanges { |
| 1143 | if checkDiff.Action == schema.MetadataDiffActionCreate || checkDiff.Action == schema.MetadataDiffActionAlter { |
| 1144 | if err := writeAddCheckConstraint(out, tableDiff.SchemaName, tableDiff.TableName, checkDiff.NewCheckConstraint); err != nil { |
| 1145 | return err |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | for _, excludeDiff := range tableDiff.ExcludeConstraintChanges { |
| 1150 | if excludeDiff.Action == schema.MetadataDiffActionCreate || excludeDiff.Action == schema.MetadataDiffActionAlter { |
| 1151 | if err := writeAddExcludeConstraint(out, tableDiff.SchemaName, tableDiff.TableName, excludeDiff.NewExcludeConstraint); err != nil { |
| 1152 | return err |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | for _, indexDiff := range tableDiff.IndexChanges { |
| 1157 | if indexDiff.Action == schema.MetadataDiffActionCreate || indexDiff.Action == schema.MetadataDiffActionAlter { |
| 1158 | if err := writeCreateIndexDiff(out, tableDiff.SchemaName, tableDiff.TableName, indexDiff.NewIndex); err != nil { |
| 1159 | return err |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | return writeTableCommentDiff(out, tableDiff.SchemaName, tableDiff.TableName, tableDiff.OldTable.GetComment(), tableDiff.NewTable.GetComment()) |
| 1164 | } |
| 1165 | |
| 1166 | func writeColumnDiff(out *strings.Builder, schemaName, tableName string, columnDiff *schema.ColumnDiff) error { |
| 1167 | switch columnDiff.Action { |
no test coverage detected