Skip to content

Commit

Permalink
sql: enrich view diffing with attribute changes (#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m authored Oct 13, 2024
1 parent 16722d8 commit cfce708
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions sql/internal/sqlx/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ type (
// one state to the other. For example, dropping or adding a `CHECK` constraint.
TableAttrDiff(from, to *schema.Table) ([]schema.Change, error)

// ViewAttrChanged reports if the view attributes were changed.
// For example, a view was changed to a materialized view.
ViewAttrChanged(from, to *schema.View) bool
// ViewAttrChanges returns the changes between the two view attributes.
ViewAttrChanges(from, to *schema.View) []schema.Change

// ColumnChange returns the schema changes (if any) for migrating one column to the other.
ColumnChange(fromT *schema.Table, from, to *schema.Column, _ *schema.DiffOptions) (schema.Change, error)
Expand Down Expand Up @@ -509,9 +508,9 @@ func (d *Diff) viewDiff(from, to *schema.View, opts *schema.DiffOptions) ([]sche
if err != nil {
return nil, err
}
var changes schema.Changes
if len(c1) > 0 || len(c2) > 0 || d.viewDefChanged(from, to) || d.ViewAttrChanged(from, to) {
changes = opts.AddOrSkip(changes, &schema.ModifyView{From: from, To: to, Changes: append(c1, c2...)})
var changes []schema.Change
if vs := append(d.ViewAttrChanges(from, to), append(c1, c2...)...); len(vs) > 0 || d.viewDefChanged(from, to) {
changes = opts.AddOrSkip(changes, &schema.ModifyView{From: from, To: to, Changes: vs})
}
return changes, nil
}
Expand Down
4 changes: 2 additions & 2 deletions sql/mysql/driver_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (*state) renameView(*schema.RenameView) {
// unimplemented.
}

func (d *diff) ViewAttrChanged(_, _ *schema.View) bool {
return false // Not implemented.
func (*diff) ViewAttrChanges(_, _ *schema.View) []schema.Change {
return nil // Not implemented.
}

func (s *state) addFunc(*schema.AddFunc) error {
Expand Down
4 changes: 2 additions & 2 deletions sql/postgres/driver_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func (*state) modifyTrigger(*schema.ModifyTrigger) error {
return nil // unimplemented.
}

func (d *diff) ViewAttrChanged(_, _ *schema.View) bool {
return false // unimplemented.
func (*diff) ViewAttrChanges(_, _ *schema.View) []schema.Change {
return nil // unimplemented.
}

// RealmObjectDiff returns a changeset for migrating realm (database) objects
Expand Down
4 changes: 2 additions & 2 deletions sql/sqlite/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (d *diff) TableAttrDiff(from, to *schema.Table) ([]schema.Change, error) {
return append(changes, sqlx.CheckDiff(from, to)...), nil
}

func (d *diff) ViewAttrChanged(_, _ *schema.View) bool {
return false // Not implemented.
func (*diff) ViewAttrChanges(_, _ *schema.View) []schema.Change {
return nil // Not implemented.
}

// ColumnChange returns the schema changes (if any) for migrating one column to the other.
Expand Down

0 comments on commit cfce708

Please sign in to comment.