@xemahq/app-schema-ddl
v0.1.4
Published
Layer 1 SDK: the SINGLE trusted server-side compiler that turns a typed, discriminated `SchemaChangePlan` into Postgres DDL statements. No SQL string ever crosses a wire — callers send a plan, this package emits the SQL. `PgTypeToken` is a closed enum (no
Downloads
10,671
Readme
@xemahq/app-schema-ddl
Compile typed schema change plans into Postgres DDL
Overview
Turns a typed SchemaChangePlan into Postgres DDL statements. Callers send a plan, never SQL. Column types come from a closed set (PgTypeToken), and every identifier is validated against KEY_PATTERN before it is quoted. The additive compiler cannot emit a DROP; destructive changes go through a separate compiler.
When to use it
- You generate or apply schema changes for app entity tables and want one auditable SQL emitter.
Installation
pnpm add @xemahq/app-schema-ddlUsage
import {
AppSchemaChangeKind,
PgTypeToken,
compileAdditivePlan,
} from '@xemahq/app-schema-ddl';
const statements = compileAdditivePlan({
schemaName: 'shop',
changes: [
{
kind: AppSchemaChangeKind.AddEntity,
entityKey: 'order',
columns: [{ key: 'total', type: PgTypeToken.DoublePrecision, notNull: true }],
},
],
});compileDestructivePlan(plan) handles renames, narrowing and drops. Invalid input throws AppSchemaDdlError.
License
Apache-2.0 © Xema — xema.dev
