Skip to content

savepoint.rollback()

Oxford Harrison edited this page Nov 15, 2024 · 5 revisions

DOCSAPISavepoint API


Perform a rollback.

See related ➞ savepoint.recommit()

Syntax

savepoint.rollback(
    options?: RollbackOptions
): Promise<boolean>;
Param Interfaces Description
options? RollbackOptions Optional extra parameters for the operation.

RollbackOptions

type RollbackOptions = {
    desc?: string;
    ref?: string;
};
Param Interfaces Description
desc? - A string description of the rollback operation.
ref? - A means of identification of the rollback operator for audit purposes. Can be any agreed-upon identifier; e.g. email, some username or profile URL, etc. Defaults to the global ClientOptions.commitRef.

Usage

Create savepoints:

// Perform a DDL operation and obtain savepoint (1)
const savepoint1 = await client.createDatabase(
    {
        name: 'database_1',
        tables: [{
            name: 'table_1',
            columns: [],
        }]
    },
    { returning: 'savepoint' }
);
// Perform a DDL operation and obtain savepoint (2)
const savepoint2 = await client.database('database_1').createTable(
    {
        name: 'table_2',
        columns: [],
    },
    { returning: 'savepoint' }
);

Rollback all changes (latest-first):

// Rollback to version 1 (drops table)
await savepoint2.rollback({
    desc: 'Changes no more necessary'
});
// Rollback to version 0 (drops database)
await savepoint1.rollback({
    desc: 'Changes no more necessary'
});
Clone this wiki locally