@rawsql-ts/ztd-cli 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -25
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.js +372 -118
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +4 -4
- package/dist/commands/lint.js +60 -40
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/ztdConfig.d.ts +2 -2
- package/dist/commands/ztdConfig.js +26 -12
- package/dist/commands/ztdConfig.js.map +1 -1
- package/dist/utils/optionalDependencies.d.ts +35 -0
- package/dist/utils/optionalDependencies.js +96 -0
- package/dist/utils/optionalDependencies.js.map +1 -0
- package/package.json +18 -10
- package/templates/AGENTS.md +36 -296
- package/templates/README.md +12 -237
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
- package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
- package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
- package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
- package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
- package/templates/dist/mapper-core/src/index.d.ts +160 -0
- package/templates/dist/mapper-core/src/index.js +637 -0
- package/templates/dist/mapper-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
- package/templates/dist/testkit-core/src/errors/index.js +111 -0
- package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
- package/templates/dist/testkit-core/src/index.d.ts +17 -0
- package/templates/dist/testkit-core/src/index.js +47 -0
- package/templates/dist/testkit-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
- package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
- package/templates/dist/testkit-core/src/types/index.js +3 -0
- package/templates/dist/testkit-core/src/types/index.js.map +1 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
- package/templates/dist/writer-core/src/index.d.ts +34 -0
- package/templates/dist/writer-core/src/index.js +115 -0
- package/templates/dist/writer-core/src/index.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.ts +24 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -0
- package/templates/src/AGENTS.md +26 -0
- package/templates/src/catalog/AGENTS.md +37 -0
- package/templates/src/catalog/runtime/AGENTS.md +75 -0
- package/templates/src/catalog/runtime/_coercions.ts +1 -0
- package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
- package/templates/src/catalog/specs/AGENTS.md +48 -0
- package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
- package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
- package/templates/src/db/sql-client.ts +5 -5
- package/templates/src/jobs/AGENTS.md +26 -0
- package/templates/src/jobs/README.md +3 -0
- package/templates/src/repositories/AGENTS.md +118 -0
- package/templates/src/repositories/tables/AGENTS.md +94 -0
- package/templates/src/repositories/tables/README.md +3 -0
- package/templates/src/repositories/views/AGENTS.md +25 -0
- package/templates/src/repositories/views/README.md +3 -0
- package/templates/src/sql/AGENTS.md +77 -0
- package/templates/src/sql/README.md +6 -0
- package/templates/tests/AGENTS.md +43 -129
- package/templates/tests/generated/AGENTS.md +16 -0
- package/templates/tests/smoke.test.ts +5 -0
- package/templates/tests/smoke.validation.test.ts +34 -0
- package/templates/tests/support/AGENTS.md +26 -0
- package/templates/tests/support/global-setup.ts +8 -23
- package/templates/tests/support/testkit-client.ts +13 -741
- package/templates/tests/ztd-layout.generated.ts +0 -2
- package/templates/tsconfig.json +9 -3
- package/templates/ztd/AGENTS.md +11 -142
- package/templates/ztd/README.md +4 -82
- package/templates/ztd/ddl/AGENTS.md +34 -0
- package/templates/ztd/ddl/demo.sql +74 -0
package/templates/tsconfig.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "../../../tsconfig.json",
|
|
3
2
|
"compilerOptions": {
|
|
4
|
-
"
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022"],
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
5
11
|
"outDir": "dist",
|
|
6
12
|
"tsBuildInfoFile": "dist/.tsbuildinfo"
|
|
7
13
|
},
|
|
8
|
-
"include": ["tests/**/*.ts"]
|
|
14
|
+
"include": ["src/**/*.ts", "tests/**/*.ts"]
|
|
9
15
|
}
|
package/templates/ztd/AGENTS.md
CHANGED
|
@@ -1,149 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
# ztd AGENTS
|
|
2
2
|
|
|
3
|
-
This
|
|
4
|
-
AI must treat these directories as authoritative sources of truth and must not modify them without explicit instruction.
|
|
3
|
+
This directory contains ZTD inputs and related documentation.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Core rule
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
- "ztd/ddl/" is the only human-owned source of truth inside "ztd/".
|
|
8
|
+
- Do not create new subdirectories under "ztd/" unless explicitly instructed.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
- After cloning the repository (or in a clean environment), run `npx ztd ztd-config`.
|
|
12
|
-
- If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
|
|
10
|
+
## Boundaries
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
- Runtime code must not depend on "ztd/".
|
|
13
|
+
- Tests may reference DDL and generated outputs via ZTD tooling.
|
|
15
14
|
|
|
16
|
-
##
|
|
15
|
+
## Editing policy
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Purpose
|
|
21
|
-
|
|
22
|
-
This directory contains all canonical definitions of database structure, including:
|
|
23
|
-
|
|
24
|
-
- CREATE TABLE
|
|
25
|
-
- ALTER TABLE
|
|
26
|
-
- Constraints
|
|
27
|
-
- Indexes
|
|
28
|
-
|
|
29
|
-
It is the **single source of truth** for the physical database schema as interpreted by ztd-cli.
|
|
30
|
-
|
|
31
|
-
### Behavior Rules (strict)
|
|
32
|
-
|
|
33
|
-
- **Never modify files in this directory unless explicitly instructed by a human.**
|
|
34
|
-
- Do not apply “helpful” refactors, cleanups, or formatting changes on your own.
|
|
35
|
-
- You may propose edits or review changes when asked, but you must not apply them without approval.
|
|
36
|
-
- All DDL statements must be:
|
|
37
|
-
- Valid PostgreSQL syntax
|
|
38
|
-
- Explicitly semicolon-terminated
|
|
39
|
-
- Do not reorder statements; dependency and execution order matters.
|
|
40
|
-
- Preserve all human-authored:
|
|
41
|
-
- Naming
|
|
42
|
-
- Formatting
|
|
43
|
-
- Comments
|
|
44
|
-
- Structural intent
|
|
45
|
-
- When asked to extend existing definitions:
|
|
46
|
-
- Do not remove or rewrite existing columns or comments unless explicitly told.
|
|
47
|
-
- Maintain column order and constraint style.
|
|
48
|
-
- Do not introduce schema changes that conflict with:
|
|
49
|
-
- `ztd/domain-specs`
|
|
50
|
-
- `ztd/enums`
|
|
51
|
-
|
|
52
|
-
If there is uncertainty, stop and request clarification instead of guessing.
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## Domain Specifications (`ztd/domain-specs/`)
|
|
57
|
-
|
|
58
|
-
You are an AI agent that **reads** domain specifications to understand business semantics.
|
|
59
|
-
|
|
60
|
-
### Purpose
|
|
61
|
-
|
|
62
|
-
Each file in this directory defines **one domain behavior**.
|
|
63
|
-
These files explain *what the data means*, not how the application is implemented.
|
|
64
|
-
|
|
65
|
-
### Instructions
|
|
66
|
-
|
|
67
|
-
- Treat each Markdown file as defining exactly **one behavior**.
|
|
68
|
-
- Use the embedded SQL block as the **reference SELECT**.
|
|
69
|
-
- Only the first top-level SQL block is executable logic.
|
|
70
|
-
- Parameters may be written as `:named` placeholders.
|
|
71
|
-
- When generating executable SQL, bind them as positional placeholders (`$1`, `$2`, `?`).
|
|
72
|
-
- **Never modify files in this directory unless explicitly instructed.**
|
|
73
|
-
|
|
74
|
-
### Rules (strict)
|
|
75
|
-
|
|
76
|
-
- Never ignore the human-written explanation above the SQL block.
|
|
77
|
-
- Keep exactly one executable SQL block per file.
|
|
78
|
-
- Do not reorder, optimize, or “simplify” SQL unless explicitly instructed.
|
|
79
|
-
- Preserve the exact semantics described by humans.
|
|
80
|
-
- This directory defines **what is correct behavior**.
|
|
81
|
-
- Your role is to reproduce that behavior elsewhere (`src/`, `tests/`), not reinterpret it.
|
|
82
|
-
|
|
83
|
-
If meaning is ambiguous, defer to human judgment and ask.
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Domain Enums (`ztd/enums/`)
|
|
88
|
-
|
|
89
|
-
You are an AI assistant responsible for **reading and using** domain enum definitions.
|
|
90
|
-
|
|
91
|
-
### Purpose
|
|
92
|
-
|
|
93
|
-
This directory defines canonical value sets such as:
|
|
94
|
-
|
|
95
|
-
- Status codes
|
|
96
|
-
- Category types
|
|
97
|
-
- Plan tiers
|
|
98
|
-
|
|
99
|
-
These enums are the **only allowed vocabulary** for such concepts.
|
|
100
|
-
|
|
101
|
-
### Behavior Guidelines (strict)
|
|
102
|
-
|
|
103
|
-
- Never invent enum values.
|
|
104
|
-
- Never hardcode magic numbers or strings.
|
|
105
|
-
- Never modify or add enum definitions unless explicitly instructed by a human.
|
|
106
|
-
|
|
107
|
-
### SQL Rules
|
|
108
|
-
|
|
109
|
-
- Each file contains exactly one executable SQL block.
|
|
110
|
-
- Enum definitions follow this canonical pattern:
|
|
111
|
-
|
|
112
|
-
```sql
|
|
113
|
-
select v.*
|
|
114
|
-
from (
|
|
115
|
-
values
|
|
116
|
-
(1, 'some_code', 'some_label')
|
|
117
|
-
) v(key, value, display_name);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
- `key` and `value` are authoritative.
|
|
121
|
-
- Additional columns (e.g. `display_name`, `ranking`) may be used for:
|
|
122
|
-
- UI display
|
|
123
|
-
- Sorting
|
|
124
|
-
- Documentation
|
|
125
|
-
|
|
126
|
-
### Use in Code Generation
|
|
127
|
-
|
|
128
|
-
- Always reference enums when generating:
|
|
129
|
-
- SQL WHERE conditions
|
|
130
|
-
- Constants
|
|
131
|
-
- Conditional logic
|
|
132
|
-
- When translating logic from `ztd/domain-specs`, resolve enum references through this directory.
|
|
133
|
-
- Maintain full consistency with naming and intent.
|
|
134
|
-
|
|
135
|
-
If a required enum does not exist, stop and ask for human clarification.
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## Absolute Restrictions (important)
|
|
140
|
-
|
|
141
|
-
- AI must not modify anything under `ztd/` by default.
|
|
142
|
-
- DDL, domain-specs, and enums are **human-led artifacts**.
|
|
143
|
-
- AI may assist by:
|
|
144
|
-
- Reading
|
|
145
|
-
- Explaining
|
|
146
|
-
- Proposing diffs
|
|
147
|
-
- AI may apply changes **only** with explicit instruction.
|
|
148
|
-
|
|
149
|
-
Violation of these rules leads to silent corruption of domain meaning and is unacceptable.
|
|
17
|
+
- Avoid modifying "ztd/README.md" unless explicitly asked.
|
|
18
|
+
- Prefer adding rules to "ztd/ddl/AGENTS.md" for DDL-related guidance.
|
package/templates/ztd/README.md
CHANGED
|
@@ -1,84 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# ztd/
|
|
2
2
|
|
|
3
|
-
This directory
|
|
3
|
+
This directory stores ZTD schema artifacts.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
The ztd/ddl/ directory stores **Data Definition Language (DDL)** files that describe the database schema. These files include CREATE TABLE, ALTER TABLE, index declarations, and constraint definitions. ZTD treats the SQL files here as the single source of truth for schemas, so both humans and AI must reference this directory when evolving the structure.
|
|
8
|
-
|
|
9
|
-
### Allowed Content and Structure
|
|
10
|
-
|
|
11
|
-
- **Schema Definition Files:** Core table structures live in ztd/ddl/ using CREATE TABLE statements, but you may also add related DDL such as ALTER TABLE commands or explicit index declarations that contribute to the schema contract.
|
|
12
|
-
- **Semantic Flexibility:** The directory supports multiple ways to describe schema changes (e.g., altering tables inline or via subsequent ALTER TABLE statements). The key is clarity and correctness so the CLI tooling can interpret the intended shape.
|
|
13
|
-
|
|
14
|
-
### File Format and Execution
|
|
15
|
-
|
|
16
|
-
- **Executable SQL Scripts:** Every file should be valid PostgreSQL with semicolon-terminated statements and a consistent dependency ordering.
|
|
17
|
-
- **Integration with ZTD CLI:** The CLI parses these files to understand schema shapes. Treat this directory as authoritative: every schema change should be captured here as if it were applied to a clean database.
|
|
18
|
-
|
|
19
|
-
### Maintenance Guidelines
|
|
20
|
-
|
|
21
|
-
- **Human-Maintained Schema:** Developers own the schema structure; AI tooling may only assist with targeted edits.
|
|
22
|
-
- **Conventions:** Follow the established naming, formatting, and typing patterns. Include comments to explain non-obvious schema choices.
|
|
23
|
-
|
|
24
|
-
### Relationships
|
|
25
|
-
|
|
26
|
-
- /ztd/domain-specs: Translates schema structures into behavioral expectations.
|
|
27
|
-
- /ztd/enums: Provides the enum sets referenced by constraints or column defaults.
|
|
28
|
-
|
|
29
|
-
## Domain Specifications
|
|
30
|
-
|
|
31
|
-
The ztd/domain-specs/ directory documents key domain behaviors as human-readable specifications.
|
|
32
|
-
|
|
33
|
-
### Purpose
|
|
34
|
-
|
|
35
|
-
Each Markdown file describes one business concept, explains it in natural language, and pairs it with an example SELECT query inside a fenced SQL block. These specifications help AI agents understand **what** the domain logic should do without prescribing implementation details.
|
|
36
|
-
|
|
37
|
-
### Format and Best Practices
|
|
38
|
-
|
|
39
|
-
- One file per concept with a prose explanation followed by an example SELECT.
|
|
40
|
-
- Keep exactly one executable SQL block per file (one file = one behavior).
|
|
41
|
-
- Named parameters (e.g., :as_of) signal intent; you may translate them into positional placeholders when generating code.
|
|
42
|
-
- Focus on semantics—use Markdown structuring (tables, bullets, etc.) to clarify the behavior.
|
|
43
|
-
- Always update the description before touching the SQL when the behavior evolves.
|
|
44
|
-
|
|
45
|
-
### Relationships
|
|
46
|
-
|
|
47
|
-
- /ztd/ddl: Supplies the physical schema that backs the behavior.
|
|
48
|
-
- /ztd/enums: Provides the vocabularies referenced in the domain logic.
|
|
49
|
-
|
|
50
|
-
## Domain Enums
|
|
51
|
-
|
|
52
|
-
The ztd/enums/ directory contains enumerated value sets such as statuses, tiers, or lifecycle states.
|
|
53
|
-
|
|
54
|
-
### Purpose
|
|
55
|
-
|
|
56
|
-
These enums are human-maintained and support:
|
|
57
|
-
|
|
58
|
-
- AI-assisted SQL/code generation
|
|
59
|
-
- TypeScript constant generation
|
|
60
|
-
- Schema enforcement (e.g., CHECK constraints)
|
|
61
|
-
- Frontend label rendering via display names
|
|
62
|
-
|
|
63
|
-
### Format and Structure
|
|
64
|
-
|
|
65
|
-
- The folder uses Markdown to keep the definitions readable.
|
|
66
|
-
- Each enum is documented in a single file using SELECT ... FROM (VALUES ...) blocks with explicit column aliases.
|
|
67
|
-
|
|
68
|
-
### Required Structure
|
|
69
|
-
|
|
70
|
-
- Each row must include at least key and value columns.
|
|
71
|
-
- Optional metadata like display_name,
|
|
72
|
-
ranking, or sort_order may be added for UI/logic purposes.
|
|
73
|
-
|
|
74
|
-
### Guidelines
|
|
75
|
-
|
|
76
|
-
- Keep naming conventions consistent and avoid duplicate value identifiers across unrelated enums.
|
|
77
|
-
- Ensure compatibility with /ztd/domain-specs and /ztd/ddl when expanding enums.
|
|
78
|
-
- Preserve human-readable display_name values as needed for front-end contexts.
|
|
79
|
-
|
|
80
|
-
### Relationships
|
|
81
|
-
|
|
82
|
-
- /ztd/ddl: Referenced by constraints or lookup tables.
|
|
83
|
-
- /ztd/domain-specs: Provides the vocabulary for behavioral rules.
|
|
84
|
-
- src/: Maps enums to generated constants or query logic.
|
|
5
|
+
- `ztd/ddl/<schema>.sql` is the source of truth for schema.
|
|
6
|
+
- Run `npx ztd ztd-config` to regenerate `tests/generated` outputs.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# ztd/ddl AGENTS
|
|
2
|
+
|
|
3
|
+
This folder contains physical schema definitions (DDL). Human-led.
|
|
4
|
+
|
|
5
|
+
## Ownership
|
|
6
|
+
|
|
7
|
+
- Humans own DDL semantics.
|
|
8
|
+
- AI may assist with mechanical edits, but must not invent domain rules.
|
|
9
|
+
|
|
10
|
+
## Conventions (Postgres-oriented)
|
|
11
|
+
|
|
12
|
+
- Table names: singular (example: "user", "order", "invoice")
|
|
13
|
+
- Primary key: "serial8" (bigserial) by default
|
|
14
|
+
- Timestamps: default "current_timestamp" where applicable
|
|
15
|
+
|
|
16
|
+
## Comments (required)
|
|
17
|
+
|
|
18
|
+
Add comments for tables and important columns.
|
|
19
|
+
|
|
20
|
+
Postgres syntax:
|
|
21
|
+
- "comment on table <schema>.<table> is '...';"
|
|
22
|
+
- "comment on column <schema>.<table>.<column> is '...';"
|
|
23
|
+
|
|
24
|
+
## Constraints
|
|
25
|
+
|
|
26
|
+
- Prefer explicit NOT NULL where appropriate.
|
|
27
|
+
- Prefer explicit unique constraints for business keys.
|
|
28
|
+
- Foreign keys are allowed, but keep them intentional and explain rationale in comments.
|
|
29
|
+
|
|
30
|
+
## File strategy
|
|
31
|
+
|
|
32
|
+
- Keep schema DDL in a clear and reviewable form.
|
|
33
|
+
- If using one file per schema (example: "public.sql"), keep it consistent.
|
|
34
|
+
- Avoid random splitting unless there is a strong reason.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
create table "user" (
|
|
2
|
+
user_id serial8 primary key,
|
|
3
|
+
user_name text not null,
|
|
4
|
+
email text not null,
|
|
5
|
+
created_at timestamptz not null default current_timestamp
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
comment on table "user" is
|
|
9
|
+
'User master. Referenced by task_assignment.';
|
|
10
|
+
|
|
11
|
+
comment on column "user".user_id is
|
|
12
|
+
'Primary key of user.';
|
|
13
|
+
comment on column "user".user_name is
|
|
14
|
+
'Display name of the user.';
|
|
15
|
+
comment on column "user".email is
|
|
16
|
+
'Email address of the user.';
|
|
17
|
+
comment on column "user".created_at is
|
|
18
|
+
'Timestamp when the user was created.';
|
|
19
|
+
|
|
20
|
+
create table task (
|
|
21
|
+
task_id serial8 primary key,
|
|
22
|
+
title text not null,
|
|
23
|
+
status text not null,
|
|
24
|
+
priority integer not null,
|
|
25
|
+
due_date date,
|
|
26
|
+
created_at timestamptz not null default current_timestamp
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
comment on table task is
|
|
30
|
+
'Task entity. Current assignee is derived from task_assignment history.';
|
|
31
|
+
|
|
32
|
+
comment on column task.task_id is
|
|
33
|
+
'Primary key of task.';
|
|
34
|
+
comment on column task.title is
|
|
35
|
+
'Short description of the task.';
|
|
36
|
+
comment on column task.status is
|
|
37
|
+
'Task status. Example: open, in_progress, done.';
|
|
38
|
+
comment on column task.priority is
|
|
39
|
+
'Priority of the task. Higher value means higher priority.';
|
|
40
|
+
comment on column task.due_date is
|
|
41
|
+
'Optional due date of the task.';
|
|
42
|
+
comment on column task.created_at is
|
|
43
|
+
'Timestamp when the task was created.';
|
|
44
|
+
|
|
45
|
+
create table task_assignment (
|
|
46
|
+
task_assignment_id serial8 primary key,
|
|
47
|
+
task_id bigint not null,
|
|
48
|
+
user_id bigint not null,
|
|
49
|
+
assigned_at timestamptz not null default current_timestamp
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
comment on table task_assignment is
|
|
53
|
+
'Assignment history of tasks. Latest assigned_at defines current assignee.';
|
|
54
|
+
|
|
55
|
+
comment on column task_assignment.task_assignment_id is
|
|
56
|
+
'Primary key of task_assignment.';
|
|
57
|
+
comment on column task_assignment.task_id is
|
|
58
|
+
'Referenced task identifier.';
|
|
59
|
+
comment on column task_assignment.user_id is
|
|
60
|
+
'Referenced user identifier.';
|
|
61
|
+
comment on column task_assignment.assigned_at is
|
|
62
|
+
'Timestamp when the task was assigned to the user.';
|
|
63
|
+
|
|
64
|
+
create index idx_task_assignment_task
|
|
65
|
+
on task_assignment(task_id);
|
|
66
|
+
|
|
67
|
+
create index idx_task_assignment_task_time
|
|
68
|
+
on task_assignment(task_id, assigned_at desc);
|
|
69
|
+
|
|
70
|
+
comment on index idx_task_assignment_task is
|
|
71
|
+
'Index for joining task_assignment by task_id.';
|
|
72
|
+
|
|
73
|
+
comment on index idx_task_assignment_task_time is
|
|
74
|
+
'Index for resolving latest assignment per task.';
|