StaticaddThe Kysely database object passed into the migration up/down function
The name of the constraint to create
Configuration options
The names of the columns to include in the constraint
The name of the table
StaticaddAdd a value to an enum.
Note that this always includes "IF NOT EXISTS", so is safe to re-run multiple times.
The Kysely database object passed into the migration up/down function
The options for adding the enum value
The name of the enum to modify
The name of the value to add to the enum
StaticcreateCreate a database extension.
// Add the case insensitive extension
await DreamMigrationHelpers.createExtension(db, 'citext')
// Add the pg trigram extension
await DreamMigrationHelpers.createExtension(db, 'pg_trgm')
The Kysely database object passed into the migration up/down function
The name of the database extension to add
Configuration options
OptionalifNotExists?: booleanOnly add the extension if it doesn't already exist
OptionalpublicSchema?: booleanCreate using the public schema
StaticcreateCreate a gin index
The Kysely database object passed into the migration up/down function
The name of the constraint to create
Configuration options
The name of the column to index
The name of the table
StaticdropDrop a constraint
Note that this always includes "IF NOT EXISTS", so is safe to re-run multiple times.
The Kysely database object passed into the migration up/down function
The name of the constraint to create
Configuration options
The name of the table
StaticdropDrop a value from an enum and replace it with a different enum already present in the enum type (or optionally remove it from array columns).
The Kysely database object passed into the migration up/down function
The options for dropping the enum value
The name of the enum to modify
The name of the value to drop from the enum
Details about which table and column to change and which value to replace the dropped value with (or remove it if the column is an array)
StaticnewForces a new transaction boundary in migration execution.
When called in a migration file, this method ensures that any existing transaction is committed before this migration runs, and a new transaction is started before the migration in this file. This is essential for migrations that depend on previously committed changes.
Some database operations require that dependent changes be committed before they can be executed. For example, check constraints that reference enum values require those enum values to be committed to the database first.
// first migration file: Add enum value
export async function up(db: Kysely<any>): Promise<void> {
await DreamMigrationHelpers.addEnumValue(db, {
enumName: 'user_status',
value: 'premium'
})
}
// second migration file: Add check constraint that depends on the enum value
export async function up(db: Kysely<any>): Promise<void> {
DreamMigrationHelpers.newTransaction() // Ensure enum value is committed first
await db.schema
.alterTable('users')
.addCheckConstraint(
'check_premium_users',
sql`status = 'premium' OR credits < 100`
)
.execute()
}
StaticrenameRename a table and its associated primary key index and sequence.
This method renames the table, its primary key index ({tablename}_pkey),
and its primary key sequence ({tablename}_id_seq) to keep them in sync.
The sequence rename is skipped for tables with UUID primary keys (which have no associated sequence). The primary key index is always renamed since PostgreSQL does not automatically rename it when the table is renamed.
The Kysely database object passed into the migration up/down function
The current name of the table to rename
The new name for the table
Unique indexes cannot be populated by the same value even within a transaction, but deferrable unique constraints can.
The Sortable decorator requires deferrable unique constraints rather than unique indexes.