From 3c9e7d64567fa77d046e74e8e75be0c46dc75732 Mon Sep 17 00:00:00 2001 From: Pawel Rog Date: Mon, 21 Oct 2024 14:12:21 +0200 Subject: [PATCH 1/2] feat: default schema configuration for postgresql --- internal/compiler/engine.go | 2 +- internal/config/config.go | 1 + internal/engine/postgresql/catalog.go | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/compiler/engine.go b/internal/compiler/engine.go index d263637d9f..7156e310a1 100644 --- a/internal/compiler/engine.go +++ b/internal/compiler/engine.go @@ -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( diff --git a/internal/config/config.go b/internal/config/config.go index 5bfa506b00..866524e0c6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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"` diff --git a/internal/engine/postgresql/catalog.go b/internal/engine/postgresql/catalog.go index 3c262122a2..19085f96ed 100644 --- a/internal/engine/postgresql/catalog.go +++ b/internal/engine/postgresql/catalog.go @@ -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 } From 16ab835b548822a8e98f1006233f9c99b1bdadde Mon Sep 17 00:00:00 2001 From: Pawel Rog Date: Thu, 19 Dec 2024 17:36:30 +0100 Subject: [PATCH 2/2] fix test --- internal/engine/postgresql/catalog_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/engine/postgresql/catalog_test.go b/internal/engine/postgresql/catalog_test.go index 875ea7e458..96fdc0a752 100644 --- a/internal/engine/postgresql/catalog_test.go +++ b/internal/engine/postgresql/catalog_test.go @@ -149,7 +149,7 @@ func TestUpdateErrors(t *testing.T) { t.Fatal(err) } - c := NewCatalog() + c := NewCatalog("") err = c.Build(stmts) if err == nil { t.Log(test.stmt)