Skip to content

PostgreSQL schema not working #2705

@Ryszard-Trojnacki

Description

@Ryszard-Trojnacki

Expected behavior

Setting schema schould make effect on database connection:

databaseConfig.setDbSchema("test1");

https://ebean.io/docs/database/postgres/#schema

Actual behavior

Setting databaseConfig.setDbSchema("test1") does nothing, schema is public.

Comment

I have checked source code and is seems, that Ebean is setting property schema but Postgresql uses currentSchema.
Setting ?currentSchema=test in URL solves this problem.

Source code from PostgreSQL JDBC driver ConnectionFactoryImpl.java:

  private List<String[]> getParametersForStartup(String user, String database, Properties info) {
....
    String currentSchema = PGProperty.CURRENT_SCHEMA.get(info);
    if (currentSchema != null) {
      paramList.add(new String[]{"search_path", currentSchema});
    }
....
}

And PGProperty.java:

  CURRENT_SCHEMA(
      "currentSchema",
      null,
      "Specify the schema (or several schema separated by commas) to be set in the search-path"),

I think, that ConnectionPool.java should be changed from:

    final String schema = params.getSchema();
    if (schema != null) {
      this.connectionProps.setProperty("schema", schema);
    }

to:

    final String schema = params.getSchema();
    if (schema != null) {
      this.connectionProps.setProperty("currentSchema", schema);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions