Skip to content

Commit

Permalink
feat: default schema configuration for postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
prog8 committed Oct 21, 2024
1 parent 8bf2817 commit 0124613
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
c.catalog = dolphin.NewCatalog()
case config.EnginePostgreSQL:
c.parser = postgresql.NewParser()
c.catalog = postgresql.NewCatalog()
c.catalog = postgresql.NewCatalog(combo.Package.DefaultSchema)
if conf.Database != nil {
if conf.Analyzer.Database == nil || *conf.Analyzer.Database {
c.analyzer = analyzer.Cached(
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type SQL struct {
Name string `json:"name" yaml:"name"`
Engine Engine `json:"engine,omitempty" yaml:"engine"`
Schema Paths `json:"schema" yaml:"schema"`
DefaultSchema string `json:"default_schema" yaml:"default_schema"`
Queries Paths `json:"queries" yaml:"queries"`
Database *Database `json:"database" yaml:"database"`
StrictFunctionChecks bool `json:"strict_function_checks" yaml:"strict_function_checks"`
Expand Down
9 changes: 6 additions & 3 deletions internal/engine/postgresql/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ func toPointer(x int) *int {
return &x
}

func NewCatalog() *catalog.Catalog {
c := catalog.New("public")
func NewCatalog(defaultSchema string) *catalog.Catalog {
if defaultSchema == "" {
defaultSchema = "public"
}
c := catalog.New(defaultSchema)
c.Schemas = append(c.Schemas, pgTemp())
c.Schemas = append(c.Schemas, genPGCatalog())
c.Schemas = append(c.Schemas, genInformationSchema())
c.SearchPath = []string{"pg_catalog"}
c.SearchPath = []string{"pg_catalog", defaultSchema}
c.LoadExtension = loadExtension
return c
}

0 comments on commit 0124613

Please sign in to comment.