Changelog - 2026-10-20
isNullableDiscriminator for the principal enricher
New FeatureIn one line. A polymorphic principal's type column can now be NOT NULL, so a row cannot name an id without saying what the id belongs to.
typescript
generatePrincipalColumnDefs({
polymorphicIdType: 'number',
defaultPolymorphic: 'User',
isNullableDiscriminator: false,
});
// principalType: text('principal_type').default('User').notNull()What changed
- New option
isNullableDiscriminator. It sits next toisNullableIdinTPrincipalEnricherOptions, on both the Postgres and the SQLitegeneratePrincipalColumnDefs. - The default is
true. The{discriminator}Typecolumn stays nullable, as it always was, so existing schemas and migrations do not change. falseaddsNOT NULL. The column keeps its default value (defaultPolymorphic,''if omitted). The return type follows: the column isNotNull<HasDefault<...>>.- The id column is separate.
isNullableIdstill controls only{discriminator}Id.
Who is affected
- Everyone not setting the option. Nothing changes.
- A model that wants the type column required. Pass
isNullableDiscriminator: falseand generate a migration. - A caller of
enrichPrincipal. Its options type is not generic, so it takes the default (true) only. SpreadgeneratePrincipalColumnDefsinto the table to setfalse.