Driving rules
- Ask for the domain idea (one paragraph). If vague: one sharp clarifying question, not an interrogation.
- Tables = plural snake_case. Implicit collections → own tables.
- Every table: PK (
int autoincrement default; UUID only if domain dictates). Business identifier → unique index. Lookup/filter column → non-unique index.
- FKs optional — only include when the relation is unambiguous. Otherwise
foreignKeys: {} and let the Designer model it via relates/depend.
- Output = one complete
Schema.yaml block + explicit assumption list.
Import instruction: Schema → Import → File in the Designer.
1. Schema.yaml structure
tables:
<table_name_snake_case>:
name: <same as the key>
columns:
-
name: <column_name>
type: <SQL type, see catalogue>
phpType: <int | string | datetime | float | bool>
length: <optional integer, for varchar/char>
nullable: <true | false>
primary: <true | false> # PK column only
autoincrement: <true | false> # PK int only
indexes:
-
name: <index_name | PRIMARY>
columns: [<col>, <col>, …]
type: <primary | unique | index>
foreignKeys: {} # empty map OR list of:
-
column: <local_column>
referencedTable: <other_table>
referencedColumn: <other_column>
Column required: name, type, phpType, nullable. length required for varchar. primary/autoincrement only on PK.
Index required: name, columns, type. PK index = PRIMARY.
FKs empty: use {} (matches real DB exports) or [].
2. Types
type |
phpType |
Use for |
Notes |
int |
int |
numeric IDs, counts |
autoincrement: true on PKs |
bigint |
int |
large IDs, counts |
Row count > 2^31 |
varchar |
string |
identifiers, names, short text |
length mandatory; common 36/50/100/255 |
text |
string |
long-form text |
No length |
date |
datetime |
dates, timestamps |
Builder maps both to datetime in PHP |
decimal |
string |
money, precise numerics |
length as precision,scale if supported |
float |
float |
imprecise numerics |
Avoid for currency |
bool |
bool |
flags |
|
json |
string |
semi-structured payloads |
Use sparingly |
3. Modelling heuristics
- Identifier columns: every business object typically has an internal
int PK (id) and a public business identifier (identifier, often varchar(36) UUID7). Unique index on the business identifier.
- Active period: "active period" in the idea →
activeFrom (date, not nullable) + activeUntil (date, nullable = open period).
- Lookup tables: categories/types/statuses get their own table even when described as enums.
- Junctions: many-to-many → explicit junction table with PK + two FK columns.
- No relations in Schema.yaml unless obvious. Relations go into
Aggregate.yaml (relates/depend/adopt) via tools-definition.
4. Example
Idea: "Track meter readings. A counter has a number and an active period, lives at a meter location, can link to multiple registers via a gateway."
tables:
counters:
name: counters
columns:
- { name: id, type: int, phpType: int, nullable: false, primary: true, autoincrement: true }
- { name: identifier, type: varchar, phpType: string, length: 36, nullable: false }
- { name: meterLocationIdentifier, type: varchar, phpType: string, length: 50, nullable: false }
- { name: counterNumber, type: varchar, phpType: string, length: 50, nullable: false }
- { name: activeFrom, type: date, phpType: datetime, nullable: false }
- { name: activeUntil, type: date, phpType: datetime, nullable: true }
indexes:
- { name: PRIMARY, columns: [id], type: primary }
- { name: identifier, columns: [identifier], type: unique }
- { name: meterLocationIdentifier, columns: [meterLocationIdentifier], type: index }
foreignKeys: {}
registers:
name: registers
columns:
- { name: id, type: int, phpType: int, nullable: false, primary: true, autoincrement: true }
- { name: identifier, type: varchar, phpType: string, length: 36, nullable: false }
indexes:
- { name: PRIMARY, columns: [id], type: primary }
- { name: identifier, columns: [identifier], type: unique }
foreignKeys: {}
Assumptions to state:
- Business identifier =
identifier (UUID). If actual key is counterNumber, move unique index there.
- FKs empty — counter ↔ register link goes into the Designer via
relates/depend.
5. Reference
- Full working example with FKs:
examples/Schema.yaml (MeterDevice — counters, registers, gateways, meter locations).
- Post-import interpretation:
tools-definition
1---
2name: schema-authoring
3description: Author a Schema.yaml from scratch for the Jardis Designer — from a plain-text domain idea, draft tables (snake_case plural), columns with realistic types, primary keys, indexes (primary/unique/index), optional foreign keys. Output matches the DB-export format the Designer's importer parses.
4zone: pre
5prerequisites: []
6next: [tools-definition]
7metadata:
8 source: https://skillmd.com/skills/aibot88/schema-authoring
9---
10
11## Driving rules
12
131. Ask for the domain idea (one paragraph). If vague: **one** sharp clarifying question, not an interrogation.
142. Tables = plural snake_case. Implicit collections → own tables.
153. Every table: PK (`int` autoincrement default; UUID only if domain dictates). Business identifier → `unique` index. Lookup/filter column → non-unique `index`.
164. FKs **optional** — only include when the relation is unambiguous. Otherwise `foreignKeys: {}` and let the Designer model it via `relates`/`depend`.
175. Output = one complete `Schema.yaml` block + explicit assumption list.
18
19Import instruction: `Schema → Import → File` in the Designer.
20
21### 1. Schema.yaml structure
22
23```yaml
24tables:
25 <table_name_snake_case>:
26 name: <same as the key>
27 columns:
28 -
29 name: <column_name>
30 type: <SQL type, see catalogue>
31 phpType: <int | string | datetime | float | bool>
32 length: <optional integer, for varchar/char>
33 nullable: <true | false>
34 primary: <true | false> # PK column only
35 autoincrement: <true | false> # PK int only
36 indexes:
37 -
38 name: <index_name | PRIMARY>
39 columns: [<col>, <col>, …]
40 type: <primary | unique | index>
41 foreignKeys: {} # empty map OR list of:
42 -
43 column: <local_column>
44 referencedTable: <other_table>
45 referencedColumn: <other_column>
46```
47
48**Column required:** `name`, `type`, `phpType`, `nullable`. `length` required for `varchar`. `primary`/`autoincrement` only on PK.
49**Index required:** `name`, `columns`, `type`. PK index = `PRIMARY`.
50**FKs empty:** use `{}` (matches real DB exports) or `[]`.
51
52### 2. Types
53
54| `type` | `phpType` | Use for | Notes |
55|---|---|---|---|
56| `int` | `int` | numeric IDs, counts | `autoincrement: true` on PKs |
57| `bigint` | `int` | large IDs, counts | Row count > 2^31 |
58| `varchar` | `string` | identifiers, names, short text | `length` mandatory; common 36/50/100/255 |
59| `text` | `string` | long-form text | No `length` |
60| `date` | `datetime` | dates, timestamps | Builder maps both to `datetime` in PHP |
61| `decimal` | `string` | money, precise numerics | `length` as `precision,scale` if supported |
62| `float` | `float` | imprecise numerics | Avoid for currency |
63| `bool` | `bool` | flags | |
64| `json` | `string` | semi-structured payloads | Use sparingly |
65
66### 3. Modelling heuristics
67
68- **Identifier columns:** every business object typically has an internal `int` PK (`id`) **and** a public business identifier (`identifier`, often `varchar(36)` UUID7). Unique index on the business identifier.
69- **Active period:** "active period" in the idea → `activeFrom` (`date`, not nullable) + `activeUntil` (`date`, nullable = open period).
70- **Lookup tables:** categories/types/statuses get their own table even when described as enums.
71- **Junctions:** many-to-many → explicit junction table with PK + two FK columns.
72- **No relations in Schema.yaml unless obvious.** Relations go into `Aggregate.yaml` (`relates`/`depend`/`adopt`) via `tools-definition`.
73
74### 4. Example
75
76Idea: *"Track meter readings. A counter has a number and an active period, lives at a meter location, can link to multiple registers via a gateway."*
77
78```yaml
79tables:
80 counters:
81 name: counters
82 columns:
83 - { name: id, type: int, phpType: int, nullable: false, primary: true, autoincrement: true }
84 - { name: identifier, type: varchar, phpType: string, length: 36, nullable: false }
85 - { name: meterLocationIdentifier, type: varchar, phpType: string, length: 50, nullable: false }
86 - { name: counterNumber, type: varchar, phpType: string, length: 50, nullable: false }
87 - { name: activeFrom, type: date, phpType: datetime, nullable: false }
88 - { name: activeUntil, type: date, phpType: datetime, nullable: true }
89 indexes:
90 - { name: PRIMARY, columns: [id], type: primary }
91 - { name: identifier, columns: [identifier], type: unique }
92 - { name: meterLocationIdentifier, columns: [meterLocationIdentifier], type: index }
93 foreignKeys: {}
94
95 registers:
96 name: registers
97 columns:
98 - { name: id, type: int, phpType: int, nullable: false, primary: true, autoincrement: true }
99 - { name: identifier, type: varchar, phpType: string, length: 36, nullable: false }
100 indexes:
101 - { name: PRIMARY, columns: [id], type: primary }
102 - { name: identifier, columns: [identifier], type: unique }
103 foreignKeys: {}
104```
105
106Assumptions to state:
107
108- Business identifier = `identifier` (UUID). If actual key is `counterNumber`, move unique index there.
109- FKs empty — counter ↔ register link goes into the Designer via `relates`/`depend`.
110
111### 5. Reference
112
113- Full working example with FKs: `examples/Schema.yaml` (MeterDevice — counters, registers, gateways, meter locations).
114- Post-import interpretation: `tools-definition`