Skip to content

Support configurable MultiStatementEnabled for PostgreSQL migrations #284

@ClaraTersi

Description

@ClaraTersi

Problem

The PostgresConnection.Connect() method has MultiStatementEnabled: true hardcoded when creating the
golang-migrate driver:

primaryDriver, err := postgres.WithInstance(dbPrimary, &postgres.Config{
    MultiStatementEnabled: true,  // hardcoded
    DatabaseName:          pc.PrimaryDBName,
    SchemaName:            "public",
})

This prevents consumers from controlling whether migrations run with multi-statement mode enabled or disabled.

Proposal

Add a MultiStatementEnabled *bool field to PostgresConnection struct:

type PostgresConnection struct {
    // ... existing fields ...
    MultiStatementEnabled *bool  // nil = default true (backward compatible)
}

Update Connect() to use the field with default true:

multiStmtEnabled := true
if pc.MultiStatementEnabled != nil {
    multiStmtEnabled = *pc.MultiStatementEnabled
}

Usage example

type Config struct {
    // ... other fields ...

    // PostgreSQL migration settings
    MultiStatementEnabled *bool `env:"DB_MULTI_STATEMENT_ENABLED"`
}

postgresConnection := &libPostgres.PostgresConnection{
    ConnectionStringPrimary: connStr,
    // ... other fields ...
    MultiStatementEnabled:   cfg.MultiStatementEnabled,  // nil = defaults to true
}

Why pointer?

Using *bool instead of bool allows distinguishing between:

  • nil → not configured, use default true
  • &true → explicitly enabled
  • &false → explicitly disabled

Backward Compatibility

  • Default behavior unchanged (true)
  • No breaking changes to existing consumers
  • Field is optional

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions