uuidDefault
@quik/database / uuidDefault
Function: uuidDefault()
uuidDefault(
engine):Raw
Defined in: database/src/migrations/utils/uuid.ts:22
Builds a dialect-aware raw SQL expression for a database-generated UUID primary key default.
Postgres requires PG13+ for the built-in gen_random_uuid() function; on older versions the
pgcrypto extension must be enabled manually before using this default.
Parameters
engine
Knex<any, any[]> | Transaction<any, any[]>
Knex connection or transaction used to detect the active dialect.
Returns
Raw
Throws
UnsupportedUuidDefaultDialectError when the active dialect has no native UUID default.
Example
public async up(schema: SchemaBuilder, engine: MigrationConnection): Promise<SchemaBuilder> {
return schema.createTable("Example", (table) => {
table.uuid("id").primary().defaultTo(uuidDefault(engine));
});
}