Skip to content

database.alterTable()

Oxford Harrison edited this page Nov 11, 2024 · 7 revisions

DOCSAPIDatabase API


Programmatically perform an ALTER TABLE operation.

See ➞ ALTER TABLE

Syntax

database.alterTable(
    alterSpec: string,
    callback: (tableSchema: TableSchemaAPI) => void,
    options?: AlterOptions
): Promise<DDLResult>;
Param Interfaces Description
alterSpec - A table name.
callback TableSchemaAPI A callback function that recieves the requested schema. This can be async.
options? AlterOptions Optional extra parameters for the query.
Interface Description
DDLResult The result type for DDL operations.

AlterOptions

type AlterOptions = {
    cascadeRule?: boolean;
    existsChecks?: boolean;
} & QueryOptions;
Param Interfaces Description
cascadeRule - A flag that adds CASCADE flags to subtree manipulations. Defaults to false. (See ➞ ALTER TABLE ➞ Managing Columns)
existsChecks - A flag that adds EXISTS checks to subtree manipulations. Defaults to false. (See ➞ ALTER TABLE ➞ Managing columns)
Interface Description
QueryOptions Inherited options.

Usage

Change table name:

// Change DB name
const savepoint = await database.alterTable(
    'table_1',
    (tableSchema) => {
        tableSchema.name('table_1_new');
    },
    { desc: 'Renaming for testing purposes' }
);
Clone this wiki locally