Skip to content

Commit d3f5232

Browse files
authored
v0.5.0 (#30)
* Update version * Update version * Fixed that added column position to expected * Update version
1 parent 4812526 commit d3f5232

4 files changed

Lines changed: 65 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
## 0.5.0 (2017-11-14)
2+
3+
Carpenter 0.5.0 has been released.
4+
5+
Note:
6+
This version has to become impossible to modify column positions.
7+
But adding column is adjusted to expecting position.
8+
9+
### Added
10+
11+
- Nothing
12+
13+
### Deprecated
14+
15+
- Nothing
16+
17+
### Removed
18+
19+
- It's to become impossible to modify column positions when alter columns.
20+
21+
### Fixed
22+
23+
- Fixed that added column position to expected
24+
25+
26+
## 0.4.9 (2017-11-10)
27+
28+
### Added
29+
30+
- Modified MySQL connection settings (no idle connections)
31+
32+
### Deprecated
33+
34+
- Nothing
35+
36+
### Removed
37+
38+
- Nothing
39+
40+
### Fixed
41+
42+
- Fixed the SQL syntax error caused by column collation comparing
43+
44+
145
## 0.4.8 (2017-10-05)
246

347
### Added

builder/builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,18 @@ func willModifyColumn(old, new *mysql.Table) []string {
138138
oldTableSchema := oldCol.TableSchema
139139
oldColumnKey := oldCol.ColumnKey
140140
oldPrivileges := oldCol.Privileges
141+
oldOrdinalPosition := oldCol.OrdinalPosition
141142
oldCol.TableSchema = newCol.TableSchema
142143
oldCol.ColumnKey = newCol.ColumnKey
143144
oldCol.Privileges = newCol.Privileges
145+
oldCol.OrdinalPosition = newCol.OrdinalPosition
144146
if !reflect.DeepEqual(oldCol, newCol) {
145-
sql := newCol.ToModifySQL()
146-
sql = fmt.Sprintf("%s %s", sql, newCol.AppendPos(new.Columns))
147-
sqls = append(sqls, sql)
147+
sqls = append(sqls, newCol.ToModifySQL())
148148
}
149149
oldCol.TableSchema = oldTableSchema
150150
oldCol.ColumnKey = oldColumnKey
151151
oldCol.Privileges = oldPrivileges
152+
oldCol.OrdinalPosition = oldOrdinalPosition
152153
}
153154
return sqls
154155
}

cmd/carpenter/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package main
22

33
const Name string = "carpenter"
4-
const Version string = "0.4.8"
4+
const Version string = "0.5.0"

dialect/mysql/column.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,21 @@ func (m Columns) ToSQL() []string {
131131
}
132132

133133
func (m *Column) AppendPos(all Columns) string {
134-
pos := "first"
135-
if m.OrdinalPosition > 1 {
136-
before := m.OrdinalPosition - 1
137-
for _, v := range all {
138-
if v.OrdinalPosition != before {
139-
continue
140-
}
141-
pos = fmt.Sprintf("after %s", Quote(v.ColumnName))
142-
break
134+
name := "first"
135+
if n := all.GetBeforeColumn(m); n != nil {
136+
name = n.ColumnName
137+
}
138+
return fmt.Sprintf("after %s", Quote(name))
139+
}
140+
141+
func (m Columns) GetBeforeColumn(col *Column) *Column {
142+
search := col.OrdinalPosition - 1
143+
for _, c := range m {
144+
if c.OrdinalPosition == search {
145+
return c
143146
}
144147
}
145-
return pos
148+
return nil
146149
}
147150

148151
func (m Columns) ToAddSQL(all Columns) []string {
@@ -180,10 +183,12 @@ func (m Columns) GroupByColumnName() map[string]*Column {
180183

181184
func (m Columns) GetSortedColumnNames() []string {
182185
names := make([]string, 0, len(m))
186+
sort.Slice(m, func(i, j int) bool {
187+
return m[i].OrdinalPosition < m[j].OrdinalPosition
188+
})
183189
for _, column := range m {
184190
names = append(names, column.ColumnName)
185191
}
186-
sort.Strings(names)
187192
return names
188193
}
189194

0 commit comments

Comments
 (0)