Skip to content

Introduction

@smplcty/schema-std is a set of standard, parameterized PostgreSQL schema building blocks — consumed by reference via @smplcty/schema-flow imports, not copy-pasted into each app.

These are the cross-cutting patterns every app re-implements: audit columns, soft delete, timestamps, an audit-log trail. They belong to no domain, so they live here — and they are parameterized, so each consuming app supplies its own identity table and actor GUC. The package therefore carries no dependency on any app’s data model (including @smplcty/auth, which consumes this like any other app).

  • Mixins
    • auditcreated_at / updated_at / created_by / updated_by plus the trigger pair (audit_skip_noop, audit_stamp) that maintains them.
    • audit_log — attaches the audit_diff trigger so a table’s field-level change history is written to the audit_log table.
    • timestampscreated_at / updated_at + a trigger; the actor-free subset of audit (no identity-table dependency).
    • soft_deletedeleted_at.
    • audit_log_actor — internal: supplies the parameterized changed_by FK for the audit_log table (application tables don’t use it).
  • Functionsaudit_stamp, audit_diff, audit_skip_noop, timestamps_stamp, and audit_backfill_by(p_actor) (a bootstrap helper).
  • Tableaudit_log (append-only field-level history).

Audit columns FK to your users table, and the audit triggers read the actor id from your session GUC. Hard-coding those names would couple the package to one app’s data model. Instead, three parameters — user_table / user_pk / actor_guc — default to the convention (users / user_id / app.actor_id), so the common case is param-free, and any app can override them in one place.

  • schema-flow ≥ 0.11.0 — needs imports plus parameterized mixins.
  • PostgreSQL — the triggers are plain plpgsql; no extensions required.

Next: Quick start.