@lumifai/harness-tool-pack-postgres 0.0.1 → 0.2.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 +27 -11
- package/dist/catalog.d.ts +10 -0
- package/dist/catalog.js +47 -1
- package/dist/catalog.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/insert-language.js +1 -1
- package/dist/insert-language.js.map +1 -1
- package/dist/pg-client.d.ts +19 -0
- package/dist/pg-client.js +66 -0
- package/dist/pg-client.js.map +1 -0
- package/dist/postgres-write.d.ts +41 -0
- package/dist/postgres-write.js +376 -0
- package/dist/postgres-write.js.map +1 -0
- package/dist/postgres.d.ts +29 -6
- package/dist/postgres.js +190 -35
- package/dist/postgres.js.map +1 -1
- package/dist/query-executor.js +26 -1
- package/dist/query-executor.js.map +1 -1
- package/dist/query-language.js +11 -4
- package/dist/query-language.js.map +1 -1
- package/dist/validation.d.ts +52 -0
- package/dist/validation.js +395 -0
- package/dist/validation.js.map +1 -0
- package/dist/workspace-file.js +31 -28
- package/dist/workspace-file.js.map +1 -1
- package/package.json +9 -3
- package/skills/postgres/SKILL.md +3 -2
- package/skills/postgres-write/SKILL.md +117 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: postgres-write
|
|
3
|
+
description: Deterministic PostgreSQL insert and update tools that read JSON from the workspace
|
|
4
|
+
version: 1.1.0
|
|
5
|
+
tags:
|
|
6
|
+
- database
|
|
7
|
+
- postgres
|
|
8
|
+
- write
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# PostgreSQL Write Tools
|
|
12
|
+
|
|
13
|
+
Use the `postgres` tool pack to persist workspace JSON files into PostgreSQL deterministically.
|
|
14
|
+
Pair these tools with the `postgres` discovery workflow before unfamiliar tables.
|
|
15
|
+
|
|
16
|
+
These tools do **not** run arbitrary SQL. Boot config must set `allowedTables` (and optionally `allowedColumns`).
|
|
17
|
+
`postgres_validate_file` is registered only when `allowedTables` is set and only accepts those targets.
|
|
18
|
+
|
|
19
|
+
## Tools
|
|
20
|
+
|
|
21
|
+
| Tool | Purpose |
|
|
22
|
+
| --------------------------- | ----------------------------------------------- |
|
|
23
|
+
| `postgres_validate_file` | Validate table rows and quarantine invalid rows |
|
|
24
|
+
| `postgres_insert_from_file` | JSON file → `INSERT` rows (optional upsert) |
|
|
25
|
+
| `postgres_update_from_file` | JSON patch → `UPDATE` one row |
|
|
26
|
+
|
|
27
|
+
## Insert file format
|
|
28
|
+
|
|
29
|
+
Path is **workspace-relative** (no leading `/`), e.g. `campaigns/123/brief.json`.
|
|
30
|
+
|
|
31
|
+
Single row:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"id": "campaign-123",
|
|
36
|
+
"name": "Fintech outreach",
|
|
37
|
+
"metadata": { "region": "US" }
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Multiple rows (every row must have the **same keys**):
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
[
|
|
45
|
+
{ "id": "c1", "name": "Campaign A", "metadata": {} },
|
|
46
|
+
{ "id": "c2", "name": "Campaign B", "metadata": {} }
|
|
47
|
+
]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Tool args:
|
|
51
|
+
|
|
52
|
+
- `conflictColumns` — e.g. `["id"]` for idempotent saves
|
|
53
|
+
- `onConflict` — `ignore` (default when conflictColumns set) or `update` (upsert non-key columns)
|
|
54
|
+
|
|
55
|
+
Empty arrays are rejected.
|
|
56
|
+
|
|
57
|
+
## Validation workflow
|
|
58
|
+
|
|
59
|
+
Call `postgres_validate_file` after producing a JSON batch and before
|
|
60
|
+
`postgres_insert_from_file`:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"jsonFilePath": "batch.merged.json",
|
|
65
|
+
"schema": "public",
|
|
66
|
+
"table": "my_table",
|
|
67
|
+
"refreshSchema": false
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The validator derives the selected table schema from PostgreSQL and caches it under
|
|
72
|
+
`.schema-cache/` for 24 hours (per connection fingerprint). It always writes a sibling
|
|
73
|
+
`.valid.json` file; it writes `.rejected.json` only when at least one row fails. Only
|
|
74
|
+
pass `validFilePath` to `postgres_insert_from_file`.
|
|
75
|
+
|
|
76
|
+
Validation is schema-driven (nullability, defaults, generated columns, enums, basic
|
|
77
|
+
SQL types, and batch uniqueness). Optional `formatRules` (`emailColumns` /
|
|
78
|
+
`phoneColumns`) add application-level checks for `text`/`varchar` columns when the
|
|
79
|
+
SQL type alone is not enough — omit them unless the pipeline needs that extra check.
|
|
80
|
+
|
|
81
|
+
After a migration or DDL change, call with `"refreshSchema": true` (or wait for the
|
|
82
|
+
TTL). Otherwise the workspace cache can accept shapes the live table no longer allows;
|
|
83
|
+
`postgres_insert_from_file` remains the DB-level safety net.
|
|
84
|
+
|
|
85
|
+
Boot `permissionRules` can auto-approve `postgres_validate_file` (and insert) when the
|
|
86
|
+
pipeline must not pause on tool approval.
|
|
87
|
+
|
|
88
|
+
The default batch uniqueness key is the first unique key, then the primary key.
|
|
89
|
+
Pass `uniqueColumns` explicitly for composite or non-default keys.
|
|
90
|
+
|
|
91
|
+
## Update file format
|
|
92
|
+
|
|
93
|
+
Flat object — **only columns to change**:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"name": "Updated campaign name",
|
|
98
|
+
"metadata": { "region": "EU", "status": "confirmed" }
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Lookup via tool args (not in the file):
|
|
103
|
+
|
|
104
|
+
- `whereColumn` — defaults to `id`
|
|
105
|
+
- `whereValue` — required unless `resolveWhereValue` is configured at server boot
|
|
106
|
+
|
|
107
|
+
## Workflow
|
|
108
|
+
|
|
109
|
+
1. Optionally inspect the table with `postgres_describe_table`.
|
|
110
|
+
2. Write JSON to the workspace (`write_file`).
|
|
111
|
+
3. Call `postgres_insert_from_file` or `postgres_update_from_file`.
|
|
112
|
+
|
|
113
|
+
## Safety rules
|
|
114
|
+
|
|
115
|
+
- Only write to tables/columns allowed in boot config.
|
|
116
|
+
- Do not include the lookup column in update JSON files.
|
|
117
|
+
- Writes require user approval by default.
|