Remote / foldkit-remote-drizzle

checkConstraints

function · packages/remote-drizzle/src/checks.ts:618

function checkConstraints(binding: AnyEntityBinding): {
  readonly constraints: ReadonlyArray<{
    readonly name: string
    readonly constraint: string
  }>
  readonly serverOnly: ReadonlyArray<string>
}

The CHECKs a binding's Entity implies, as clauses for a migration written in SQL, and the rules no CHECK holds, which only the server's writes do:

ts
const { constraints, serverOnly } = checkConstraints(Db.Post)
sqlite.exec(`create table posts (…, ${constraints.map(c => c.constraint).join(', ')})`)
// Postgres adds them to a table: alter table posts add <constraint>

Each clause is constraint "<name>" check (…). Refuses, by name, an invariant the dialect cannot compile.