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.The new name for the table
An executor for the alter table query
setSchema
Sets the schema for the table.The new schema for the table
An executor for the alter table query
alterColumn
Alters a column in the table.The name of the column to alter
A callback that receives an AlterColumnBuilder and returns modifications
A builder for additional column alterations
dropColumn
Drops a column from the table.The name of the column to drop
A builder for additional column alterations
renameColumn
Renames a column.The current name of the column
The new name for the column
A builder for additional column alterations
addColumn
Adds a new column to the table.The name of the column to add
The data type of the column
Optional callback to configure the column definition
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.
The name of the column to modify
The new data type for the column
Optional callback to configure the column definition
A builder for additional column alterations
addUniqueConstraint
Adds a unique constraint for one or more columns. See CreateTableBuilder.addUniqueConstraint for more details.The name of the constraint
The columns to include in the unique constraint
Optional callback to configure the constraint
An executor for the alter table query
addCheckConstraint
Adds a check constraint. See CreateTableBuilder.addCheckConstraint for more details.The name of the constraint
The check expression
Optional callback to configure the constraint
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.
The name of the constraint
The columns in this table
The target table name
The columns in the target table
Optional callback to configure the constraint
A builder for the foreign key constraint
addPrimaryKeyConstraint
Adds a primary key constraint for one or more columns. See CreateTableBuilder.addPrimaryKeyConstraint for more details.The name of the constraint
The columns to include in the primary key
Optional callback to configure the constraint
An executor for the alter table query
dropConstraint
Drops a constraint from the table.The name of the constraint to drop
A builder for dropping constraints
renameConstraint
Renames a constraint.The current name of the constraint
The new name for the constraint
A builder for the constraint operation
addIndex
Adds an index to the table.The name of the index to add
A builder for creating the index
Examples
dropIndex
Drops an index from the table.The name of the index to drop
An executor for the alter table query
Examples
$call
Calls the given function passingthis as the only argument.
See CreateTableBuilder.$call for more details.
A function that receives the builder and returns a value
The return value of the provided function