Stricture MicroDDL Schema Compiler and Code Generator
raw JSON → 4.0.2 verified Fri May 01 auth: no javascript
Stricture 4.0.2 is a multi-target data definition language (MicroDDL) compiler that transforms a Markdown-inspired, line-based schema definition into MySQL scripts, Meadow schema files, relationship diagrams (Graphviz), data dictionaries (Markdown, LaTeX, CSV), and test fixtures. Unlike general-purpose schema tools, Stricture is purpose-built for the Meadow application framework and provides first-class support for audit columns, authorization definitions, and PICT UI definitions. The project follows a service-oriented architecture on the Pict/Fable 3.x stack, with both a Commander-based CLI and a programmatic API. Releases are irregular but stable; v3 introduced a major CLI syntax change (migrating from yargs to Commander subcommands).
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/stricture/index.js not supported. ↓
cause Package is ESM-only since v3, but code uses CommonJS require().
fix
Switch to import statements or use dynamic import() as a fallback.
error stricture: error: unknown option `-i' ↓
cause Using deprecated yargs-style CLI options that were removed in v3.
fix
Use 'stricture full <input.mddl>' syntax instead.
error TypeError: stricture.StrictureCompiler is not a constructor ↓
cause Importing the default export and trying to access .StrictureCompiler, which may not exist or is not a constructor in the version used.
fix
Import named export directly: import { StrictureCompiler } from 'stricture'.
error SyntaxError: Unexpected token 'export' ↓
cause Node.js version < 12, or 'type': 'module' not set in package.json when using import statements.
fix
Use Node >= 14 and set 'type': 'module' in package.json, or use dynamic import().
Warnings
breaking CLI syntax changed in v3: subcommands replaced yargs-style options ↓
fix Use 'stricture full Model.mddl' instead of 'stricture -i Model.mddl -c Full'
breaking Package is ESM-only since v3. require() will fail with ERR_REQUIRE_ESM ↓
fix Use import statements or dynamic import(). Add 'type': 'module' to package.json if needed.
deprecated Legacy 'yargs' CLI is removed. Old command-line flags no longer work. ↓
fix Migrate to subcommand syntax described in v3 migration guide.
gotcha Compiler expects source files as .mddl text, not JSON. Passing JSON directly via API bypasses MicroDDL parsing. ↓
fix Use the programmatic API with model objects if you already have JSON; otherwise ensure input is .mddl.
gotcha Audit column detection is case-sensitive. 'CreateDate' is recognized but 'created_at' is not. ↓
fix Use exact names: CreateDate, UpdateDate, Deleted (case-sensitive).
gotcha Generated MySQL scripts include IF NOT EXISTS by default. No IF EXISTS in DROP statements. ↓
fix Review generated migration scripts before running on production databases.
Install
npm install stricture yarn add stricture pnpm add stricture Imports
- default wrong
const stricture = require('stricture');correctimport stricture from 'stricture'; - StrictureCompiler wrong
import { StrictureCompiler } from './node_modules/stricture/lib/compiler.js';correctimport { StrictureCompiler } from 'stricture'; - MySQLGenerator
import { MySQLGenerator } from 'stricture';
Quickstart
import stricture from 'stricture';
import { MySQLGenerator } from 'stricture';
const sources = [
{
'Name': 'Users',
'Columns': [
{ 'Name': 'UserId', 'Type': 'int', 'PrimaryKey': true, 'Identity': true },
{ 'Name': 'Username', 'Type': 'varchar(255)', 'Nullable': false },
{ 'Name': 'Email', 'Type': 'varchar(255)', 'Nullable': false },
{ 'Name': 'CreateDate', 'Type': 'datetime', 'Default': 'now()' }
]
},
{
'Name': 'Posts',
'Columns': [
{ 'Name': 'PostId', 'Type': 'int', 'PrimaryKey': true, 'Identity': true },
{ 'Name': 'UserId', 'Type': 'int', 'ForeignKey': 'Users.UserId' },
{ 'Name': 'Title', 'Type': 'varchar(255)', 'Nullable': false },
{ 'Name': 'Body', 'Type': 'text', 'Nullable': false }
]
}
];
const model = { 'Tables': sources };
const compiler = new stricture.StrictureCompiler();
const compiled = compiler.compile(model);
const mysqlGen = new MySQLGenerator();
const sql = mysqlGen.generate(compiled);
console.log(sql);