{"id":43944,"library":"sql-schema-generator","title":"sql-schema-generator","description":"A declarative relational database SQL schema generator for PostgreSQL that abstracts boilerplate and enforces best practices like insert-only temporal database design, optimal data types, and naming conventions. Current stable version is 0.25.2, with an inactive release cadence (last release in 2020). It generates static and versioned tables, mapping tables, upsert functions, and current-version views to support event-driven, domain-driven design patterns. Unlike ORMs or migration tools, it produces raw SQL files under user control, avoiding lock-in and allowing custom modifications.","status":"active","version":"0.25.2","language":"javascript","source_language":"en","source_url":"https://github.com/ehmpathy/sql-schema-generator","tags":["javascript","database","schema","dont-repeat-yourself","sql","postgres","postgresql","insert-only","domain-driven-design","typescript"],"install":[{"cmd":"npm install sql-schema-generator","lang":"bash","label":"npm"},{"cmd":"yarn add sql-schema-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-schema-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"CLI framework for command-line interface","package":"oclif","optional":true}],"imports":[{"note":"ESM only; no default export.","wrong":"const generateSchema = require('sql-schema-generator');","symbol":"generateSchema","correct":"import { generateSchema } from 'sql-schema-generator';"},{"note":"TypeScript type for entity definition objects.","wrong":"","symbol":"SqlEntity","correct":"import { SqlEntity } from 'sql-schema-generator';"},{"note":"Main CLI entry point; run via `npx sql-schema-generator`.","wrong":"import { run } from 'sql-schema-generator';","symbol":"cli","correct":"import { cli } from 'sql-schema-generator';"}],"quickstart":{"code":"import { generateSchema } from 'sql-schema-generator';\n\nconst entities = [{\n  name: 'user',\n  properties: {\n    email: { type: 'string', unique: true },\n    name: { type: 'string', required: true },\n  },\n  updatableProperties: ['name'],\n}];\n\nconst sql = generateSchema(entities);\nconsole.log(sql);","lang":"typescript","description":"Generates SQL schema for a 'user' entity with static and updatable properties, outputting CREATE TABLE statements."},"warnings":[{"fix":"Update to v1.0.0+ and use the string directly.","message":"The `generateSchema` function now returns a string instead of an object with sql keys in v1.0.0.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use quoted identifiers in SQL if case mixing is needed.","message":"Entity names are case-sensitive; references must match exactly.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Rename reference columns to match the naming convention.","message":"All foreign key columns must end with `_id` or `_id` suffix.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Define a separate mapping table entity instead of array properties.","message":"The `array` property type is deprecated since v0.20.0; use `mapping` entity pattern instead.","severity":"deprecated","affected_versions":">=0.20.0"}],"env_vars":null,"search_vec":"'0.25.2':38 '2020':47 'abstract':15 'allow':91 'avoid':86 'best':19 'boilerpl':16 'cadenc':43 'control':85 'convent':33 'current':34,60 'current-vers':59 'custom':92 'data':29 'databas':8,26,95 'declar':6 'design':27,71,110 'domain':69,108 'domain-driven':68 'domain-driven-design':107 'dont':98 'dont-repeat-yourself':97 'driven':67,70,109 'enforc':18 'event':66 'event-driven':65 'file':82 'function':57 'generat':4,11,49 'inact':41 'insert':23,105 'insert-on':22,104 'javascript':94 'last':44 'like':21 'lock':88 'lock-in':87 'map':54 'migrat':76 'modif':93 'name':32 'optim':28 'orm':74 'pattern':72 'postgr':102 'postgresql':13,103 'practic':20 'produc':79 'raw':80 'relat':7 'releas':42,45 'repeat':99 'schema':3,10,96 'sql':2,9,81,101 'sql-schema-gener':1 'stabl':35 'static':50 'support':64 'tabl':53,55 'tempor':25 'tool':77 'type':30 'typescript':111 'unlik':73 'upsert':56 'user':84 'version':36,52,61 'view':62","created_at":"2026-06-05T17:02:13.532176+00:00","updated_at":"2026-06-05T17:02:13.532176+00:00","problems":[{"fix":"Use `import { generateSchema } from 'sql-schema-generator';`","cause":"Using default import instead of named import.","error":"TypeError: generateSchema is not a function"},{"fix":"Add type: 'string' (or appropriate type) to all properties.","cause":"Missing 'type' field in property definition.","error":"Error: property 'email' must have a type defined"},{"fix":"Use double-quoted identifiers for reserved words like 'user'.","cause":"Generated SQL may contain reserved keywords used as identifiers without quoting.","error":"SyntaxError: Unexpected identifier at line 1"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/ehmpathy/sql-schema-generator","github":"https://github.com/ehmpathy/sql-schema-generator","docs":null,"changelog":null,"pypi":null,"npm":"sql-schema-generator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}