Skip to content

Commit

Permalink
v0.5.0 (#30)
Browse files Browse the repository at this point in the history
* Update version

* Update version

* Fixed that added column position to expected

* Update version
  • Loading branch information
hatajoe authored Nov 14, 2017
1 parent 4812526 commit d3f5232
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
## 0.5.0 (2017-11-14)

Carpenter 0.5.0 has been released.

Note:
This version has to become impossible to modify column positions.
But adding column is adjusted to expecting position.

### Added

- Nothing

### Deprecated

- Nothing

### Removed

- It's to become impossible to modify column positions when alter columns.

### Fixed

- Fixed that added column position to expected


## 0.4.9 (2017-11-10)

### Added

- Modified MySQL connection settings (no idle connections)

### Deprecated

- Nothing

### Removed

- Nothing

### Fixed

- Fixed the SQL syntax error caused by column collation comparing


## 0.4.8 (2017-10-05)

### Added
Expand Down
7 changes: 4 additions & 3 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,18 @@ func willModifyColumn(old, new *mysql.Table) []string {
oldTableSchema := oldCol.TableSchema
oldColumnKey := oldCol.ColumnKey
oldPrivileges := oldCol.Privileges
oldOrdinalPosition := oldCol.OrdinalPosition
oldCol.TableSchema = newCol.TableSchema
oldCol.ColumnKey = newCol.ColumnKey
oldCol.Privileges = newCol.Privileges
oldCol.OrdinalPosition = newCol.OrdinalPosition
if !reflect.DeepEqual(oldCol, newCol) {
sql := newCol.ToModifySQL()
sql = fmt.Sprintf("%s %s", sql, newCol.AppendPos(new.Columns))
sqls = append(sqls, sql)
sqls = append(sqls, newCol.ToModifySQL())
}
oldCol.TableSchema = oldTableSchema
oldCol.ColumnKey = oldColumnKey
oldCol.Privileges = oldPrivileges
oldCol.OrdinalPosition = oldOrdinalPosition
}
return sqls
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/carpenter/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

const Name string = "carpenter"
const Version string = "0.4.8"
const Version string = "0.5.0"
27 changes: 16 additions & 11 deletions dialect/mysql/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,21 @@ func (m Columns) ToSQL() []string {
}

func (m *Column) AppendPos(all Columns) string {
pos := "first"
if m.OrdinalPosition > 1 {
before := m.OrdinalPosition - 1
for _, v := range all {
if v.OrdinalPosition != before {
continue
}
pos = fmt.Sprintf("after %s", Quote(v.ColumnName))
break
name := "first"
if n := all.GetBeforeColumn(m); n != nil {
name = n.ColumnName
}
return fmt.Sprintf("after %s", Quote(name))
}

func (m Columns) GetBeforeColumn(col *Column) *Column {
search := col.OrdinalPosition - 1
for _, c := range m {
if c.OrdinalPosition == search {
return c
}
}
return pos
return nil
}

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

func (m Columns) GetSortedColumnNames() []string {
names := make([]string, 0, len(m))
sort.Slice(m, func(i, j int) bool {
return m[i].OrdinalPosition < m[j].OrdinalPosition
})
for _, column := range m {
names = append(names, column.ColumnName)
}
sort.Strings(names)
return names
}

Expand Down

0 comments on commit d3f5232

Please sign in to comment.