This builder can be used to create a alter table query.

Implements

Constructors

Properties

#private: any

Methods

  • Calls the given function passing this as the only argument.

    See CreateTableBuilder.$call

    Type Parameters

    • T

    Parameters

    • func: ((qb) => T)
        • (qb): T
        • Parameters

          • qb: this

          Returns T

    Returns T

  • Parameters

    • constraintName: string
    • checkExpression: Expression<any>

    Returns AlterTableExecutor

  • See CreateTableBuilder.addForeignKeyConstraint

    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 per ALTER TABLE query.

    Parameters

    • constraintName: string
    • columns: string[]
    • targetTable: string
    • targetColumns: string[]

    Returns AlterTableAddForeignKeyConstraintBuilder

  • This can be used to add index to table.

    Examples

    db.schema.alterTable('person')
    .addIndex('person_email_index')
    .column('email')
    .unique()
    .execute()

    The generated SQL (MySQL):

    alter table `person` add unique index `person_email_index` (`email`)
    

    Parameters

    • indexName: string

    Returns AlterTableAddIndexBuilder

  • Parameters

    • constraintName: string
    • columns: string[]

    Returns AlterTableExecutor

  • Parameters

    • constraintName: string
    • columns: string[]
    • Optional build: UniqueConstraintNodeBuilderCallback

    Returns AlterTableExecutor

  • Parameters

    • constraintName: string

    Returns AlterTableDropConstraintBuilder

  • This can be used to drop index from table.

    Examples

    db.schema.alterTable('person')
    .dropIndex('person_email_index')
    .execute()

    The generated SQL (MySQL):

    alter table `person` drop index `test_first_name_index`
    

    Parameters

    • indexName: string

    Returns AlterTableExecutor

  • Parameters

    • newTableName: string

    Returns AlterTableExecutor

  • Parameters

    • newSchema: string

    Returns AlterTableExecutor