Skip to content

Commit 6ca9ed7

Browse files
committed
update GetSchemataAll to use SchemataLevelColumn and add corresponding test
1 parent 8aa4d5d commit 6ca9ed7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

core/dbio/database/schemata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ func GetSchemataAll(conn Connection) (schemata Schemata, err error) {
999999
}
10001000

10011001
// pull down schemata
1002-
newSchemata, err := newConn.GetSchemata("", "")
1002+
newSchemata, err := newConn.GetSchemata(SchemataLevelColumn, "")
10031003
if err != nil {
10041004
g.Warn("could not obtain schemata for database: %s. %s", dbName, err)
10051005
return

core/dbio/database/schemata_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66

77
"github.com/flarco/g"
88
"github.com/slingdata-io/sling-cli/core/dbio"
9+
"github.com/slingdata-io/sling-cli/core/env"
10+
"github.com/spf13/cast"
911
"github.com/stretchr/testify/assert"
1012
)
1113

@@ -297,6 +299,34 @@ func TestParseSQLMultiStatements(t *testing.T) {
297299
}
298300
}
299301

302+
func TestGetSchemataAll(t *testing.T) {
303+
ef := env.LoadSlingEnvFile()
304+
305+
url := cast.ToStringMap(ef.Connections["POSTGRES"])["url"]
306+
if url == nil {
307+
t.Skip("POSTGRES env var not set")
308+
}
309+
310+
conn, err := NewConn(cast.ToString(url))
311+
if !assert.NoError(t, err) {
312+
return
313+
}
314+
defer conn.Close()
315+
316+
schemata, err := GetSchemataAll(conn)
317+
if !assert.NoError(t, err) {
318+
return
319+
}
320+
321+
// Count all tables from all databases
322+
tableCount := 0
323+
for _, db := range schemata.Databases {
324+
tableCount += len(db.Tables())
325+
}
326+
327+
assert.Greater(t, tableCount, 0, "expected at least one table across all databases")
328+
}
329+
300330
func TestTrimSQLComments(t *testing.T) {
301331
type testCase struct {
302332
name string

0 commit comments

Comments
 (0)