MySQL Storage
The MySQL storage plugin uses a MySQL database to store the migration history (duh). In the same package you can find the MySQL Loader and the MySQL Generator.
Installation
npm install @emigrate/mysql
pnpm add @emigrate/mysql
yarn add @emigrate/mysql
bun add @emigrate/mysql
{ "dependencies": { "@emigrate/mysql": "*" }}
Configuration
The MySQL storage can be configured either using environment variables or by configuring the plugin directly in the emigrate.config.js
file.
Configuration file
import { createMysqlStorage } from '@emigrate/mysql';
export default { storage: createMysqlStorage({ table: 'migrations', connection: { ... }, }),};
Options
table
type: string
default: "migrations"
The name of the table to use for storing the migrations.
connection
(required)
type: object | string
The connection options to use for connecting to the MySQL database. This can either be a connection URI or an object with connection options. For a list of supported connection options, see the mysql documentation.
Environment variables
The following environment variables are supported:
Variable | Description | Default |
---|---|---|
MYSQL_TABLE | The name of the table to use for storing the migrations | "migrations" |
MYSQL_URL | The full URI for connecting to a MySQL database, e.g: "mysql://user:pass@127.0.0.1:3306/database" | |
MYSQL_HOST | The host on which the MySQL server instance is running | "localhost" |
MYSQL_USER | The MySQL user account to use for the authentication | |
MYSQL_PASSWORD | The MySQL user password to use for the authentication | |
MYSQL_PORT | The network port on which the MySQL server is listening | 3306 |
MYSQL_DATABASE | The MySQL database to use for the connection |
The environment variables are used when the storage plugin is used using the --storage
command line option:
npx emigrate list --storage mysql
Or when specifying the storage in the emigrate.config.js
file as a string:
export default { storage: 'mysql',};