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

sql/internal/sqlx: pass diff options to drivers #3175

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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
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