or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cockroachdb-support.mdindex.mdpostgresql-configuration.mdpostgresql-connection.mdpostgresql-database.mdpostgresql-parser.mdpostgresql-schema.md
tile.json

tessl/maven-org-flywaydb--flyway-database-postgresql

PostgreSQL database support module for Flyway migration tool with specialized implementations for PostgreSQL and CockroachDB databases

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.flywaydb/flyway-database-postgresql@11.8.x

To install, run

npx @tessl/cli install tessl/maven-org-flywaydb--flyway-database-postgresql@11.8.0

index.mddocs/

Flyway Database PostgreSQL

Flyway Database PostgreSQL provides specialized database support for PostgreSQL and CockroachDB databases in the Flyway migration framework. It extends Flyway's core functionality with database-specific implementations for connection management, schema handling, SQL parsing, and migration execution, enabling reliable database schema versioning and automated migrations in PostgreSQL environments.

Package Information

  • Package Name: flyway-database-postgresql
  • Package Type: maven
  • Group ID: org.flywaydb
  • Artifact ID: flyway-database-postgresql
  • Language: Java
  • Installation: Add to your Maven pom.xml:
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-database-postgresql</artifactId>
    <version>11.8.2</version>
</dependency>

For Gradle:

implementation 'org.flywaydb:flyway-database-postgresql:11.8.2'

Core Imports

import org.flywaydb.database.postgresql.PostgreSQLDatabaseType;
import org.flywaydb.database.postgresql.PostgreSQLDatabase;
import org.flywaydb.database.postgresql.PostgreSQLConnection;
import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;

For CockroachDB support:

import org.flywaydb.database.cockroachdb.CockroachDBDatabaseType;
import org.flywaydb.database.cockroachdb.CockroachDBDatabase;

Basic Usage

The package is automatically registered with Flyway through the service provider interface. When Flyway encounters a PostgreSQL JDBC URL, it automatically uses the appropriate database type:

import org.flywaydb.core.Flyway;

// Configure Flyway with PostgreSQL
Flyway flyway = Flyway.configure()
    .dataSource("jdbc:postgresql://localhost:5432/mydb", "user", "password")
    .locations("classpath:db/migration")
    .load();

// Migrate the database
flyway.migrate();

For CockroachDB:

Flyway flyway = Flyway.configure()
    .dataSource("jdbc:postgresql://localhost:26257/mydb", "root", "")
    .locations("classpath:db/migration")
    .load();

flyway.migrate();

Architecture

The package is built around several key components:

  • Database Type Registry: Automatic detection and instantiation of PostgreSQL/CockroachDB support
  • Connection Management: PostgreSQL-specific connection handling with advisory locking and role management
  • SQL Parser: PostgreSQL-specific SQL parsing supporting COPY operations, dollar quoting, and transaction control
  • Schema Operations: Full schema lifecycle management including cleaning, type management, and extension handling
  • Configuration Extensions: PostgreSQL-specific configuration options and environment variable mapping

Capabilities

PostgreSQL Database Support

Core PostgreSQL database implementation providing connection management, schema operations, and migration table creation.

public class PostgreSQLDatabaseType extends BaseDatabaseType {
    public String getName();
    public List<String> getSupportedEngines();
    public int getNullType();
    public boolean handlesJDBCUrl(String url);
    public String getDriverClass(String url, ClassLoader classLoader);
    public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection);
    public Database createDatabase(Configuration configuration, 
                                  JdbcConnectionFactory jdbcConnectionFactory, 
                                  StatementInterceptor statementInterceptor);
    public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext);
    public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader);
    public Properties getExternalAuthProperties(String url, String username);
}

public class PostgreSQLDatabase extends Database<PostgreSQLConnection> {
    public PostgreSQLDatabase(Configuration configuration, 
                             JdbcConnectionFactory jdbcConnectionFactory, 
                             StatementInterceptor statementInterceptor);
    public void ensureSupported(Configuration configuration);
    public String getRawCreateScript(Table table, boolean baseline);
    public boolean supportsDdlTransactions();
    public String getBooleanTrue();
    public String getBooleanFalse();
    public String doQuote(String identifier);
    public String getEscapedQuote();
    public boolean catalogIsSchema();
    public boolean useSingleConnection();
    public String getSelectStatement(Table table);
    public String getDatabaseHosting();
    protected String doGetCurrentUser() throws SQLException;
}

PostgreSQL Database Support

PostgreSQL Connection Management

PostgreSQL-specific connection implementation with role management, schema handling, and advisory locking.

