LadderCheck.ts overview

A role column’s CHECK, derived from the application’s Ladder, so the rung set is declared once. Growing the ladder changes the DDL, so a migration-drift gate catches the missing migration.

Example

import { check, pgTable, text } from "drizzle-orm/pg-core"
import * as Auth from "@thomasfosterau/effect-auth"
import * as Drizzle from "@thomasfosterau/effect-auth-drizzle"

const Roles = Auth.Ladder.make(["user", "contributor", "moderator", "admin"])

export const users = pgTable(
  "users",
  { id: text("id").primaryKey(), role: text("role").notNull().default("user") },
  (table) => [check("users_role_valid", Drizzle.LadderCheck.ladderCheck(table.role, Roles))]
)

Exports Grouped by Category


schema

ladderCheck

<column> IN (<every rung>) — the body of a CHECK constraint, with the rungs inlined as quoted literals (inlineParams), since DDL has no bind parameters: the migration carries the literal IN list whichever tool renders it.

Signature

declare const ladderCheck: <Rung extends string>(column: SQLWrapper, ladder: Auth.Ladder.Ladder<Rung>) => SQL

Source

Since v0.1.0


This site uses Just the Docs, a documentation theme for Jekyll.