Skip to main content

migrations

Creates, updates, deletes, gets or lists a migrations resource.

Overview​

Namemigrations
TypeResource
Idnetlify.database.migrations

Fields​

The following fields are returned by SELECT queries:

NameDatatypeDescription
namestringThe migration name
contentstringThe raw contents of the migration file
pathstringThe path to the migration file in the deploy bundle
versioninteger (int64)The migration version number

Methods​

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectsite_id, namebranchReturns the contents of a named migration for the specified branch.
listselectsite_idbranchReturns the list of migrations available for the specified branch, indicating which ones have been applied to the database.
runexecsite_id, deploy_idRuns database migrations for the specified deploy. Finds the deploy and determines the appropriate branch.

Parameters​

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
deploy_idstringThe deploy ID to run migrations for
namestringThe migration name
site_idstring
branchstringThe branch ID to list migrations for. Defaults to "production" if not specified.

SELECT examples​

Returns the contents of a named migration for the specified branch.

SELECT
name,
content,
path,
version
FROM netlify.database.migrations
WHERE site_id = '{{ site_id }}' -- required
AND name = '{{ name }}' -- required
AND branch = '{{ branch }}'
;

Lifecycle Methods​

Runs database migrations for the specified deploy. Finds the deploy and determines the appropriate branch.

EXEC netlify.database.migrations.run
@site_id='{{ site_id }}' --required,
@deploy_id='{{ deploy_id }}' --required
@@json=
'{
"dry_run": {{ dry_run }}
}'
;