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

cmd/atlas/internal/migratelint: make linting inspection context-aware #3201

Merged
merged 1 commit into from
Oct 26, 2024
Merged
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
19 changes: 15 additions & 4 deletions cmd/atlas/internal/migratelint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,22 @@ func (d *DevLoader) mayFix(stmt string, changes schema.Changes) schema.Changes {

// inspect the realm and filter by schema if we are connected to one.
func (d *DevLoader) inspect(ctx context.Context) (*schema.Realm, error) {
opts := &schema.InspectRealmOption{}
if d.Dev.URL.Schema != "" {
opts.Schemas = append(opts.Schemas, d.Dev.URL.Schema)
if d.Dev.URL.Schema == "" {
return d.Dev.InspectRealm(ctx, &schema.InspectRealmOption{})
}
return d.Dev.InspectRealm(ctx, opts)
ns, err := d.Dev.InspectSchema(ctx, "", &schema.InspectOptions{})
if err != nil {
return nil, err
}
// Normalize the returned realm to
// look like InspectRealm output.
if ns.Name == "" {
ns.Name = d.Dev.URL.Schema
}
if ns.Realm == nil {
ns.Realm = schema.NewRealm(ns)
}
return ns.Realm, nil
}

// lock database so no one else interferes with our change detection.
Expand Down