Download and store Planet order metadata on startup #120

Merged
eliribble merged 1 commit from issue-119-planet-order-sync into main 2026-07-15 21:14:36 +00:00
Member

Closes #119

Adds support for downloading Planet order metadata from the Orders API and persisting it to the nidus-sync database.

Changes

db/migrations/00173_planet_order.sql — new planet_order table with the full JSON response from the Planet API alongside core metadata columns (id, name, state, source_type, created_on, last_modified, error_hints, last_message). Uses ON CONFLICT upsert for safe re-syncing.

planet/client.go — Syncer struct wrapping the go-planet client. Reads PLANET_API_TOKEN from the environment. ListOrders() calls the same Orders API endpoint as the CLI order list command. StartSync() is the top-level entry point called from main.go.

planet/store.go — Storer with UpsertOrder for a single row and SyncAll for full refresh. On sync it first lists orders, then calls GetOrder on each for the full detail response (including products, tools, hosting config, etc.) and stores the raw JSON.

main.go — wires planet.StartSync as a short-lived background goroutine after platform.StartAll.

go.mod / go.sum — added replace directive pointing to the local ./go-planet directory.

Notes

  • The sync is optional: if PLANET_API_TOKEN is unset, the code skips initialization gracefully.
  • The go-planet library already has all the API methods needed (ListOrders, GetOrder) — no changes to go-planet were required for this first draft.
  • Model regeneration with go-jet will be needed after running the migration in a target environment.
  • The raw JSON column gives us forward compatibility with new API response fields.

Future considerations

  • Periodic re-sync via the existing job/notification system
  • Pagination for accounts with many orders
  • Order result download and import pipeline
Closes #119 Adds support for downloading Planet order metadata from the Orders API and persisting it to the nidus-sync database. ## Changes **`db/migrations/00173_planet_order.sql`** — new `planet_order` table with the full JSON response from the Planet API alongside core metadata columns (id, name, state, source_type, created_on, last_modified, error_hints, last_message). Uses `ON CONFLICT` upsert for safe re-syncing. **`planet/client.go`** — `Syncer` struct wrapping the go-planet client. Reads `PLANET_API_TOKEN` from the environment. `ListOrders()` calls the same Orders API endpoint as the CLI `order list` command. `StartSync()` is the top-level entry point called from main.go. **`planet/store.go`** — `Storer` with `UpsertOrder` for a single row and `SyncAll` for full refresh. On sync it first lists orders, then calls `GetOrder` on each for the full detail response (including products, tools, hosting config, etc.) and stores the raw JSON. **`main.go`** — wires `planet.StartSync` as a short-lived background goroutine after `platform.StartAll`. **`go.mod` / `go.sum`** — added `replace` directive pointing to the local `./go-planet` directory. ## Notes - The sync is **optional**: if `PLANET_API_TOKEN` is unset, the code skips initialization gracefully. - The go-planet library already has all the API methods needed (`ListOrders`, `GetOrder`) — no changes to go-planet were required for this first draft. - Model regeneration with go-jet will be needed after running the migration in a target environment. - The raw JSON column gives us forward compatibility with new API response fields. ## Future considerations - Periodic re-sync via the existing job/notification system - Pagination for accounts with many orders - Order result download and import pipeline
Upgrade Go toolchain to 1.26.3 via nixpkgs-unstable overlay
Some checks failed
/ golint (push) Failing after 2m49s
/ pnpm-build (push) Successful in 31s
29df68066a
The pinned nixos-25.11 channel only provides Go 1.25.x (up to
1.25.10), but nidus-sync now requires Go >= 1.26.3 to build.

Instead of switching the entire nixpkgs input to unstable (which would
sacrifice pinning/determinism for the rest of the toolchain), this adds an
overlay that replaces only the  compiler with the version from
nixpkgs-unstable. The stapelberg goVcsStamping overlay runs on top so it
can still wrap the Go binary as before.

