Skip to content

fix(postgresql): support schemas in base store#2273

Open
zouyx wants to merge 3 commits into
agentscope-ai:mainfrom
zouyx:fix/postgres-base-store-schema
Open

fix(postgresql): support schemas in base store#2273
zouyx wants to merge 3 commits into
agentscope-ai:mainfrom
zouyx:fix/postgres-base-store-schema

Conversation

@zouyx

@zouyx zouyx commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Closes #2192.

PostgresBaseStore previously only supported unqualified table names. This PR adds optional PostgreSQL schema support while preserving the existing behavior when no schema is configured.

Changes:

  • Add PostgresBaseStore.Builder#schemaName(String).
  • Use quoted schema.table identifiers for all BaseStore SQL when a schema is configured.
  • Create the schema before the table when initializeSchema(true) is enabled.
  • Validate schema and table identifiers before including them in SQL.
  • Add unit tests for schema-qualified queries, schema initialization, and invalid schema names.

Testing:

  • mvn -q -pl agentscope-extensions/agentscope-extensions-postgresql -am -Dtest=PostgresBaseStoreTest -Dsurefire.failIfNoSpecifiedTests=false test
  • Result: 40 tests passed.

Checklist

  • Code formatting was verified by Spotless during the Maven build.
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions.
  • Related API documentation has been updated.
  • Code is ready for review.

Copilot AI review requested due to automatic review settings July 17, 2026 14:53

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

Adds optional PostgreSQL schema support to PostgresBaseStore while keeping the existing unqualified-table behavior when no schema is configured. This aligns PostgresBaseStore more closely with other PostgreSQL-backed stores in the extensions module and addresses #2192.

Changes:

  • Add PostgresBaseStore.Builder#schemaName(String) and build schema-qualified, quoted identifiers when configured.
  • Create the schema (if configured) before creating the table when initializeSchema(true) is enabled.
  • Add tests for schema-qualified SQL, schema initialization, and invalid schema names.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
agentscope-extensions/agentscope-extensions-postgresql/src/main/java/io/agentscope/extensions/postgresql/store/PostgresBaseStore.java Adds schema configuration, qualified table naming, schema creation on initialization, and shared identifier validation.
agentscope-extensions/agentscope-extensions-postgresql/src/test/java/io/agentscope/extensions/postgresql/store/PostgresBaseStoreTest.java Adds unit tests covering schema-qualified SQL usage, schema creation, and schema name validation.

Comment on lines +159 to +161
this.selectSql = String.format(SELECT_SQL, qualifiedTableName);
this.upsertSql = String.format(UPSERT_SQL, qualifiedTableName);
this.insertSql = String.format(INSERT_SQL, qualifiedTableName);

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.

@zouyx

zouyx commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

i think the problem the same as #2260

In #2260 , i have fixed in
agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentSubagentStreamEventsTest.java

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR adds optional PostgreSQL schema support to PostgresBaseStore while preserving backward compatibility when no schema is configured. The implementation is clean and well-structured: it introduces a schemaName builder parameter, properly validates identifiers to prevent SQL injection, and generates correctly-quoted schema-qualified table names ("schema"."table"). The test coverage is good, covering schema-qualified queries, schema initialization, and invalid identifier rejection. However, there's one concern about the ON CONFLICT SET clause behavior with schema-qualified names that should be verified against a real PostgreSQL database, as the current tests use mocks.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR adds optional PostgreSQL schema support to PostgresBaseStore while preserving backward compatibility when no schema is configured. The implementation is clean and well-structured: it introduces a schemaName builder parameter, properly validates identifiers to prevent SQL injection, and generates correctly-quoted schema-qualified table names ("schema"."table"). The test coverage is good, covering schema-qualified queries, schema initialization, and invalid identifier rejection. However, there's one concern about the ON CONFLICT SET clause behavior with schema-qualified names that should be verified against a real PostgreSQL database, as the current tests use mocks.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

zouyx and others added 2 commits July 18, 2026 14:12
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/ext/integration External protocols & middleware integrations labels Jul 18, 2026

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

This PR contains 205 lines of changes. Review in progress.


Automated review by github-manager-bot

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

Labels

area/ext/integration External protocols & middleware integrations bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:PostgresBaseStore中没有加入对应SCHEMA,对于同是扩展来说,PostgresAgentStateStore里面有对应的SCHEMA

5 participants