suppa-mcp-2 1.2.0 → 1.2.2
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 +17 -7
- package/dist/server.js +9 -3
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +65 -14
- package/skills/suppa-entity-code/references/entities.md +5 -2
- package/skills/suppa-entity-code/references/registration.md +51 -1
- package/skills/suppa-entity-code/references/seeds.md +2 -0
- package/skills/suppa-entity-code/references/tabular-parts.md +146 -0
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +524 -127
- package/skills/suppa-entity-code/templates/tabular-part.template.ts +93 -0
package/README.md
CHANGED
|
@@ -296,13 +296,23 @@ node <this-skill-dir>/scripts/validate-suppa-schema.mjs <app-root>
|
|
|
296
296
|
Checks: SQL-string defaults, decorator misuse, thunk-less relations, seed
|
|
297
297
|
idempotency (importKeyFields / `$key`), forbidden seed keys, numeric relation
|
|
298
298
|
ids, reverse `@OneToMany` references, `forFeature` membership, seed dependency
|
|
299
|
-
order, `dist/` autoload paths, tsconfig decorator flags,
|
|
300
|
-
`@Entity()`/`@Column()` options or field types
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
299
|
+
order, `dist/` autoload paths, tsconfig decorator flags, unknown
|
|
300
|
+
`@Entity()`/`@Column()` options or field types, and tabular-part rules —
|
|
301
|
+
the `type: 'tabular-part'` + `relationEntityName` + `owner` triad, `owner`
|
|
302
|
+
resolving to the right parent, and `owner` first in `importKeyFields`
|
|
303
|
+
(E108/E109/E110/W607) — validated against the installed `@suppa/sdk` typings
|
|
304
|
+
when resolvable, falling back to the doc tables otherwise
|
|
305
|
+
(E101/E102/E107/E501/E502). Options/records/registration arrays delivered via
|
|
306
|
+
spread or by reference can't be statically checked and fire a W606 warning
|
|
307
|
+
instead. An entity or seed left out of `EntityModule.forFeature()` fires
|
|
308
|
+
E301/E302, naming the module file to edit so the fix is a find-and-add, not a
|
|
309
|
+
search. Exit code 1 on any error. Use the `write_entity_code` MCP prompt to
|
|
310
|
+
drive it from any client.
|
|
311
|
+
|
|
312
|
+
Tabular parts (owned child sub-tables like checklist items or order lines)
|
|
313
|
+
and the remove-and-re-add-a-field semantics — a re-added field restores its
|
|
314
|
+
old data because the key defaults to `<EntityName>.<fieldName>` — are both
|
|
315
|
+
covered; see `references/tabular-parts.md` and `references/registration.md`.
|
|
306
316
|
|
|
307
317
|
---
|
|
308
318
|
|
package/dist/server.js
CHANGED
|
@@ -1656,13 +1656,19 @@ export function buildServer() {
|
|
|
1656
1656
|
"representativeFieldName, and per-field nullable.\n" +
|
|
1657
1657
|
"3. Write src/common/database/entities/*.entity.ts — @Entity class extending SystemBaseEntity; scalars via @Column({ type: FieldTypeEnum.X }); " +
|
|
1658
1658
|
"relations via thunks (@ManyToOne(() => Target)); fixed choices via @Enum('Entity.field', ...); attachments via @File/@MultiFile; " +
|
|
1659
|
-
"'default' is a SQL expression STRING ('false', \"'draft'\") — never a JS value
|
|
1659
|
+
"'default' is a SQL expression STRING ('false', \"'draft'\") — never a JS value. Repeating rows owned by one parent record " +
|
|
1660
|
+
"(checklist items, order lines) are a TABULAR PART, not a plain entity: type: 'tabular-part' + relationEntityName + a @ManyToOne " +
|
|
1661
|
+
"field named owner, with owner first in importKeyFields (see references/tabular-parts.md). " +
|
|
1662
|
+
"Registering the class is part of writing it: add it to EntityModule.forFeature([...]) in the app module " +
|
|
1663
|
+
'(find it with grep -rn "EntityModule.forFeature" src/) in the same step — an unregistered class gets no table.\n' +
|
|
1660
1664
|
"4. Write matching *.seed.ts with createSeed(): every importKeyField in every record (or $key); relations referenced by import key " +
|
|
1661
1665
|
"({ name: 'Default' }) — never numeric ids; never system columns, access metadata, or reverse @OneToMany fields.\n" +
|
|
1662
|
-
"5.
|
|
1666
|
+
"5. Export the entity and seed from their barrels (entities/index.ts, seeds/index.ts), and add the seed to " +
|
|
1667
|
+
"EntityModule.forFeature()'s seeds array, positioned after the seeds of everything it references — dependencies first.\n" +
|
|
1663
1668
|
"6. Gate before claiming done: node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs <app-root> " +
|
|
1664
1669
|
"(or the skills/ dir of a checkout) reports 0 errors; npx tsc --noEmit passes; " +
|
|
1665
|
-
"push, reload (POST /core/applications/:appId/reload), verify with suppa_describe_entity
|
|
1670
|
+
"push, reload (POST /core/applications/:appId/reload), verify with suppa_describe_entity — " +
|
|
1671
|
+
"the gate fails with E301 if anything is unregistered — run it, do not assume.\n" +
|
|
1666
1672
|
"Porting from Suppa 1.0? Read the schema with suppa_read_v1_entity_props / suppa_read_v1_enum and map per references/v1-mapping.md — " +
|
|
1667
1673
|
"never invent a mapping; record data stays with suppa_migrate_entities_from_v1.");
|
|
1668
1674
|
return server;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": { "suppa-mcp": "dist/bin.js" },
|
|
@@ -40,19 +40,22 @@ Confirm all 5 before writing anything:
|
|
|
40
40
|
## Hard rules
|
|
41
41
|
|
|
42
42
|
1. Every entity extends `SystemBaseEntity`; never declare `id`, `createdAt`, `updatedAt`, `deletedAt`, `createdBy`, `removedBy` yourself — it already provides them.
|
|
43
|
-
2.
|
|
44
|
-
3.
|
|
45
|
-
4.
|
|
46
|
-
5.
|
|
47
|
-
6.
|
|
48
|
-
7.
|
|
49
|
-
8.
|
|
50
|
-
9.
|
|
43
|
+
2. An entity class that is not in `EntityModule.forFeature()` does not exist — the platform creates no table for it (doc: "An entity class that is never passed to forFeature() is invisible"). Write the entity and register it in the SAME step; never move on to the next entity, or report progress, with an unregistered class.
|
|
44
|
+
3. `default` is a SQL expression string — `'false'`, `"'draft'"` — never a JS value; a JS value is rejected at migration time.
|
|
45
|
+
4. Scalars only via `@Column({ type: FieldTypeEnum.X })`; relations/enums/files are NEVER declared via `@Column` — use the `@ManyToOne`/`@ManyToMany`/`@OneToMany`/`@ManyToManyBackRef`/`@Enum`/`@MultiEnum`/`@File`/`@MultiFile` families.
|
|
46
|
+
5. Relation targets are thunks — `() => Target`, never the class itself — or circular imports break.
|
|
47
|
+
6. If an option isn't in the reference tables (`references/entities.md`, `references/seeds.md`, `references/registration.md`), it doesn't exist — stop and ask, don't guess.
|
|
48
|
+
7. Every entity class must appear in some `forFeature()`'s `entities` array; every seed in its `seeds` array, dependencies first — `workflowsSeed` before `stageWorkflowsSeed`.
|
|
49
|
+
8. Seeds: every record carries all `importKeyFields` (or `$key`); relations are referenced by the target's import-key object, never a numeric id; no system columns; no `$readAccess`/`$updateAccess`/`$instanceAccess`; no reverse `@OneToMany` field, even as `[]`.
|
|
50
|
+
9. Autoload paths (`entitiesPath`/`seedsPath`) point at `dist/`, never `src/` — autoloading reads compiled output.
|
|
51
|
+
10. Renames need `key` set on `@Entity()`/`@Column()` BEFORE the rename ships — otherwise it's a drop-and-create, not a rename.
|
|
52
|
+
11. Repeating rows owned by one parent record are a **tabular part**, never a plain entity: `type: 'tabular-part'` + `relationEntityName` (the parent's `@Entity()` name) + a `@ManyToOne` field named exactly `owner` pointing at the parent class — all three required, the platform infers none of them. Put `owner` FIRST in `importKeyFields` — it scopes the business key to the parent, or rows collide across different parents.
|
|
51
53
|
|
|
52
54
|
## Decorator decision table
|
|
53
55
|
|
|
54
56
|
| You need | Decorator |
|
|
55
57
|
|---|---|
|
|
58
|
+
| Repeating rows owned by one parent record (checklist items, order lines, attendees) | **Tabular part** — `type: 'tabular-part'` + `relationEntityName` + a `@ManyToOne` field named `owner` on `@Entity()`; see `templates/tabular-part.template.ts` and `references/tabular-parts.md` |
|
|
56
59
|
| Scalar column (text/numeric/integer/boolean/timestamp/json/uuid/multi-language/bytea/tsvector/multi-type/icon) | `@Column({ type: FieldTypeEnum.<Member> })` |
|
|
57
60
|
| Fixed single-select value set | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
|
|
58
61
|
| Fixed multi-select value set | `@MultiEnum(...)` — same signature as `@Enum` |
|
|
@@ -82,10 +85,9 @@ Confirm all 5 before writing anything:
|
|
|
82
85
|
|
|
83
86
|
1. Pre-flight (above) — confirm repo, SDK version, tsconfig, layout.
|
|
84
87
|
2. Blocking questions (above) — get answers before writing any file.
|
|
85
|
-
3. Write the entity from `templates/entity.template.ts
|
|
86
|
-
4. Need default rows?
|
|
87
|
-
5.
|
|
88
|
-
6. Run the close-out gate (below) — do not report "done" before all 4 steps pass.
|
|
88
|
+
3. Write the entity AND wire it in (one step, both files): write `*.entity.ts` from `templates/entity.template.ts` per `references/entities.md`, then immediately export it from the entities barrel and add it to `EntityModule.forFeature()`'s `entities` array — see "Wiring a new entity in" below. The class does not exist to the platform until this is done.
|
|
89
|
+
4. Need default rows? Same deal for the seed: write it from `templates/seed.template.ts` per `references/seeds.md`, export it from the seeds barrel, and add it to the `seeds` array (dependencies first) in the same step. The seed is not done until it is in the `seeds` array.
|
|
90
|
+
5. Run the close-out gate (below) — do not report "done" before all 4 steps pass.
|
|
89
91
|
|
|
90
92
|
## Flow B — port a Suppa 1.0 entity to v2 code
|
|
91
93
|
|
|
@@ -93,9 +95,47 @@ Confirm all 5 before writing anything:
|
|
|
93
95
|
2. `suppa_read_v1_entity_props` (+ `suppa_read_v1_enum` for enum fields) -> read its fields.
|
|
94
96
|
3. Map every field per `references/v1-mapping.md` — the same authority (`classifyV1Field`) as the API migration path.
|
|
95
97
|
4. Never silently drop a field: anything unmapped or unsupported gets `// SKIPPED: <field> — <reason>` inside the class body.
|
|
96
|
-
5. Continue with Flow A from the blocking questions onward (steps 2-
|
|
98
|
+
5. Continue with Flow A from the blocking questions onward (steps 2-5 above).
|
|
97
99
|
6. Record data migrates separately, via `suppa_migrate_entities_from_v1` — this skill only produces schema code.
|
|
98
100
|
|
|
101
|
+
## Wiring a new entity in (same step as writing it)
|
|
102
|
+
|
|
103
|
+
**Locate the registration first.** The entity and seed files are new files written from templates; registration is an edit to an existing module file you have not seen yet, so find it before you start.
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
grep -rn "EntityModule.forFeature" src/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Fallback: `src/app/app.module.ts`. If the call you find uses `entitiesPath`/`seedsPath` (autoload) instead of explicit arrays, there is nothing to edit here — the class is picked up from `dist/` — so verify the build output path instead.
|
|
110
|
+
|
|
111
|
+
Four edits, every time:
|
|
112
|
+
|
|
113
|
+
1. Export the class from the entities barrel — `src/common/database/entities/index.ts`.
|
|
114
|
+
2. Export the seed from the seeds barrel — `src/common/database/seeds/index.ts`.
|
|
115
|
+
3. Import the class in the module and add it to the `entities` array.
|
|
116
|
+
4. Add the seed to the `seeds` array, positioned AFTER the seeds of everything it references.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
// before
|
|
120
|
+
EntityModule.forFeature([Workflows], { seeds: [workflowsSeed] });
|
|
121
|
+
|
|
122
|
+
// after — new import, new entity, new seed
|
|
123
|
+
import { MyNewEntity } from '../common/database/entities';
|
|
124
|
+
import { myNewEntitySeed } from '../common/database/seeds';
|
|
125
|
+
|
|
126
|
+
EntityModule.forFeature([Workflows, MyNewEntity], {
|
|
127
|
+
seeds: [workflowsSeed, myNewEntitySeed],
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Self-check, no tooling required:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
grep -rn "MyNewEntity" src/ | grep -i module
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
If that prints nothing, the entity is not registered.
|
|
138
|
+
|
|
99
139
|
## Close-out gate (all steps, in order — no "done" before all pass)
|
|
100
140
|
|
|
101
141
|
```
|
|
@@ -106,6 +146,8 @@ Confirm all 5 before writing anything:
|
|
|
106
146
|
4. verify the tenant converged: suppa_describe_entity('<EntityName>')
|
|
107
147
|
```
|
|
108
148
|
|
|
149
|
+
Step 1 exists to catch exactly this: an unregistered class is E301 and the gate fails. Never report done on an unrun gate.
|
|
150
|
+
|
|
109
151
|
`validate-suppa-schema.mjs` exits `0` on a clean run, `1` when errors are found, `2` on a usage error or a missing path. The gate requires exit `0` — warnings alone do not block.
|
|
110
152
|
|
|
111
153
|
## Troubleshooting
|
|
@@ -119,4 +161,13 @@ Confirm all 5 before writing anything:
|
|
|
119
161
|
| Back reference can't insert | A reverse `@OneToMany` field is present in a seed record, possibly as `[]` | E204 |
|
|
120
162
|
| A renamed entity or field appears as a new one | No `key` option was set | W602 |
|
|
121
163
|
| `default` value is rejected | A JavaScript value was passed instead of a SQL expression string | E103 |
|
|
122
|
-
|
|
|
164
|
+
| A re-added field already contains old data | Same name means the same key, so the soft-deleted field was restored with its column — this is a runtime migration outcome, not statically checkable | documented-only, see references/registration.md |
|
|
165
|
+
| A removed field is still present after a reload | The removal pass was skipped because the system user could not be resolved | documented-only, see references/registration.md |
|
|
166
|
+
| The table has columns such as `title_1730457600000` | Leftovers from removed fields — renaming is how the platform removes a column; nothing cleans them up | documented-only, see references/registration.md |
|
|
167
|
+
| A tabular part has no `ownerId` column and its tab stays empty | `relationEntityName` was set, but the `owner` `@ManyToOne` was not declared | E108 |
|
|
168
|
+
| A tabular part is missing from the parent's tabs | `type: 'tabular-part'` or `relationEntityName` is missing, so it is listed under `/related` instead | E108 |
|
|
169
|
+
| Duplicate tabular-part rows across different parents | `owner` is missing from `importKeyFields`, so the key is matched globally instead of per-parent | E110 |
|
|
170
|
+
| A tabular part's rows land on/read from the wrong parent | `owner`'s `@ManyToOne` target resolves to an entity whose `@Entity()` name doesn't match `relationEntityName` | E109 |
|
|
171
|
+
| A tabular part's business key isn't scoped to its parent | `owner` is present in `importKeyFields` but not first | W607 |
|
|
172
|
+
| Validator warns W606 | Content delivered via spread or reference — options, `default`, `importKeyFields`, seed records, enum refs, `$key`, autoload paths, registration arrays, tabular-part `type`/`relationEntityName` — is not statically verifiable; the matching check is skipped. Inline it so the validator can check | W606 |
|
|
173
|
+
| Validator warns W608 | No `tsconfig.json` at the given root, so `experimentalDecorators`/`emitDecoratorMetadata` could not be verified — point the validator at the app root | W608 |
|
|
@@ -56,9 +56,12 @@ Every entity must extend SystemBaseEntity. It contributes the standard columns,
|
|
|
56
56
|
| importKeyFields | string[] | Business key used by seeds, import and relation references. |
|
|
57
57
|
| key | string | Stable identifier that survives renaming the entity. |
|
|
58
58
|
| icon | Record<string, any> | Icon configuration. |
|
|
59
|
-
| type | string | Entity
|
|
59
|
+
| type | string | Entity kind. Omit for a standalone entity, or set 'tabular-part' — see Tabular Parts. |
|
|
60
|
+
| relationEntityName | string | Name of the entity this one belongs to. Required for a tabular part. |
|
|
60
61
|
| options | Record<string, any> | Platform features to enable or disable for the entity (see below). |
|
|
61
62
|
|
|
63
|
+
See [references/tabular-parts.md](tabular-parts.md) for the full triad required to declare a tabular part (`type: 'tabular-part'` + `relationEntityName` + an `owner` relation).
|
|
64
|
+
|
|
62
65
|
options toggles the built-in per-entity features. Disable what the entity does not need — each enabled feature adds side tables and processing:
|
|
63
66
|
|
|
64
67
|
```ts
|
|
@@ -274,7 +277,7 @@ importKeyFields names the fields that identify a record independently of its num
|
|
|
274
277
|
Pick fields that are stable and unique in practice. Without importKeyFields, seeds have nothing to match on and cannot stay idempotent.
|
|
275
278
|
|
|
276
279
|
> **TIP**
|
|
277
|
-
> Use the key option on @Entity() and @Column() when you expect to rename things later. The key is the stable identity used to recognize an existing entity or field, so a rename becomes a rename instead of a drop-and-create.
|
|
280
|
+
> Use the key option on @Entity() and @Column() when you expect to rename things later. The key is the stable identity used to recognize an existing entity or field, so a rename becomes a rename instead of a drop-and-create. Without it the key defaults to the name — see Removing and Re-Adding a Field.
|
|
278
281
|
|
|
279
282
|
## About title
|
|
280
283
|
|
|
@@ -123,6 +123,50 @@ Entities and seeds behave differently on conflict. Entity metadata is overridden
|
|
|
123
123
|
|
|
124
124
|
It runs per tenant. Each tenant schema is migrated separately, and a newly provisioned tenant gets your entities and seeds when the application first boots for it.
|
|
125
125
|
|
|
126
|
+
## Removing and Re-Adding a Field
|
|
127
|
+
|
|
128
|
+
Deleting a property from an entity class and later adding it back with the same name is the one change whose outcome surprises people. Nothing is destroyed, and nothing starts empty: the field comes back with its old data.
|
|
129
|
+
|
|
130
|
+
The reason is that the sync matches your declarations against existing metadata by key, and the key of a field defaults to `<EntityName>.<fieldName>`. Same entity plus same field name means the same key, whether or not you ever set key yourself.
|
|
131
|
+
|
|
132
|
+
### Removing a Field
|
|
133
|
+
|
|
134
|
+
Delete the property, push, reload — on the next start the sync sees a key that exists in metadata but is no longer declared, and tears the field down:
|
|
135
|
+
|
|
136
|
+
| Step | Result |
|
|
137
|
+
|---|---|
|
|
138
|
+
| Field metadata | Soft-deleted: deletedAt is set and removedBy points at the system user. The row itself stays. |
|
|
139
|
+
| Column | Renamed, not dropped: title becomes title_1730457600000, where the suffix is deletedAt in epoch milliseconds. |
|
|
140
|
+
| Data | Untouched. Every value is still in the renamed column. |
|
|
141
|
+
| Relation fields | The relation is torn down the same way, through a soft removal. |
|
|
142
|
+
| Indexes and checks on the field | Their metadata is removed together with the field. |
|
|
143
|
+
| API and UI | The field is gone from metadata, from selects, and from forms. |
|
|
144
|
+
|
|
145
|
+
```sql
|
|
146
|
+
-- what the platform actually runs
|
|
147
|
+
ALTER TABLE "Tasks" RENAME COLUMN "title" TO "title_1730457600000";
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
> **WARNING**
|
|
151
|
+
> The renamed column is never cleaned up. It stays in the table with all its rows, invisible to the platform, until someone drops it manually. Removing a field is therefore not a way to delete data, and repeated remove/re-add cycles leave one leftover column each.
|
|
152
|
+
|
|
153
|
+
### Adding the Same Field Back
|
|
154
|
+
|
|
155
|
+
Re-declare the property with the same name on the same entity, and the sync resolves the key to the soft-deleted field instead of creating a new one:
|
|
156
|
+
|
|
157
|
+
| Step | Result |
|
|
158
|
+
|---|---|
|
|
159
|
+
| Field metadata | The same row is restored — deletedAt is cleared. No duplicate field, and the field id does not change. |
|
|
160
|
+
| Column | title_1730457600000 is renamed back to title. |
|
|
161
|
+
| Data | The old values are back, including everything written before the removal. |
|
|
162
|
+
|
|
163
|
+
```sql
|
|
164
|
+
ALTER TABLE "Tasks" RENAME COLUMN "title_1730457600000" TO "title";
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
> **WARNING**
|
|
168
|
+
> Re-adding a field is a restore, not a fresh start. If you removed the field in order to clear it, the data returns the moment you declare it again. There is no flag that turns this off — to get a genuinely empty field, the new field must have a different key.
|
|
169
|
+
|
|
126
170
|
## The Development Loop
|
|
127
171
|
|
|
128
172
|
```txt
|
|
@@ -135,7 +179,7 @@ Reload with the application record id:
|
|
|
135
179
|
POST /core/applications/:appId/reload
|
|
136
180
|
```
|
|
137
181
|
|
|
138
|
-
appId is the id of the record in the Applications table. The runner rebuilds the app from that record and restarts the running instance.
|
|
182
|
+
(From Run application:) appId is the id of the record in the Applications table. The runner rebuilds the app from that record and restarts the running instance.
|
|
139
183
|
|
|
140
184
|
See Run application for the full application lifecycle.
|
|
141
185
|
|
|
@@ -153,6 +197,12 @@ See Run application for the full application lifecycle.
|
|
|
153
197
|
| Back reference can't insert | A reverse @OneToMany field is present in a seed record, possibly as []. |
|
|
154
198
|
| A renamed entity or field appears as a new one | No key option was set, so the rename was not recognized as a rename. |
|
|
155
199
|
| default value is rejected | A JavaScript value was passed instead of a SQL expression string. |
|
|
200
|
+
| A re-added field already contains old data | Same name means the same key, so the soft-deleted field was restored with its column. |
|
|
201
|
+
| A removed field is still present after a reload | The removal pass was skipped because the system user could not be resolved. |
|
|
202
|
+
| The table has columns such as title_1730457600000 | Leftovers from removed fields. Renaming is how the platform removes a column; nothing cleans them up. |
|
|
203
|
+
| A tabular part has no ownerId column and its tab stays empty | relationEntityName was set, but the owner @ManyToOne was not declared. |
|
|
204
|
+
| A tabular part is missing from the parent's tabs | type: 'tabular-part' or relationEntityName is missing, so it is listed under /related instead. |
|
|
205
|
+
| Duplicate tabular-part rows across different parents | owner is missing from importKeyFields, so the key is matched globally. |
|
|
156
206
|
|
|
157
207
|
## Requirements
|
|
158
208
|
|
|
@@ -108,6 +108,8 @@ Because `workflow: { name: 'Default' }` resolves by name, the seed works in ever
|
|
|
108
108
|
| Reverse @OneToMany fields — even as [] | Back references cannot be inserted; the import throws. |
|
|
109
109
|
| Numeric relation ids | They do not match across tenants. Use import-key references. |
|
|
110
110
|
|
|
111
|
+
Seeding a tabular part's owner is the same @ManyToOne reference shape as any other relation — see [references/tabular-parts.md](tabular-parts.md) for the owner-referenced seed example.
|
|
112
|
+
|
|
111
113
|
> **TIP**
|
|
112
114
|
> When you build a seed from an exported record, strip those keys before committing. Seed a child entity with its own seed instead of nesting it in the parent.
|
|
113
115
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Tabular parts — verbatim rules
|
|
2
|
+
|
|
3
|
+
Transcribed from docs.modern-expo.com/backend/application-developing/migrations.html (captured 2026-08-03). If an option is not in these tables, it does not exist — stop and ask.
|
|
4
|
+
|
|
5
|
+
## Tabular Parts
|
|
6
|
+
|
|
7
|
+
A tabular part is a child entity whose rows only exist inside one parent record — the table the user edits on the parent's form rather than a separate section with its own list. Checklist items of a task, lines of an order, attendees of an event.
|
|
8
|
+
|
|
9
|
+
The platform uses the same mechanism for its own entities: ApplicationJobs and ApplicationEnvs are tabular parts of Applications, CalendarEventAttendees is a tabular part of CalendarEvents.
|
|
10
|
+
|
|
11
|
+
A tabular part is still an ordinary entity — its own table, its own columns, readable through Query Manager. What `type: 'tabular-part'` changes is ownership: the platform records that these rows belong to a parent record, and the UI renders them inside it.
|
|
12
|
+
|
|
13
|
+
## Declaring One
|
|
14
|
+
|
|
15
|
+
Three things make an entity a tabular part. All three are required, and the platform does not infer any of them:
|
|
16
|
+
|
|
17
|
+
- `type: 'tabular-part'` on `@Entity()`.
|
|
18
|
+
- `relationEntityName` — the name of the parent entity.
|
|
19
|
+
- A `@ManyToOne` field named `owner` pointing at the parent class.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
Column,
|
|
24
|
+
Entity,
|
|
25
|
+
FieldTypeEnum,
|
|
26
|
+
Index,
|
|
27
|
+
ManyToOne,
|
|
28
|
+
SystemBaseEntity,
|
|
29
|
+
} from '@suppa/sdk';
|
|
30
|
+
import { Tasks } from './tasks.entity';
|
|
31
|
+
|
|
32
|
+
@Index('TaskChecklistItemsOwnerTitleUindex', ['owner', 'title'], {
|
|
33
|
+
unique: true,
|
|
34
|
+
where: '"deletedAt" IS NULL',
|
|
35
|
+
})
|
|
36
|
+
@Entity({
|
|
37
|
+
name: 'TaskChecklistItems',
|
|
38
|
+
title: { en: 'Checklist items', uk: 'Пункти чеклиста' },
|
|
39
|
+
type: 'tabular-part',
|
|
40
|
+
relationEntityName: 'Tasks',
|
|
41
|
+
importKeyFields: ['owner', 'title'],
|
|
42
|
+
representativeFieldName: 'title',
|
|
43
|
+
})
|
|
44
|
+
export class TaskChecklistItems extends SystemBaseEntity {
|
|
45
|
+
@ManyToOne(() => Tasks, {
|
|
46
|
+
name: 'owner',
|
|
47
|
+
title: { en: 'Task', uk: 'Задача' },
|
|
48
|
+
})
|
|
49
|
+
owner?: Tasks;
|
|
50
|
+
|
|
51
|
+
@Column({
|
|
52
|
+
name: 'title',
|
|
53
|
+
title: { en: 'Title', uk: 'Назва' },
|
|
54
|
+
type: FieldTypeEnum.Text,
|
|
55
|
+
nullable: false,
|
|
56
|
+
})
|
|
57
|
+
title: string;
|
|
58
|
+
|
|
59
|
+
@Column({
|
|
60
|
+
name: 'done',
|
|
61
|
+
title: { en: 'Done', uk: 'Виконано' },
|
|
62
|
+
type: FieldTypeEnum.Boolean,
|
|
63
|
+
nullable: false,
|
|
64
|
+
default: 'false',
|
|
65
|
+
})
|
|
66
|
+
done: boolean;
|
|
67
|
+
|
|
68
|
+
@Column({
|
|
69
|
+
name: 'order',
|
|
70
|
+
title: { en: 'Order', uk: 'Порядок' },
|
|
71
|
+
type: FieldTypeEnum.Integer,
|
|
72
|
+
})
|
|
73
|
+
order: number;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## What Gets Created
|
|
78
|
+
|
|
79
|
+
Registering the class in EntityModule.forFeature() and starting the application produces:
|
|
80
|
+
|
|
81
|
+
| Artifact | Result |
|
|
82
|
+
|---|---|
|
|
83
|
+
| Table | A normal table TaskChecklistItems in the tenant schema. Nothing about the storage differs from a standalone entity. |
|
|
84
|
+
| ownerId column | An integer foreign key to the parent table, materialized from the owner relation. |
|
|
85
|
+
| Entity metadata | An EntityMetadata row with type = 'tabular-part' and relationEntity pointing at Tasks. |
|
|
86
|
+
| Schema API | The entity is returned by GET /core/schema/Tasks/tabular-parts and is excluded from GET /core/schema/Tasks/related. |
|
|
87
|
+
| UI | The client reads that list and renders the rows as a table on the parent record instead of giving the entity its own navigation entry. |
|
|
88
|
+
| Index and constraints | Whatever you declared with @Index() / @Check(), unchanged. |
|
|
89
|
+
|
|
90
|
+
## Scoping the Business Key
|
|
91
|
+
|
|
92
|
+
Put owner first in importKeyFields. A checklist item is unique inside its task, not across the workspace, and seeds, import and export all resolve the row through that pair:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
importKeyFields: ['owner', 'title'],
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The unique index mirrors the same pair, so the database enforces what the metadata declares:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
@Index('TaskChecklistItemsOwnerTitleUindex', ['owner', 'title'], {
|
|
102
|
+
unique: true,
|
|
103
|
+
where: '"deletedAt" IS NULL',
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`where: '"deletedAt" IS NULL'` keeps soft-deleted rows from blocking a re-created one.
|
|
108
|
+
|
|
109
|
+
## The Back Reference on the Parent
|
|
110
|
+
|
|
111
|
+
Declare the reverse side on the parent to read the rows as a nested array and to give the tab a localized name:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
@OneToMany(() => TaskChecklistItems, (item) => item.owner, {
|
|
115
|
+
title: { en: 'Checklist', uk: 'Чекліст' },
|
|
116
|
+
})
|
|
117
|
+
checklist: TaskChecklistItems[];
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
This is the same shape the platform uses — Applications.jobs is an @OneToMany to ApplicationJobs inverted on owner.
|
|
121
|
+
|
|
122
|
+
> **WARNING**
|
|
123
|
+
> A back reference is readable, not writable. Never include the field in a seed — not even as `[]` — the import throws `Back reference can't insert`. Seed the tabular part with its own seed and reference the parent through owner.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { createSeed } from '@suppa/sdk';
|
|
127
|
+
|
|
128
|
+
export const taskChecklistItemsSeed = createSeed('TaskChecklistItems', [
|
|
129
|
+
{ owner: { externalId: 'onboarding-task' }, title: 'Sign the NDA', order: 1000 },
|
|
130
|
+
{ owner: { externalId: 'onboarding-task' }, title: 'Set up the laptop', order: 2000 },
|
|
131
|
+
]);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
owner is referenced through the parent's importKeyFields, exactly like any other @ManyToOne.
|
|
135
|
+
|
|
136
|
+
## Registration
|
|
137
|
+
|
|
138
|
+
A tabular part is registered like any other entity — both classes go into forFeature(), and the parent does not need to come first:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
EntityModule.forFeature([Tasks, TaskChecklistItems], {
|
|
142
|
+
seeds: [tasksSeed, taskChecklistItemsSeed],
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Seed order still matters: the parent's seed must run before the tabular part's seed, or owner resolves to nothing.
|