MD_GET_DIVE_VERSION
Returns a single version of a Dive, including its component code. Use this to read the code that was live at an earlier point, or to restore it by passing it back to MD_UPDATE_DIVE_CONTENT.
Syntax
SELECT * FROM MD_GET_DIVE_VERSION(
id := '<dive_id>',
version := <n>
);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | UUID | Yes | Identifier of the Dive. |
version | UINTEGER | Yes | The version to fetch. Version numbers start at 1 and increment on each content update. |
Return columns
| Column | Type | Description |
|---|---|---|
id | UUID | Identifier of the version (not the Dive). |
version | UINTEGER | The version number. |
storage_url | VARCHAR | Internal storage location of the version's content. |
description | VARCHAR | Description attached to the version, or NULL. |
created_at | TIMESTAMP WITH TIME ZONE | When the version was created. |
api_version | UINTEGER | Dive API version of the content. |
required_resources | LIST(STRUCT(name VARCHAR, alias VARCHAR, url VARCHAR, id UUID, resource_type VARCHAR)) | Databases and shares this version queries. |
content | VARCHAR | The JSX/React source of this version. |
Examples
Read the first version's code:
SELECT version, content
FROM MD_GET_DIVE_VERSION(
id := '80000000-0000-0000-0000-000000000001',
version := 1
);
Roll back by republishing an older version's content. Function arguments accept literals and getvariable() calls, but not subqueries or lateral column references. Store the old content in a SQL variable, then pass it back with getvariable():
-- Step 1: read the content to restore into a SQL variable
SET VARIABLE rollback_content = (
SELECT content
FROM MD_GET_DIVE_VERSION(id := '<dive_id>', version := 2)
);
-- Step 2: republish it as a new version
SELECT version
FROM MD_UPDATE_DIVE_CONTENT(
id := '<dive_id>',
content := getvariable('rollback_content'),
description := 'Roll back to version 2'
);
Related
MD_LIST_DIVE_VERSIONS— List all versions of a Dive.MD_GET_DIVE— Fetch the latest version and summary in one call.