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).
What’s in the box
Section titled “What’s in the box”- Mixins
audit—created_at/updated_at/created_by/updated_byplus the trigger pair (audit_skip_noop,audit_stamp) that maintains them.audit_log— attaches theaudit_difftrigger so a table’s field-level change history is written to theaudit_logtable.timestamps—created_at/updated_at+ a trigger; the actor-free subset ofaudit(no identity-table dependency).soft_delete—deleted_at.audit_log_actor— internal: supplies the parameterizedchanged_byFK for theaudit_logtable (application tables don’t use it).
- Functions —
audit_stamp,audit_diff,audit_skip_noop,timestamps_stamp, andaudit_backfill_by(p_actor)(a bootstrap helper). - Table —
audit_log(append-only field-level history).
Why parameterized
Section titled “Why parameterized”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.
Requirements
Section titled “Requirements”- schema-flow ≥ 0.11.0 — needs
importsplus parameterized mixins. - PostgreSQL — the triggers are plain
plpgsql; no extensions required.
Next: Quick start.