Skip to content

Commit b7d7078

Browse files
committed
docs: Update CLAUDE.md with goose migration documentation
1 parent 189a6da commit b7d7078

1 file changed

Lines changed: 87 additions & 4 deletions

File tree

CLAUDE.md

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Developer Guide for AI Assistants
22

3-
**Last Updated:** December 2024
3+
**Last Updated:** January 2025
44
**Project Status:** Production-ready CLI application with Web UI
55

66
## What This Project Is
@@ -333,6 +333,9 @@ Ask yourself:
333333
- **costco-go** - [github.com/eshaffer321/costco-go](https://github.com/eshaffer321/costco-go)
334334
- Fetches Costco orders
335335
- Uses saved credentials
336+
- **goose** - [github.com/pressly/goose/v3](https://github.com/pressly/goose)
337+
- Database migration management
338+
- SQL and Go migrations supported
336339

337340
### API Integrations
338341
- **OpenAI GPT-4** - Item categorization (~$0.01-0.05 per order)
@@ -342,7 +345,45 @@ Ask yourself:
342345

343346
## Database Schema
344347

345-
SQLite database at `monarch_sync.db` with auto-migration:
348+
SQLite database at `monarch_sync.db` with auto-migration using [goose](https://github.com/pressly/goose).
349+
350+
### Migration System
351+
352+
Migrations are managed by **goose** and stored as SQL files in `internal/infrastructure/storage/migrations/`:
353+
354+
```
355+
migrations/
356+
├── 00001_initial_schema.sql # processing_records table
357+
├── 00002_add_sync_runs_table.sql # sync_runs table
358+
├── 00003_add_api_calls_table.sql # api_calls table
359+
├── 00004_backfill_null_values.sql
360+
├── 00005_add_ledger_tables.sql # order_ledgers, ledger_charges
361+
├── 00006_add_charged_at_column.sql
362+
└── 00007_goose_bridge.go # Bridge migration for legacy system
363+
```
364+
365+
**Adding a new migration:**
366+
```bash
367+
# Create a new SQL migration
368+
touch internal/infrastructure/storage/migrations/00008_your_migration.sql
369+
370+
# Use goose format:
371+
# -- +goose Up
372+
# CREATE TABLE ...
373+
# -- +goose Down
374+
# DROP TABLE ...
375+
```
376+
377+
**Migration commands** (via goose CLI if installed):
378+
```bash
379+
goose -dir internal/infrastructure/storage/migrations sqlite3 ./monarch_sync.db status
380+
goose -dir internal/infrastructure/storage/migrations sqlite3 ./monarch_sync.db up
381+
goose -dir internal/infrastructure/storage/migrations sqlite3 ./monarch_sync.db down
382+
```
383+
384+
Note: Migrations run automatically on app startup. The goose CLI is optional for manual operations.
385+
386+
### Core Tables
346387

347388
```sql
348389
-- Processing history and deduplication
@@ -356,7 +397,7 @@ CREATE TABLE processing_records (
356397
item_count INTEGER,
357398
split_count INTEGER,
358399
processed_at TIMESTAMP,
359-
status TEXT, -- 'success', 'failed', 'dry-run'
400+
status TEXT, -- 'success', 'failed', 'dry-run', 'pending'
360401
error_message TEXT,
361402
match_confidence REAL,
362403
dry_run BOOLEAN
@@ -374,9 +415,51 @@ CREATE TABLE sync_runs (
374415
dry_run BOOLEAN,
375416
lookback_days INTEGER
376417
);
418+
419+
-- API call logging
420+
CREATE TABLE api_calls (
421+
id INTEGER PRIMARY KEY,
422+
run_id INTEGER REFERENCES sync_runs(id),
423+
order_id TEXT,
424+
method TEXT,
425+
request_json TEXT,
426+
response_json TEXT,
427+
error TEXT,
428+
duration_ms INTEGER
429+
);
430+
431+
-- Order payment ledgers (Walmart multi-charge tracking)
432+
CREATE TABLE order_ledgers (
433+
id INTEGER PRIMARY KEY,
434+
order_id TEXT,
435+
provider TEXT,
436+
ledger_state TEXT,
437+
ledger_json TEXT,
438+
total_charged REAL,
439+
charge_count INTEGER
440+
);
441+
442+
CREATE TABLE ledger_charges (
443+
id INTEGER PRIMARY KEY,
444+
order_ledger_id INTEGER REFERENCES order_ledgers(id),
445+
order_id TEXT,
446+
charge_amount REAL,
447+
charge_type TEXT,
448+
charged_at TIMESTAMP,
449+
monarch_transaction_id TEXT,
450+
is_matched BOOLEAN
451+
);
452+
453+
-- Goose migration tracking (managed by goose)
454+
CREATE TABLE goose_db_version (
455+
id INTEGER PRIMARY KEY,
456+
version_id INTEGER,
457+
is_applied INTEGER,
458+
tstamp TIMESTAMP
459+
);
377460
```
378461

379-
Schema auto-migrates on startup. See [internal/infrastructure/storage/storage.go](internal/infrastructure/storage/storage.go).
462+
See [internal/infrastructure/storage/sqlite.go](internal/infrastructure/storage/sqlite.go) for the storage implementation.
380463

381464
## Project Scope
382465

0 commit comments

Comments
 (0)