Class PostgreSQLMigrationRunner
- Namespace
- The.PostgreSQL.Schema
- Assembly
- Instagile.PostgreSQL.dll
Executes schema migrations against a PostgreSQL database. Handles control table creation and migration version tracking.
public sealed class PostgreSQLMigrationRunner : MigrationRunner<IDatabase>
- Inheritance
-
PostgreSQLMigrationRunner
- Inherited Members
Constructors
PostgreSQLMigrationRunner(IDatabase, QueryConfig?, ILogger<PostgreSQLMigrationRunner>?)
public PostgreSQLMigrationRunner(IDatabase database, QueryConfig? config = null, ILogger<PostgreSQLMigrationRunner>? logger = null)
Parameters
databaseIDatabaseconfigQueryConfigloggerILogger<PostgreSQLMigrationRunner>
Methods
CreateDbParameter(int, object)
Creates a PostgreSQL parameter which will match a positional placeholder ($1, $2, etc.).
protected override DbParameter CreateDbParameter(int number, object value)
Parameters
Returns
CreateDbParametersFor(MigrationRunnerOptions)
Creates parameters for migration runner options. PostgreSQL requires time zone conversion for DateTime → Instant transitions.
protected override DbParameter[] CreateDbParametersFor(MigrationRunnerOptions migrationParameters)
Parameters
migrationParametersMigrationRunnerOptions
Returns
ExecuteBatch(IDatabase, string, TimeSpan, DbParameter[])
Executes a migration batch, using NpgsqlBatch if the SQL contains multiple statements. This is necessary because PostgreSQL parameter binding doesn't work with semicolon-concatenated SQL.
protected override void ExecuteBatch(IDatabase db, string text, TimeSpan timeout, DbParameter[] parameters)
Parameters
dbIDatabasetextstringtimeoutTimeSpanparametersDbParameter[]
Remarks
DML is careful to execute only one statement at at a time; DDL, unfortunately, was designed to be written to .theSchema files and does not provide the same guarantee.
GetControlTableExists(IDatabase)
Checks if the migration control table exists in the PostgreSQL database.
protected override bool GetControlTableExists(IDatabase db)
Parameters
dbIDatabase
Returns
GetServerProperties(IDatabase)
Gets PostgreSQL server properties for migration decision-making.
protected override HashSet<string> GetServerProperties(IDatabase db)
Parameters
dbIDatabase
Returns
SplitBatch(string)
Splits a batch of SQL statements while respecting PostgreSQL dollar-quoted strings (\(...\) and \(tag\)...\(tag\)). This prevents splitting on semicolons that appear inside PL/pgSQL function bodies. Assumes dollar quotes appear at the start or end of lines (as generated by PostgreSQLTriggers).
public static IEnumerable<string> SplitBatch(string batchSql)
Parameters
batchSqlstring