Skip to content

Commit

Permalink
sql/internal/sqlx: pass diff options to ColumnChange (#3182)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m authored Oct 9, 2024
1 parent 208598f commit b49f56f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sql/internal/sqlx/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type (
ViewAttrChanged(from, to *schema.View) bool

// ColumnChange returns the schema changes (if any) for migrating one column to the other.
ColumnChange(fromT *schema.Table, from, to *schema.Column) (schema.Change, error)
ColumnChange(fromT *schema.Table, from, to *schema.Column, _ *schema.DiffOptions) (schema.Change, error)

// IndexAttrChanged reports if the index attributes were changed.
// For example, an index type or predicate (for partial indexes).
Expand Down Expand Up @@ -393,7 +393,7 @@ func (d *Diff) columnDiff(from, to *schema.Table, opts *schema.DiffOptions) ([]s
all = append(all, &schema.DropColumn{C: c1})
continue
}
change, err := d.ColumnChange(from, c1, c2)
change, err := d.ColumnChange(from, c1, c2, opts)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/mysql/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (d *diff) TableAttrDiff(from, to *schema.Table) ([]schema.Change, error) {
}

// ColumnChange returns the schema changes (if any) for migrating one column to the other.
func (d *diff) ColumnChange(fromT *schema.Table, from, to *schema.Column) (schema.Change, error) {
func (d *diff) ColumnChange(fromT *schema.Table, from, to *schema.Column, _ *schema.DiffOptions) (schema.Change, error) {
change := sqlx.CommentChange(from.Attrs, to.Attrs)
if from.Type.Null != to.Type.Null {
change |= schema.ChangeNull
Expand Down
4 changes: 2 additions & 2 deletions sql/postgres/crdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (cd *crdbDiff) Normalize(from, to *schema.Table, _ *schema.DiffOptions) err
return nil
}

func (cd *crdbDiff) ColumnChange(fromT *schema.Table, from, to *schema.Column) (schema.Change, error) {
func (cd *crdbDiff) ColumnChange(fromT *schema.Table, from, to *schema.Column, opts *schema.DiffOptions) (schema.Change, error) {
// All serial types in Cockroach are implemented as bigint.
// See: https://www.cockroachlabs.com/docs/stable/serial.html#generated-values-for-mode-sql_sequence-and-sql_sequence_cached.
for _, c := range []*schema.Column{from, to} {
Expand All @@ -90,7 +90,7 @@ func (cd *crdbDiff) ColumnChange(fromT *schema.Table, from, to *schema.Column) (
from.Default = nil
}
}
return cd.diff.ColumnChange(fromT, from, to)
return cd.diff.ColumnChange(fromT, from, to, opts)
}

func (cd *crdbDiff) normalize(table *schema.Table) {
Expand Down
2 changes: 1 addition & 1 deletion sql/postgres/diff_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *diff) TableAttrDiff(from, to *schema.Table) ([]schema.Change, error) {
}

// ColumnChange returns the schema changes (if any) for migrating one column to the other.
func (d *diff) ColumnChange(_ *schema.Table, from, to *schema.Column) (schema.Change, error) {
func (d *diff) ColumnChange(_ *schema.Table, from, to *schema.Column, _ *schema.DiffOptions) (schema.Change, error) {
change := sqlx.CommentChange(from.Attrs, to.Attrs)
if from.Type.Null != to.Type.Null {
change |= schema.ChangeNull
Expand Down
2 changes: 1 addition & 1 deletion sql/sqlite/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *diff) ViewAttrChanged(_, _ *schema.View) bool {

// ColumnChange returns the schema changes (if any) for migrating one column to the other.
// Note that column comments are ignored as SQLite does not support it.
func (d *diff) ColumnChange(_ *schema.Table, from, to *schema.Column) (schema.Change, error) {
func (d *diff) ColumnChange(_ *schema.Table, from, to *schema.Column, _ *schema.DiffOptions) (schema.Change, error) {
var change schema.ChangeKind
if from.Type.Null != to.Type.Null {
change |= schema.ChangeNull
Expand Down

0 comments on commit b49f56f

Please sign in to comment.