Phase 9, part 5: file storage, a folder or an S3 bucket

internal/storage keeps files that must outlast the app's disk (exports,
uploads) behind one interface: a folder (<data>/files) or an S3-compatible
bucket (minio-go, path-style, for Garage). Names that would reach outside
the store are refused. An S3 store is checked at start; supermarket config
checks the storage and Postgres for real. The same tests run on a folder
and on Garage (SUPERMARKET_TEST_S3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 07:42:11 -07:00
co-authored by Claude Opus 5.5
parent c76a7791ee
commit d2f1658708
13 changed files with 718 additions and 8 deletions
+5
View File
@@ -241,6 +241,10 @@ collation. New SQL should run on both: use `db.Insert` (not `LastInsertId`),
`ON CONFLICT … DO NOTHING` (not `INSERT OR IGNORE`), table-qualified columns
in an upsert's `DO UPDATE`, and every selected column in `GROUP BY`.
File storage (`internal/storage`) is tested on a folder, and on an
S3-compatible bucket when `SUPERMARKET_TEST_S3` names one, such as a Garage in
Docker: `SUPERMARKET_TEST_S3='http://ACCESS_KEY:SECRET_KEY@127.0.0.1:3900/bucket'`.
**Changing the schema.** Add a `db.Migration` to `both` in
`internal/db/migrations.go`, written in SQLite's SQL. Postgres gets the same
statements translated (`INTEGER` → `BIGINT`, `INTEGER PRIMARY KEY` → an identity
@@ -258,6 +262,7 @@ together), and each is recorded in `schema_migrations`.
| `cmd/supermarket` | The server |
| `internal/config` | The edition (local, server, multi-tenant) and its settings |
| `internal/db` | The database: SQLite or Postgres, the schema and its migrations |
| `internal/storage` | Files that must last (exports, uploads): a folder, or an S3 bucket (Garage) |
| `internal/web` | Pages (Go templates + [htmx](https://htmx.org), no JavaScript build) |
| `internal/profile`, `internal/inventory` | The company profile and the inventory |
| `internal/ai` | AI providers: Anthropic (official Go SDK) and OpenAI-compatible servers |