AlterTableBuilder class is used to construct ALTER TABLE queries. It provides a fluent API for modifying tables, adding or dropping columns, and managing constraints.
Methods
renameTo
Renames the table.string
required
The new name for the table
AlterTableExecutor
An executor for the alter table query
setSchema
Sets the schema for the table.string
required
The new schema for the table
AlterTableExecutor
An executor for the alter table query
alterColumn
Alters a column in the table.string
required
The name of the column to alter
AlterColumnBuilderCallback
required
A callback that receives an AlterColumnBuilder and returns modifications
AlterTableColumnAlteringBuilder
A builder for additional column alterations
dropColumn
Drops a column from the table.string
required
The name of the column to drop
AlterTableColumnAlteringBuilder
A builder for additional column alterations
renameColumn
Renames a column.string
required
The current name of the column
string
required
The new name for the column
AlterTableColumnAlteringBuilder
A builder for additional column alterations
addColumn
Adds a new column to the table.string
required
The name of the column to add
DataTypeExpression
required
The data type of the column
ColumnDefinitionBuilderCallback
Optional callback to configure the column definition
AlterTableColumnAlteringBuilder
A builder for additional column alterations
modifyColumn
Creates anALTER TABLE MODIFY COLUMN query.
The MODIFY COLUMN statement is only implemented by MySQL and Oracle. On other databases you should use the alterColumn method.
string
required
The name of the column to modify
DataTypeExpression
required
The new data type for the column
ColumnDefinitionBuilderCallback
Optional callback to configure the column definition
AlterTableColumnAlteringBuilder
A builder for additional column alterations
addUniqueConstraint
Adds a unique constraint for one or more columns. See CreateTableBuilder.addUniqueConstraint for more details.string
required
The name of the constraint
string[]
required
The columns to include in the unique constraint
UniqueConstraintNodeBuilderCallback
Optional callback to configure the constraint
AlterTableExecutor
An executor for the alter table query
addCheckConstraint
Adds a check constraint. See CreateTableBuilder.addCheckConstraint for more details.string
required
The name of the constraint
Expression<any>
required
The check expression
CheckConstraintBuilderCallback
Optional callback to configure the constraint
AlterTableExecutor
An executor for the alter table query
addForeignKeyConstraint
Adds a foreign key constraint. Unlike CreateTableBuilder.addForeignKeyConstraint, this method returns the constraint builder and doesn’t take a callback as the last argument. This is because you can only add one column perALTER TABLE query.
string
required
The name of the constraint
string[]
required
The columns in this table
string
required
The target table name
string[]
required
The columns in the target table
ForeignKeyConstraintBuilderCallback
Optional callback to configure the constraint
AlterTableAddForeignKeyConstraintBuilder
A builder for the foreign key constraint
addPrimaryKeyConstraint
Adds a primary key constraint for one or more columns. See CreateTableBuilder.addPrimaryKeyConstraint for more details.string
required
The name of the constraint
string[]
required
The columns to include in the primary key
PrimaryKeyConstraintBuilderCallback
Optional callback to configure the constraint
AlterTableExecutor
An executor for the alter table query
dropConstraint
Drops a constraint from the table.string
required
The name of the constraint to drop
AlterTableDropConstraintBuilder
A builder for dropping constraints
renameConstraint
Renames a constraint.string
required
The current name of the constraint
string
required
The new name for the constraint
AlterTableDropConstraintBuilder
A builder for the constraint operation
addIndex
Adds an index to the table.string
required
The name of the index to add
AlterTableAddIndexBuilder
A builder for creating the index
Examples
dropIndex
Drops an index from the table.string
required
The name of the index to drop
AlterTableExecutor
An executor for the alter table query
Examples
$call
Calls the given function passingthis as the only argument.
See CreateTableBuilder.$call for more details.
(qb: this) => T
required
A function that receives the builder and returns a value
T
The return value of the provided function