Skip to content

Commit

Permalink
sql/internal/sqlx: pass diff options to drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Oct 4, 2024
1 parent fb15bfb commit d6abc61
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
17 changes: 13 additions & 4 deletions cmd/atlas/internal/cmdapi/cmdapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ type (
AbortError struct {
Err error
}
// Aborter allows errors to signal if the error is an abort error.
Aborter interface {
error
IsAbort()
}
)

func (e *FormattedError) Error() string { return e.Err.Error() }
Expand All @@ -129,10 +134,14 @@ func (e *AbortError) FormatError(cmd *cobra.Command) {

// RunE wraps the command cobra.Command.RunE function with additional postrun logic.
func RunE(f func(*cobra.Command, []string) error) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
err := f(cmd, args)
if ef, ok := err.(ErrorFormatter); ok {
ef.FormatError(cmd)
return func(cmd *cobra.Command, args []string) (err error) {
if err = f(cmd, args); err != nil {
if err1 := (Aborter)(nil); errors.As(err, &err1) {
err = &AbortError{Err: err}
}
if ef, ok := err.(ErrorFormatter); ok {
ef.FormatError(cmd)
}
}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions sql/internal/sqlx/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type (

// SchemaObjectDiff returns a changeset for migrating schema objects from
// one state to the other. For example, changing schema custom types.
SchemaObjectDiff(from, to *schema.Schema) ([]schema.Change, error)
SchemaObjectDiff(from, to *schema.Schema, _ *schema.DiffOptions) ([]schema.Change, error)

// TableAttrDiff returns a changeset for migrating table attributes from
// one state to the other. For example, dropping or adding a `CHECK` constraint.
Expand Down Expand Up @@ -196,7 +196,7 @@ func (d *Diff) schemaDiff(from, to *schema.Schema, opts *schema.DiffOptions) ([]
})
}
// Add, drop or modify objects.
change, err := d.SchemaObjectDiff(from, to)
change, err := d.SchemaObjectDiff(from, to, 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 @@ -61,7 +61,7 @@ func (*diff) RealmObjectDiff(_, _ *schema.Realm) ([]schema.Change, error) {

// SchemaObjectDiff returns a changeset for migrating schema objects from
// one state to the other.
func (*diff) SchemaObjectDiff(_, _ *schema.Schema) ([]schema.Change, error) {
func (*diff) SchemaObjectDiff(_, _ *schema.Schema, _ *schema.DiffOptions) ([]schema.Change, error) {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion sql/postgres/driver_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (*diff) RealmObjectDiff(_, _ *schema.Realm) ([]schema.Change, error) {

// SchemaObjectDiff returns a changeset for migrating schema objects from
// one state to the other.
func (*diff) SchemaObjectDiff(from, to *schema.Schema) ([]schema.Change, error) {
func (*diff) SchemaObjectDiff(from, to *schema.Schema, _ *schema.DiffOptions) ([]schema.Change, error) {
var changes []schema.Change
// Drop or modify enums.
for _, o1 := range from.Objects {
Expand Down
2 changes: 1 addition & 1 deletion sql/sqlite/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (*diff) RealmObjectDiff(_, _ *schema.Realm) ([]schema.Change, error) {

// SchemaObjectDiff returns a changeset for migrating schema objects from
// one state to the other.
func (*diff) SchemaObjectDiff(_, _ *schema.Schema) ([]schema.Change, error) {
func (*diff) SchemaObjectDiff(_, _ *schema.Schema, _ *schema.DiffOptions) ([]schema.Change, error) {
return nil, nil
}

Expand Down

0 comments on commit d6abc61

Please sign in to comment.