migrations
Creates, updates, deletes, gets or lists a migrations resource.
Overview
| Name | migrations |
| Type | Resource |
| Id | netlify.database.migrations |
Fields
The following fields are returned by SELECT queries:
- get
- list
| Name | Datatype | Description |
|---|---|---|
name | string | The migration name |
content | string | The raw contents of the migration file |
path | string | The path to the migration file in the deploy bundle |
version | integer (int64) | The migration version number |
| Name | Datatype | Description |
|---|---|---|
name | string | The migration name |
applied | boolean | Whether this migration has been applied to the branch |
path | string | The path to the migration file in the deploy bundle |
version | integer (int64) | The migration version number |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get | select | site_id, name | branch | Returns the contents of a named migration for the specified branch. |
list | select | site_id | branch | Returns the list of migrations available for the specified branch, indicating which ones have been applied to the database. |
run | exec | site_id, deploy_id | Runs 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.
| Name | Datatype | Description |
|---|---|---|
deploy_id | string | The deploy ID to run migrations for |
name | string | The migration name |
site_id | string | |
branch | string | The branch ID to list migrations for. Defaults to "production" if not specified. |
SELECT examples
- get
- list
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 }}'
;
Returns the list of migrations available for the specified branch, indicating which ones have been applied to the database.
SELECT
name,
applied,
path,
version
FROM netlify.database.migrations
WHERE site_id = '{{ site_id }}' -- required
AND branch = '{{ branch }}'
;
Lifecycle Methods
- run
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 }}
}'
;