Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/dbup-postgresql/PostgresqlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Data;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -165,6 +165,13 @@ public static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase s
PostgresqlDatabase(supported, connectionString, logger, new PostgresqlConnectionOptions());
}

/// <summary>
/// Ensures that the database specified in the connection string exists using SSL for the connection.
/// </summary>
/// <param name="supported">Fluent helper type.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="logger">The <see cref="DbUp.Engine.Output.IUpgradeLog"/> used to record actions.</param>
/// <param name="certificate">Certificate for securing connection.</param>
public static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase supported, string connectionString, IUpgradeLog logger, X509Certificate2 certificate)
{
var options = new PostgresqlConnectionOptions
Expand All @@ -174,6 +181,13 @@ public static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase s
PostgresqlDatabase(supported, connectionString, logger, options);
}

/// <summary>
/// Ensures that the database specified in the connection string exists using SSL for the connection.
/// </summary>
/// <param name="supported">Fluent helper type.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="logger">The <see cref="DbUp.Engine.Output.IUpgradeLog"/> used to record actions.</param>
/// <param name="connectionOptions">Connection options to set SSL parameters</param>
public static void PostgresqlDatabase(
this SupportedDatabasesForEnsureDatabase supported,
string connectionString,
Expand Down Expand Up @@ -292,6 +306,13 @@ public static void PostgresqlDatabase(this SupportedDatabasesForDropDatabase sup
PostgresqlDatabase(supported, connectionString, logger, new PostgresqlConnectionOptions());
}

/// <summary>
/// Drops the database specified in the connection string if it exists using SSL for the connection.
/// </summary>
/// <param name="supported">Fluent helper type.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="logger">The <see cref="DbUp.Engine.Output.IUpgradeLog"/> used to record actions.</param>
/// <param name="certificate">Certificate for securing connection.</param>
public static void PostgresqlDatabase(this SupportedDatabasesForDropDatabase supported, string connectionString, IUpgradeLog logger, X509Certificate2 certificate)
{
var options = new PostgresqlConnectionOptions
Expand All @@ -301,6 +322,13 @@ public static void PostgresqlDatabase(this SupportedDatabasesForDropDatabase sup
PostgresqlDatabase(supported, connectionString, logger, options);
}

/// <summary>
/// Drops the database specified in the connection string if it exists using SSL for the connection.
/// </summary>
/// <param name="supported">Fluent helper type.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="logger">The <see cref="DbUp.Engine.Output.IUpgradeLog"/> used to record actions.</param>
/// <param name="connectionOptions">Connection options to set SSL parameters</param>
public static void PostgresqlDatabase(
this SupportedDatabasesForDropDatabase supported,
string connectionString,
Expand Down
5 changes: 4 additions & 1 deletion src/dbup-postgresql/PostgresqlObjectParser.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using DbUp.Support;
using DbUp.Support;

namespace DbUp.Postgresql;

/// <summary>
/// Parses Sql Objects and performs quoting functions.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="PostgresqlObjectParser"/> class.
/// </remarks>
public class PostgresqlObjectParser() : SqlObjectParser("\"", "\"");
12 changes: 7 additions & 5 deletions src/dbup-postgresql/PostgresqlScriptExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using DbUp.Engine;
using DbUp.Engine.Output;
Expand All @@ -25,12 +25,14 @@ public class PostgresqlScriptExecutor : ScriptExecutor
public PostgresqlScriptExecutor(Func<IConnectionManager> connectionManagerFactory, Func<IUpgradeLog> log, string schema, Func<bool> variablesEnabled,
IEnumerable<IScriptPreprocessor> scriptPreprocessors, Func<IJournal> journalFactory)
: base(connectionManagerFactory, new PostgresqlObjectParser(), log, schema, variablesEnabled, scriptPreprocessors, journalFactory)
{
}
{
}

protected override string GetVerifySchemaSql(string schema) => $"CREATE SCHEMA IF NOT EXISTS {schema}";
/// <inheritdoc/>
protected override string GetVerifySchemaSql(string schema) => $"CREATE SCHEMA IF NOT EXISTS {schema}";

protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScript script, Action executeCommand)
/// <inheritdoc/>
protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScript script, Action executeCommand)
{
try
{
Expand Down
12 changes: 8 additions & 4 deletions src/dbup-postgresql/PostgresqlTableJournal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Data;
using DbUp.Engine;
using DbUp.Engine.Output;
Expand All @@ -22,10 +22,11 @@ public class PostgresqlTableJournal : TableJournal
/// <param name="tableName">The name of the journal table.</param>
public PostgresqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string tableName)
: base(connectionManager, logger, new PostgresqlObjectParser(), schema, tableName)
{
}
{
}

protected override IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
/// <inheritdoc/>
protected override IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
{
// EnableSqlRewriting is enabled by default, and needs to be explicitly disabled
bool enableSqlRewriting = !AppContext.TryGetSwitch("Npgsql.EnableSqlRewriting", out bool enabled) || enabled;
Expand All @@ -49,16 +50,19 @@ protected override IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandF
return command;
}

/// <inheritdoc/>
protected override string GetInsertJournalEntrySql(string scriptName, string applied)
{
return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({scriptName}, {applied})";
}

/// <inheritdoc/>
protected override string GetJournalEntriesSql()
{
return $"select ScriptName from {FqSchemaTableName} order by ScriptName";
}

/// <inheritdoc/>
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName)
{
return
Expand Down
3 changes: 2 additions & 1 deletion src/dbup-postgresql/dbup-postgresql.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>DbUp makes it easy to deploy and upgrade SQL Server databases. This package adds PostgreSQL support.</Description>
Expand All @@ -14,6 +14,7 @@
<SignAssembly>true</SignAssembly>
<RepositoryUrl>https://github.com/DbUp/dbup-postgresql.git</RepositoryUrl>
<PackageIcon>dbup-icon.png</PackageIcon>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(CI)' == 'true'">
Expand Down