-
-
Notifications
You must be signed in to change notification settings - Fork 2
database.alterTable()
Oxford Harrison edited this page Nov 11, 2024
·
7 revisions
DOCS • API • Database API
Programmatically perform an ALTER TABLE
operation.
See ➞ ALTER TABLE
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. |
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. |
Change table name:
// Change DB name
const savepoint = await database.alterTable(
'table_1',
(tableSchema) => {
tableSchema.name('table_1_new');
},
{ desc: 'Renaming for testing purposes' }
);