dialect/sql/schema: qualify if schema is given (#4346)

This commit is contained in:
Jannik Clausen
2025-03-10 14:24:01 +01:00
committed by GitHub
parent 7f5f143bd2
commit 80f9cbf5bf
2 changed files with 7 additions and 4 deletions

View File

@@ -937,10 +937,6 @@ func (a *Atlas) realm(tables []*Table) (*schema.Realm, error) {
ss := slices.SortedFunc(maps.Values(sm), func(a, b *schema.Schema) int { ss := slices.SortedFunc(maps.Values(sm), func(a, b *schema.Schema) int {
return strings.Compare(a.Name, b.Name) return strings.Compare(a.Name, b.Name)
}) })
// In case there only is one schema, do not qualify the schema name.
if len(ss) == 1 {
ss[0].Name = ""
}
return &schema.Realm{Schemas: ss}, nil return &schema.Realm{Schemas: ss}, nil
} }

View File

@@ -325,5 +325,12 @@ CREATE VIEW $pets_without_fur$ ($id$, $name$, $owner_id$) AS SELECT id, name, ow
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, tt.expected, ac) require.Equal(t, tt.expected, ac)
}) })
t.Run(n+" single schema", func(t *testing.T) {
ac, err := Dump(context.Background(), tt.dialect, tt.version, tables[0:1])
require.NoError(t, err)
if tt.dialect != dialect.SQLite {
require.True(t, strings.HasPrefix(ac, "-- Add new schema named \"s1\""), strings.Split(ac, "\n")[0])
}
})
} }
} }