Skip to content

Conversation

tengfei8771
Copy link

Enhance the behavior of obtaining default schema through database connection string by specifying the default schema through the SearchPath parameter in the connection string

droyad and others added 3 commits March 3, 2025 14:23
* Add NpgsqlDataSource support to PostgresqlConnectionManager

* Used new GHA workflows

* Updated to dbup-core 6.0 beta, targeted netstandard2 and update Npgsql reference

* Bump to the next beta of dbup-core

* Merge fix

* Removed stray #If

* fix: #680 PostgreSQL statements split implemented (DbUp#19)

* fix: #680 PostgreSQL statements split implemented



Co-authored-by: shokurov <[email protected]>

* Updated approval file

---------

Co-authored-by: shokurov <[email protected]>
Co-authored-by: Robert Wagner <[email protected]>

* Update of libs

* File scoped namespaces and primary ctors

* Target `net8` so we can use the latest version of Npgsql (DbUp#24)

* Target net8 so we can use the latest version of Npgsql

* Used new APIs

* Added Npgsql licence information (DbUp#25)

* fix(DbUp#26): avoid NullReferenceException when creating database (DbUp#27)

* fix(DbUp#26): avoid NullReferenceException when creating database

* Updated approval file

---------

Co-authored-by: Robert Wagner <[email protected]>

* fix: fix delimiter parsing (DbUp#28)

* Lowered Connection string printing to debug, resolves DbUp#30

---------

Co-authored-by: Sébastien Crocquesel <[email protected]>
Co-authored-by: Campbell Harding-Deason <[email protected]>
Co-authored-by: shokurov <[email protected]>
Co-authored-by: nvierge-addactis <[email protected]>
…nection string by specifying the default schema through the SearchPath parameter in the connection string
@tengfei8771 tengfei8771 changed the base branch from main to release/6.0.0 April 23, 2025 08:31
@@ -15,6 +16,7 @@
/// </summary>
public static class PostgresqlExtensions
{
private static readonly string pattern= @"(?i)SearchPath=([^;]+)";
Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://www.postgresql.org/docs/current/ddl-schemas.html

Default search path would be:

"$user", public

Normally to customize search path one would use:

SET search_path TO myschema,public;

In both cases search path contains multiple schemas delimited by comma.

This regex does not seem to respect multiple schemas in search path?

Copy link
Author

Choose a reason for hiding this comment

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

This method only processes connection strings and does not support this parameter like 'search_path' in connection strings. If this parameter is not set, the database will default to reading public

@@ -15,6 +16,7 @@
/// </summary>
public static class PostgresqlExtensions
{
private static readonly string pattern= @"(?i)SearchPath=([^;]+)";
Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://www.npgsql.org/doc/connection-string-parameters.html parameter should be named "Search Path" and not "SearchPath"?

Copy link
Author

Choose a reason for hiding this comment

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

Common connection strings, like this
"Server=xxxx;Port=xxx;Database=xxx;User Id=xxxx;Password=xxxx;Pooling=false;Search Path=xxxx;IncludeErrorDetail=true;"
The schema parameters support SearchPath and Search Path and ignore case.
I modified the regular expression to support the above parameter types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants