-
Notifications
You must be signed in to change notification settings - Fork 13
Enhance the behavior of obtaining default schema through database con… #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/6.0.0
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using System; | ||
using System.Data; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text.RegularExpressions; | ||
using DbUp; | ||
using DbUp.Builder; | ||
using DbUp.Engine.Output; | ||
|
@@ -15,6 +16,7 @@ | |
/// </summary> | ||
public static class PostgresqlExtensions | ||
{ | ||
private static readonly string pattern= @"(?i)SearchPath=([^;]+)"; | ||
|
||
/// <summary> | ||
/// Creates an upgrader for PostgreSQL databases. | ||
/// </summary> | ||
|
@@ -24,8 +26,21 @@ public static class PostgresqlExtensions | |
/// A builder for a database upgrader designed for PostgreSQL databases. | ||
/// </returns> | ||
public static UpgradeEngineBuilder PostgresqlDatabase(this SupportedDatabases supported, string connectionString) | ||
=> PostgresqlDatabase(supported, connectionString, null); | ||
|
||
=> PostgresqlDatabase(supported, connectionString, GetDefaultSchemaByConnectionString(connectionString)); | ||
/// <summary> | ||
/// Get connection string use parameter SearchPath for defaultSchema | ||
/// </summary> | ||
/// <param name="connectionString">PostgreSQL database connection string.</param> | ||
/// <returns></returns> | ||
private static string GetDefaultSchemaByConnectionString(string connectionString) | ||
{ | ||
Match match = Regex.Match(connectionString, pattern); | ||
if (match.Success) | ||
{ | ||
return match.Groups[1].Value; | ||
} | ||
return null; | ||
} | ||
/// <summary> | ||
/// Creates an upgrader for PostgreSQL databases. | ||
/// </summary> | ||
|
There was a problem hiding this comment.
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:
Normally to customize search path one would use:
In both cases search path contains multiple schemas delimited by comma.
This regex does not seem to respect multiple schemas in search path?
There was a problem hiding this comment.
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