feat(dbml): @postgres/@sqlite dialect directives (#19)
Add parseable `@<namespace>[(<target>)]: <args>` directives embedded in DBML.
They are stored losslessly on each object's Metadata, round-trip unchanged
through the DBML writer, and are translated to SQL only by the writer for the
matching dialect.
- models: Directive type + catalog; Metadata map added to Column and Index
- dbml reader: parse and attach directives at database/table/column/index
level; line-numbered errors; repeatable by default with singleton duplicate
detection. Fixes a preexisting bug where an `indexes {}` closing brace ended
the table early, dropping trailing Note: and directive lines.
- dbml writer: re-emit directives at their location; idempotent output
- pgsql writer: PARTITION BY / INHERITS / WITH / TABLESPACE (table),
STORAGE / COMPRESSION / identity (column), WITH / TABLESPACE (index)
- sqlite writer: WITHOUT ROWID / STRICT (table), COLLATE (column)
- --strict-directives flag on ReaderOptions and WriterOptions
- docs/DBML_DIRECTIVES.md + reader/writer READMEs
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ss2MY5J11cRGwEz86ZXk7d
This commit is contained in:
@@ -172,6 +172,26 @@ When `include_audit` is enabled, adds:
|
||||
- Concurrent index creation (`CREATE INDEX CONCURRENTLY`) via `Index.Concurrent`
|
||||
- Check constraints with expressions
|
||||
- Extension types and indexes: PostGIS, pgvector, citext, hstore, ltree (see below)
|
||||
- DBML dialect directives (`@postgres:` — see below)
|
||||
|
||||
### DBML dialect directives
|
||||
|
||||
`@postgres:` directives carried on a model object's `Metadata` (typically from a
|
||||
DBML source file) are translated to SQL:
|
||||
|
||||
| Directive | Location | Emitted |
|
||||
|-----------|----------|---------|
|
||||
| `@postgres: partition by …` | table | `PARTITION BY …` on `CREATE TABLE` |
|
||||
| `@postgres: inherits …` | table | `INHERITS (…)` |
|
||||
| `@postgres: with (…)` | table, index | `WITH (…)` (on an index, overrides the comment-derived `WITH`) |
|
||||
| `@postgres: tablespace …` | table, index | `TABLESPACE …` |
|
||||
| `@postgres(col): storage …` | column | `STORAGE …` |
|
||||
| `@postgres(col): compression …` | column | `COMPRESSION …` |
|
||||
| `@postgres(col): identity always` / `identity by default` | column | `GENERATED ALWAYS/BY DEFAULT AS IDENTITY` |
|
||||
|
||||
Directives for other dialects (`@sqlite:` …) are ignored. With
|
||||
`WriterOptions.StrictDirectives` (CLI `--strict-directives`) an untranslatable
|
||||
`@postgres:` key is an error. Full reference: [`docs/DBML_DIRECTIVES.md`](../../../docs/DBML_DIRECTIVES.md).
|
||||
|
||||
## Data Types
|
||||
|
||||
|
||||
Reference in New Issue
Block a user