Skip to content
ContractSpec
Start here

Package manual · tools

·CLI, authoring and agent tooling

tool.contractspec-drizzle-gen

Generator that compiles ContractSpec defineDatabaseTable specs into Drizzle pgTable definitions, relations, and an RLS adapter manifest.

toolstoolv3.0.4stableservernode
@lssm-tech/tool.contractspec-drizzle-gen
bun add @lssm-tech/tool.contractspec-drizzle-gen
Package source ↗Manifest ↗

Manifest declarations describe the current workspace; they do not verify registry publication or runtime execution.

Package guide

Deterministically compile ContractSpec physical-table declarations into typed Drizzle pgTable definitions and an optional tenant-RLS evidence manifest.

Usage

ts
import {
  defineDatabaseTable,
  defineUnscopedDatabaseTable,
} from "@lssm-tech/lib.contracts-spec/database";
import { generateContractSpecDrizzle } from "@lssm-tech/tool.contractspec-drizzle-gen";

const claims = defineDatabaseTable({
  name: "grace_claims",
  columns: [
    { name: "id", type: "uuid", nullable: false },
    { name: "tenant_id", type: "uuid", nullable: false },
    {
      name: "status",
      type: "text",
      nullable: false,
      enumValues: ["draft", "submitted"],
    },
  ],
  primaryKey: ["id"],
  foreignKeys: [],
  tenantColumn: "tenant_id",
});

const principals = defineUnscopedDatabaseTable({
  name: "grace_business_principals",
  columns: [
    { name: "id", type: "uuid", nullable: false },
    { name: "email", type: "text", nullable: false },
  ],
  primaryKey: ["id"],
  foreignKeys: [],
});

const artifacts = generateContractSpecDrizzle({}, [claims, principals]);

schemaSource contains the generated Drizzle module. The RLS manifest contains only tables declared through defineDatabaseTable; unscoped tables never gain invented tenant authority. Commit generated schema source and compare a fresh in-memory generation byte-for-byte in CI.

This tool does not replace a migration authority. Consumers may retain dbmate, Drizzle Kit, or another reviewed migration workflow while using generated Drizzle models for typed queries.

Relationships

THIS PACKAGEtool.contractspec-drizzle-gen5 import paths

Arrows point from a package to its direct dependency. Counts are derived from captured workspace manifests.

2 declarations

Declared capabilities

This manifest does not declare a capability catalogue. Use the guide, import map and source to assess the package.

Scripts

  • buildcontractspec-bun-build build
  • build:bundlecontractspec-bun-build transpile
  • build:typescontractspec-bun-build types
  • prebuildcontractspec-bun-build prebuild
  • devcontractspec-bun-build dev
  • cleanrimraf dist .turbo
  • typechecktsgo --noEmit
  • testbun test
  • lint:checknode ../../../scripts/biome.cjs check .
  • lintbun run lint:fix
  • lint:fixnode ../../../scripts/biome.cjs check --write .