8000 fix(database/gdb): handle PostgreSQL schema in gdb and gen dao by fainc · Pull Request #4871 · gogf/gf · GitHub
[go: up one dir, main page]

Skip to content

fix(database/gdb): handle PostgreSQL schema in gdb and gen dao - #4871

Open
fainc wants to merge 2 commits into
gogf:masterfrom
fainc:fix_4127
Open

fainc wants to merge 2 commits into
gogf:masterfrom
fainc:fix_4127

Conversation

@fainc
@fainc fainc commented Aug 28, 2026 •
Copy link
Copy Markdown
Contributor

Fixes #4127

fix(database/gdb): implement PostgreSQL schema handling
fix(gendao): support PostgreSQL schema generation

This pull request introduces support for PostgreSQL schema selection in the gen dao command and improves schema handling across the codebase, especially for PostgreSQL. It adds a new --schema option, updates documentation and test coverage, and refines internal logic to correctly handle schema configuration for different drivers.

PostgreSQL Schema Support in gen dao:

  • Added a Schema field to CGenDaoInput, exposed as the --schema command-line option and in config metadata, allowing users to specify which PostgreSQL schema to use when generating DAOs. [1] [2] [3]
  • Updated the doGenDaoForArray function to switch the database context to the selected schema if specified.
  • Introduced a new unit test (Test_Gen_Dao_PostgreSQLSchema) to verify DAO generation from a specific PostgreSQL schema.
  • Enhanced documentation and usage examples to show how to use the new --schema option with PostgreSQL. [1] [2]

Internal Schema Handling Improvements:

  • Refactored schema handling in gdb.Core to use a new helper, setSchemaToConfigNode, which ensures PostgreSQL schema selection uses the Namespace field and does not overwrite the database name. [1] [2] [3] [4]
  • Added a dedicated test to verify correct schema assignment for PostgreSQL and MySQL drivers.

PostgreSQL Driver and Test Adjustments:

  • Refactored how the PostgreSQL driver retrieves the schema for table discovery, using GetSchema() instead of Namespace directly.
  • Updated test initialization and references to use public as the default PostgreSQL schema, improving test clarity and correctness. [1] [2] [3] [4] [5]

These changes ensure that schema selection is explicit, consistent, and driver-appropriate, especially for PostgreSQL users working with multiple schemas.

@fainc
fainc requested a review from lingcoder August 28, 2026 03:40
@fainc fainc added bug It is confirmed a bug, but don't worry, we'll handle it. CLI about gf cli labels Aug 28, 2026
@fainc
fainc requested a lite review from Copilot August 28, 2026 03:49
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates GoFrame’s gdb and gf gen dao tooling to support PostgreSQL schema selection (schema-as-namespace) without conflating it with the database name, enabling correct multi-schema workflows for pgsql.

Changes:

  • Add --schema support to gf gen dao (plus config metadata + tests) and apply the selected schema via db.Schema(...) during generation.
  • Refine gdb.Core schema handling so PostgreSQL uses ConfigNode.Namespace (schema) while preserving ConfigNode.Name (database).
  • Update the PostgreSQL driver and unit tests to treat public as the default schema and use GetSchema() consistently.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
database/gdb/gdb.go Adds pgsql driver type constant and applies schema to config nodes via a driver-aware helper.
database/gdb/gdb_core_config.go Updates GetSchema() so PostgreSQL schema comes from Namespace rather than Name.
database/gdb/gdb_z_unit_schema_test.go Adds unit test verifying driver-specific schema assignment behavior (pgsql vs mysql).
contrib/drivers/pgsql/pgsql_z_unit_init_test.go Adjusts pgsql test initialization to separate database name vs schema and default to public.
contrib/drivers/pgsql/pgsql_z_unit_filter_test.go Updates schema arguments in pgsql tests to use the shared SchemaName.
contrib/drivers/pgsql/pgsql_z_unit_feature_metadata_test.go Updates schema-related test comment to reflect public default.
contrib/drivers/pgsql/pgsql_tables.go Uses GetSchema() for table discovery and reorders link retrieval accordingly.
cmd/gf/internal/cmd/gendao/gendao.go Adds Schema to input and applies it to the DB instance before table discovery/generation.
cmd/gf/internal/cmd/gendao/gendao_test.go Adds unit test verifying Schema is exposed via struct tags/metadata.
cmd/gf/internal/cmd/gendao/gendao_tag.go Updates CLI help/config examples and adds the schema brief/metadata entry.
cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go Adds integration-style unit test generating DAOs from a dynamically created PostgreSQL schema.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 59 to 62
schemaTemplate := "SELECT 'CREATE DATABASE %s' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '%s')"
if _, err := db.Exec(ctx, fmt.Sprintf(schemaTemplate, SchemaName, SchemaName)); err != nil {
if _, err := db.Exec(ctx, fmt.Sprintf(schemaTemplate, DatabaseName, DatabaseName)); err != nil {
gtest.Error(err)
}
@gqcn
gqcn commented Sep 14, 2026
Copy link
Copy Markdown
Member

This looks like useful PostgreSQL schema support, and the tests/help text around --schema are a good start. A couple of process items would make it easier to merge:

  • Suggested priority PR title: it currently does not follow <type>[optional scope]: <description> (for example fix(database/gdb): handle PostgreSQL schema in gdb and gen dao).
  • Suggested improvement issue link: the body uses Fix:#4127. Consider Fixes #4127 so GitHub can close the issue on merge.

I have not added the bot-approved label yet.

@fainc fainc changed the title Implement PostgreSQL schema handling and gf gen dao generation support fix(database/gdb): handle PostgreSQL schema in gdb and gen dao Sep 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug It is confirmed a bug, but don't worry, we'll handle it. CLI about gf cli

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pgsql does not support dynamic schema switch

3 participants

0