public class PostgreSQLConnection extends Connection<PostgreSQLDatabase> {
    protected PostgreSQLConnection(PostgreSQLDatabase database, 
                                  java.sql.Connection connection);
    public Schema doGetCurrentSchema() throws SQLException;
    public void changeCurrentSchemaTo(Schema schema);
    public Schema getSchema(String name);
    public <T> T lock(Table table, Callable<T> callable);
    public boolean isAwsRds();
}

Connection Management

PostgreSQL SQL Parsing

Specialized SQL parser for PostgreSQL with support for COPY operations, dollar quoting, and transaction control.

public class PostgreSQLParser extends Parser {
    public PostgreSQLParser(Configuration configuration, ParsingContext parsingContext);
    protected char getAlternativeStringLiteralQuote();
    protected ParsedSqlStatement createStatement(PeekingReader reader, Recorder recorder,
        int statementPos, int statementLine, int statementCol, int nonCommentPartPos, 
        int nonCommentPartLine, int nonCommentPartCol, StatementType statementType, 
        boolean canExecuteInTransaction, Delimiter delimiter, String sql, 
        List<Token> tokens, boolean batchable) throws IOException;
}

SQL Parsing

PostgreSQL Schema Management

Schema operations including creation, cleanup, and management of PostgreSQL-specific objects.

public class PostgreSQLSchema extends Schema<PostgreSQLDatabase, PostgreSQLTable> {
    protected PostgreSQLSchema(JdbcTemplate jdbcTemplate, 
                              PostgreSQLDatabase database, String name);
    protected boolean doExists() throws SQLException;
    protected boolean doEmpty() throws SQLException;
    protected void doCreate() throws SQLException;
    protected void doDrop() throws SQLException;
    protected void doClean() throws SQLException;
    protected PostgreSQLTable[] doAllTables() throws SQLException;
}

Schema Management

Configuration Extensions

PostgreSQL-specific configuration options and environment variable mapping.

public class PostgreSQLConfigurationExtension implements ConfigurationExtension {
    public boolean isTransactionalLock();
    public void setTransactionalLock(boolean transactionalLock);
    public String getConfigurationParameterFromEnvironmentVariable(String environmentVariable);
    public String getNamespace();
}

Configuration

CockroachDB Support

Specialized support for CockroachDB databases with retry logic and version-specific features.

public class CockroachDBDatabaseType extends BaseDatabaseType {
    public String getName();
    public int getNullType();
    public boolean supportsReadOnlyTransactions();
    public boolean handlesJDBCUrl(String url);
    public int getPriority();
    public String getDriverClass(String url, ClassLoader classLoader);
    public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, 
                                                       String databaseProductVersion, 
                                                       Connection connection);
    public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);
    public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext);
    public DatabaseExecutionStrategy createExecutionStrategy(Connection connection);
    public ExecutionTemplate createTransactionalExecutionTemplate(Connection connection, boolean rollbackOnException);
    public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader);
    public Properties getExternalAuthProperties(String url, String username);
}

public class CockroachDBDatabase extends Database<CockroachDBConnection> {
    public CockroachDBDatabase(Configuration configuration, 
                              JdbcConnectionFactory jdbcConnectionFactory, 
                              StatementInterceptor statementInterceptor);
    public void ensureSupported(Configuration configuration);
    public String getRawCreateScript(Table table, boolean baseline);
    protected MigrationVersion determineVersion();
    boolean supportsSchemas();
    public boolean supportsDdlTransactions();
    public String getBooleanTrue();
    public String getBooleanFalse();
    public String doQuote(String identifier);
    public String getEscapedQuote();
    public boolean catalogIsSchema();
    public boolean useSingleConnection();
    protected String doGetCurrentUser() throws SQLException;
}

CockroachDB Support

Types

// Configuration model for transactional settings (Lombok @Data annotation provides getters/setters)
@Data
public class TransactionalModel {
    private Boolean lock = null;
}

// Common interfaces from Flyway core
interface Configuration {
    String getUrl();
    String getTablespace();
    // ... other configuration methods
}

interface JdbcConnectionFactory {
    // Factory for creating JDBC connections
}

interface StatementInterceptor {
    // Interceptor for SQL statement execution
}

interface ResourceProvider {
    // Provider for loading migration resources
}

interface ParsingContext {
    // Context information for SQL parsing
}

interface ExecutionTemplate {
    // Template for executing SQL statements
}

interface DatabaseExecutionStrategy {
    // Strategy for database operation execution
}

class Properties extends java.util.Properties {
    // Java Properties for connection configuration
}

class MigrationVersion {
    // Version information for database migrations
    public static MigrationVersion fromVersion(String version);
    public boolean isAtLeast(String version);
    public String getVersion();
}

interface Parser {
    // SQL statement parser interface
}

interface Connection {
    // JDBC connection wrapper
}