Skip to main content

branches

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

Overview

Namebranches
TypeResource
Idnetlify.database.branches

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
connection_stringstringThe connection string for the database branch
metadataobjectMetadata associated with the branch

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectsite_id, branch_idroleReturns the database branch connection string for a specific branch.
listselectsite_idReturns all branches for the site's database with compute status and metadata.
createinsertsite_id, branch_idCreates a new database branch. If a branch already exists for the specified branch ID, returns the existing connection string.
deletedeletesite_id, branch_idDeletes a database branch.
resetexecsite_id, branch_idforce, roleResets a non-production database branch by re-forking it from a source branch (defaults to the production branch). If the target branch is already in sync with the source, returns the existing connection string without performing a reset, unless force=true is passed. The production branch cannot be reset.

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
branch_idstringThe branch ID to reset
site_idstring
forcebooleanIf true, resets the branch even when it is already in sync with the source.
rolestringThe database role to use for the returned connection string. Defaults to netlifydb_owner if not specified.

SELECT examples

Returns the database branch connection string for a specific branch.

SELECT
connection_string,
metadata
FROM netlify.database.branches
WHERE site_id = '{{ site_id }}' -- required
AND branch_id = '{{ branch_id }}' -- required
AND role = '{{ role }}'
;

INSERT examples

Creates a new database branch. If a branch already exists for the specified branch ID, returns the existing connection string.

INSERT INTO netlify.database.branches (
parent_branch_id,
branch_id,
metadata,
site_id
)
SELECT
'{{ parent_branch_id }}',
'{{ branch_id }}' /* required */,
'{{ metadata }}',
'{{ site_id }}'
RETURNING
connection_string,
metadata
;

DELETE examples

Deletes a database branch.

DELETE FROM netlify.database.branches
WHERE site_id = '{{ site_id }}' --required
AND branch_id = '{{ branch_id }}' --required
;

Lifecycle Methods

Resets a non-production database branch by re-forking it from a source branch (defaults to the production branch). If the target branch is already in sync with the source, returns the existing connection string without performing a reset, unless force=true is passed. The production branch cannot be reset.

EXEC netlify.database.branches.reset
@site_id='{{ site_id }}' --required,
@branch_id='{{ branch_id }}' --required,
@force={{ force }},
@role='{{ role }}'
@@json=
'{
"source_branch_id": "{{ source_branch_id }}"
}'
;