Skip to content

PostgreSQL Loader Plugin

The PostgreSQL loader plugin transforms .sql files into JavaScript functions that Emigrate can use to execute the migrations. In the same package you can find the PostgreSQL Generator and the PostgreSQL Storage.

Installation

Terminal window
npm install @emigrate/postgres

Configuration

The PostgreSQL loader plugin can be configured either using environment variables or by configuring the plugin directly in the emigrate.config.js file.

Configuration file

emigrate.config.js
import { createPostgresLoader } from '@emigrate/postgres';
export default {
plugins: [
createPostgresLoader({
connection: { ... },
}),
],
};

Options

connection (required)

type: object | string

The connection options to use for connecting to the PostgreSQL database when the SQL statements from the migration files are executed. This can either be a connection URI or an object with connection options. For a list of supported connection options, see the postgres documentation.

Environment variables

The following environment variables are supported:

VariableDescriptionDefault
POSTGRES_URLThe full URI for connecting to a PostgreSQL database, e.g: "postgres://user:pass@127.0.0.1:3306/database"
POSTGRES_HOSTThe host on which the PostgreSQL server instance is running"localhost"
POSTGRES_USERThe PostgreSQL user account to use for the authentication
POSTGRES_PASSWORDThe PostgreSQL user password to use for the authentication
POSTGRES_PORTThe network port on which the PostgreSQL server is listening5432
POSTGRES_DBThe PostgreSQL database to use for the connection

The environment variables are used when the plugin is used using the --plugin command line option:

Terminal window
npx emigrate list --plugin postgres

Or when specifying the plugin in the emigrate.config.js file as a string:

emigrate.config.js
export default {
plugins: ['postgres'],
};