Skip to content

client.alterDatabase()

Oxford Harrison edited this page Nov 9, 2024 · 12 revisions

Programmatically perform an ALTER DATABASE operation.

Syntax

client.alterDatabase(
    alterSpec: string | { name: string, tables?: string[] },
    callback: (databaseSchema: DatabaseSchemaAPI) => void,
    options?: QueryOptions
): Promise<Savepoint | boolean>;
Param Type Description
alterSpec string or object A database name, or an object specifying the name and, optionally, a list of tables to be included in the retrieved database schema instance.
callback function A callback function that recieves the requested schema. This can be async.
options QueryOptions Standard QueryOptions.

Return Value

  • Savepoint | boolean: a Savepoint instance (See ➞ Savepoint) or the boolean true when savepoint creation has been disabled via options.noCreateSavepoint; (Compare ➞ Query Return Value)

Usage

Specify database by name:

const savepoint = await client.alterDatabase(
    'database_1',
    (databaseSchema) => {
        databaseSchema.name('database_1_new');
    },
    { desc: 'Renaming for testing purposes' }
);

or by an object, with an optional list of tables to be altered along with it:

const savepoint = await client.alterDatabase(
    { name: 'database_1', tables: ['table_1'] },
    (databaseSchema) => {
        databaseSchema.name('database_1_new');
        databaseSchema.table('table_1').column('column_1').name('column_1_new');
        databaseSchema.table('table_1').column('column_2').type('varchar');
    }, 
    { desc: 'Renaming for testing purposes' }
);
Clone this wiki locally