Netlify CLI database command
database
Section titled “database”Provision a production ready Postgres database with a single command
Usage
netlify databaseFlags
filter(string) - For monorepos, specify the name of the application to run the command indebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
| Subcommand | description |
|---|---|
database status | Check the status of the database, including applied and pending migrations |
database init | Interactive setup: install the package, scaffold a starter migration, and verify the database |
database connect | Connect to the database |
database reset | Reset the local development database, removing all data and tables |
database migrations | Manage database migrations |
Examples
netlify database statusnetlify database migrations applynetlify database migrations pullnetlify database migrations newnetlify database resetdatabase status
Section titled “database status”Check the status of the database, including applied and pending migrations
Usage
netlify database statusFlags
branch(string) - Netlify branch name to query; defaults to the local development databasejson(boolean) - Output result as JSONshow-credentials(boolean) - Include the full connection string (including username and password) in the outputdebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
Examples
netlify database statusnetlify database status --show-credentialsnetlify database status --jsonnetlify database status --branch my-feature-branchdatabase init
Section titled “database init”Interactive setup: install the package, scaffold a starter migration, and verify the database
Usage
netlify database initFlags
filter(string) - For monorepos, specify the name of the application to run the command inyes(boolean) - Non-interactive mode. Accepts the defaults for every prompt.debug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
Examples
netlify database initnetlify database init --yesdatabase connect
Section titled “database connect”Connect to the database
Usage
netlify database connectFlags
filter(string) - For monorepos, specify the name of the application to run the command injson(boolean) - Output query results as JSON. When used without —query, prints the connection details as JSON instead.query(string) - Execute a single query and exitdebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
Examples
netlify database connectnetlify database connect --query "SELECT * FROM users"netlify database connect --json --query "SELECT * FROM users"netlify database connect --jsondatabase reset
Section titled “database reset”Reset the local development database, removing all data and tables
Usage
netlify database resetFlags
filter(string) - For monorepos, specify the name of the application to run the command injson(boolean) - Output result as JSONdebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
database migrations
Section titled “database migrations”Manage database migrations
Usage
netlify database migrationsFlags
filter(string) - For monorepos, specify the name of the application to run the command indebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
| Subcommand | description |
|---|---|
database migrations apply | Apply database migrations to the local development database |
database migrations new | Create a new migration |
database migrations pull | Pull migrations and overwrite local migration files |
database migrations reset | Delete local migration files that have not been applied yet |
database migrations apply
Section titled “database migrations apply”Apply database migrations to the local development database
Usage
netlify database migrations applyFlags
filter(string) - For monorepos, specify the name of the application to run the command injson(boolean) - Output result as JSONto(string) - Target migration name or prefix to apply up to (applies all if omitted)debug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
database migrations new
Section titled “database migrations new”Create a new migration
Usage
netlify database migrations newFlags
description(string) - Purpose of the migration (used to generate the file name)filter(string) - For monorepos, specify the name of the application to run the command injson(boolean) - Output result as JSONscheme(sequential | timestamp) - Numbering scheme for migration prefixesdebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
Examples
netlify database migrations newnetlify database migrations new --description "add users table" --scheme sequentialdatabase migrations pull
Section titled “database migrations pull”Pull migrations and overwrite local migration files
Usage
netlify database migrations pullFlags
branch(string) - Pull migrations for a specific branch (defaults to ‘production’; pass —branch with no value to use local git branch)filter(string) - For monorepos, specify the name of the application to run the command inforce(boolean) - Skip confirmation promptdebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging injson(boolean) - Output result as JSON
Examples
netlify database migrations pullnetlify database migrations pull --branch stagingnetlify database migrations pull --branchnetlify database migrations pull --forcedatabase migrations reset
Section titled “database migrations reset”Delete local migration files that have not been applied yet
Usage
netlify database migrations resetFlags
branch(string) - Target a remote preview branch instead of the local development databasefilter(string) - For monorepos, specify the name of the application to run the command injson(boolean) - Output result as JSONdebug(boolean) - Print debugging informationauth(string) - Netlify auth token - can be used to run this command without logging in
Examples
netlify database migrations resetnetlify database migrations reset --branch my-feature-branch