Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support autoIncColumnChange #2240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sql/mysql/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ func (d *diff) ColumnChange(fromT *schema.Table, from, to *schema.Column) (schem
if changed {
change |= schema.ChangeCollate
}
if changed, err = d.autoIncColumnChange(from, to); err != nil {
return schema.NoChange, err
}
if changed {
change |= schema.ChangeColumn
}
return change, nil
}

Expand Down Expand Up @@ -411,6 +417,13 @@ func (*diff) autoIncChange(from, to []schema.Attr) schema.Change {
return noChange
}

// autoIncColumnChange returns the column change for changing the AUTO_INCREMENT
func (*diff) autoIncColumnChange(from, to *schema.Column) (bool, error) {
var fromA, toA AutoIncrement
fromHas, toHas := sqlx.Has(from.Attrs, &fromA), sqlx.Has(to.Attrs, &toA)
return fromHas != toHas, nil
}

// indexType returns the index type from its attribute.
// The default type is BTREE if no type was specified.
func indexType(attr []schema.Attr) *IndexType {
Expand Down