Skip to main content

alterEnumColumn

@quik/database


@quik/database / alterEnumColumn

Function: alterEnumColumn()

alterEnumColumn(engine, options): Promise<void>

Defined in: database/src/migrations/utils/enum.ts:72

Alters the allowed value set of an existing enum column, using a dialect-appropriate strategy.

Postgres has no ALTER TYPE ... REMOVE VALUE/reorder support for native enum types, so nativeType: true uses the standard "recreate type" strategy: create a new type with the desired values, cast the column across with USING column::text::new_type, drop the old type, then rename the new type into place. Non-native (CHECK-constraint-backed) Postgres enum columns are simpler to alter — the existing constraint is dropped and replaced. MySQL enum columns are altered directly with MODIFY COLUMN ... ENUM(...), since MySQL enums have no such limitation.

Parameters

engine

Knex<any, any[]> | Transaction<any, any[]>

Knex connection or transaction used to detect the active dialect and run the alteration.

options

QAlterEnumColumnOptions

Alteration options; see QAlterEnumColumnOptions.

Returns

Promise<void>

Throws

UnsupportedEnumAlterationDialectError when the active dialect has no supported alteration strategy.

Example

public async up(schema: SchemaBuilder, engine: MigrationConnection): Promise<void> {
await alterEnumColumn(engine, {
table: "Order",
column: "status",
values: ["pending", "shipped", "delivered", "cancelled"],
nativeType: true,
typeName: "order_status"
});
}