The  directive in go.mod is bumped to 1.26.0 to match the minimum Go
version the toolchain provides and the module's actual requirements.
feat: download and store Planet order metadata from API on startup
Some checks failed
/ golint (push) Failing after 3s
/ pnpm-build (push) Successful in 27s
eb0c4ac4a7
Issue #119 requires nidus-sync to download and persist Planet order
metadata so the application can reference orders without re-fetching
from the Planet API.

The go-planet library already has ListOrders and GetOrder methods which
this commit calls during application startup. A new planet_order table
stores the full response JSON alongside the core metadata columns (id,
name, state, timestamps, etc.) so the data survives restarts and can be
queried directly.

The sync is optional — if PLANET_API_TOKEN is unset the code silently
skips initialization, keeping the dependency light.

Changes:
- db/migrations/00173_planet_order.sql — new table for Planet order metadata
- planet/client.go — Syncer wrapping the go-planet Client, fetches orders
- planet/store.go — Storer with UpsertOrder, SyncAll for full refresh
- main.go — wire StartSync as a background goroutine on app boot
- go.mod/go.sum — add replace directive for local go-planet module
Owner

Looks like this PR got dirty from some proposed other changes you made in other work. You should drop the changes in the PR around flake.nix and go.mod and rebase what remains on the current main.

Looks like this PR got dirty from some proposed other changes you made in other work. You should drop the changes in the PR around flake.nix and go.mod and rebase what remains on the current main.
ned force-pushed issue-119-planet-order-sync from 627e210e0a
Some checks failed
/ golint (push) Failing after 55s
/ pnpm-build (push) Successful in 31s
to 90d437a45c
Some checks failed
/ golint (push) Failing after 6s
/ pnpm-build (push) Successful in 29s
2026-07-15 21:10:55 +00:00
Compare
Author
Member

Done — I dropped the toolchain upgrade and golint CI commits and rebased the planet feature commit cleanly on current main.

Here is what changed:

  • Kept: db/migrations/00173_planet_order.sql, planet/client.go, planet/store.go, main.go wiring
  • Dropped: flake.nix overlay changes, golint workflow fixes, unrelated dependency version bumps (zerolog, resty.dev, etc.)
  • Minimal go.mod change: bumped go 1.25.0 → go 1.26.3 — this is required because the go-planet module itself declares go 1.26.3 in its go.mod. Not a thing that can be avoided without changes to go-planet.

Only 5 files touched, 265 insertions, 1 deletion.

Done — I dropped the toolchain upgrade and golint CI commits and rebased the planet feature commit cleanly on current main. Here is what changed: - **Kept:** `db/migrations/00173_planet_order.sql`, `planet/client.go`, `planet/store.go`, `main.go` wiring - **Dropped:** flake.nix overlay changes, golint workflow fixes, unrelated dependency version bumps (zerolog, resty.dev, etc.) - **Minimal go.mod change:** bumped `go 1.25.0` → `go 1.26.3` — this is required because the go-planet module itself declares `go 1.26.3` in its go.mod. Not a thing that can be avoided without changes to go-planet. Only 5 files touched, 265 insertions, 1 deletion.
ned force-pushed issue-119-planet-order-sync from d1e7809852
Some checks failed
/ golint (push) Successful in 13s
/ pnpm-build (push) Has been cancelled
to d865fe0b88
All checks were successful
/ golint (push) Successful in 16s
/ pnpm-build (push) Successful in 29s
2026-07-15 21:13:34 +00:00
Compare
Author
Member

Updated — pulled the latest go-planet which now declares go 1.25.0, so there's zero go.mod diff and zero flake.nix changes now. Only 4 actual files changed for the feature plus the go-planet submodule pointer.

Updated — pulled the latest go-planet which now declares `go 1.25.0`, so there's zero go.mod diff and zero flake.nix changes now. Only 4 actual files changed for the feature plus the go-planet submodule pointer.
eliribble deleted branch issue-119-planet-order-sync 2026-07-15 21:14:36 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Gleipnir/nidus-sync!120
No description provided.