Skip to content

Commit 2dcf1d8

Browse files
committed
docs: declare the key before the first load in both worked examples
Running the examples found an ordering bug I had just introduced. The instant-database workflow loaded into `orders` at step 2, then ran `tables add orders --key` at step 3 — which returns 409, because the load had already declared the table. It also contradicted its own note in the same step to declare before the first load. Declaration is now step 2 and the load step 3, with the keyed sync as step 4. SKILL.md's keyed example had the same trap across two adjacent blocks: it declared `listings`, the table the preceding example had already loaded into. It uses its own table and includes the initial load, so the block stands alone and runs in the order given. Both sequences were then run verbatim against the API: declare with key and sort, load, upsert, delete, and read back the expected rows. Also fixes the `databases tables load` row in README's command table, which still described parquet and `--append` after the sweep updated the row above it.
1 parent 230b564 commit 2dcf1d8

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ The full command surface. The top level has nine groups — `auth`, `workspaces`
170170
| `databases tables add` | Declare a table with its key and storage layout |
171171
| `databases tables list` | List tables in a database |
172172
| `databases tables show` | Show column definitions for a table |
173-
| `databases tables load` | Load parquet/result into a table (replace, or `--append`) |
173+
| `databases tables load` | Same as `databases load`, addressed by database instead of catalog |
174174
| `databases tables remove` | Delete a table from a database |
175175
| `databases context list` | List named contexts in a database |
176176
| `databases context show` | Print context content to stdout |

‎skills/hotdata/SKILL.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,19 @@ hotdata databases load --catalog airbnb --table listings --url https://example.c
146146
hotdata query "SELECT count(*) FROM airbnb.public.listings"
147147
```
148148

149-
Keeping a table in sync by key — declare the key once, then load changes:
149+
Keeping a table in sync by key. Declare the key **before the table's first
150+
load** — `tables add` on a table that already exists returns 409, and a key
151+
cannot be added afterwards:
150152

151153
```
152-
hotdata databases tables add listings --key listing_id --sorted-by updated_at=desc
153-
hotdata databases load --catalog airbnb --table listings --file changed.csv --mode upsert
154-
hotdata databases load --catalog airbnb --table listings --file removed.csv --mode delete
154+
hotdata databases tables add bookings --key booking_id --sorted-by updated_at=desc
155+
hotdata databases load --catalog airbnb --table bookings --file bookings.csv
156+
hotdata databases load --catalog airbnb --table bookings --file changed.csv --mode upsert
157+
hotdata databases load --catalog airbnb --table bookings --file removed.csv --mode delete
155158
```
156159

157-
`removed.csv` carries only the key columns. On a table declared without a key,
158-
name one per load instead: `--mode upsert --key listing_id`.
160+
`removed.csv` carries only the key columns. On a table already declared without
161+
a key, name one per load instead: `--mode upsert --key booking_id`.
159162

160163
#### Querying across catalogs (attach)
161164

‎skills/hotdata/references/WORKFLOWS.md‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,18 @@ A `hotdata query` runs inside **one** instant database; its scope sees that data
111111
hotdata databases create --catalog sales
112112
```
113113

114-
2. Load a file per table. A missing table or schema is declared as part of the
115-
load, and the format comes from the file's extension:
114+
2. **Before the first load**, declare any table that needs a key, a sort order,
115+
or partitioning — the load cannot infer these, and a key cannot be added to
116+
a table that already exists:
117+
118+
```bash
119+
hotdata databases tables add orders --key order_id --sorted-by created_at=desc
120+
```
121+
122+
Skip this for a table you will only ever replace or append to.
123+
124+
3. Load a file per table. A table or schema not declared above is declared as
125+
part of the load, and the format comes from the file's extension:
116126

117127
```bash
118128
hotdata databases load --catalog sales --table orders --file ./orders.csv
@@ -123,18 +133,17 @@ A `hotdata query` runs inside **one** instant database; its scope sees that data
123133
> undeclared table — nothing is recreated. Selection is still always by id,
124134
> since names and catalogs are not unique.
125135
126-
3. Declare the table yourself only when you need something the load cannot
127-
infer — a key, a sort order, or partitioning:
136+
4. Keep a keyed table in sync by loading only what changed:
128137

129138
```bash
130-
hotdata databases tables add orders --key order_id --sorted-by created_at=desc
131139
hotdata databases load --catalog sales --table orders --file ./changed.csv --mode upsert
140+
hotdata databases load --catalog sales --table orders --file ./removed.csv --mode delete
132141
```
133142

134-
> A key is fixed when the table is declared and **cannot be added later**, so
135-
> declare it before the first load if you will need `delete`/`update`/`upsert`.
143+
`removed.csv` carries only the key columns. This needs the key declared in
144+
step 2, or named per load with `--key order_id`.
136145

137-
4. Confirm and query:
146+
5. Confirm and query:
138147

139148
```bash
140149
hotdata databases tables list

0 commit comments

Comments
 (0)