fix(seed): apply migrations, and fail loudly instead of skipping
Seeding a database the app had never opened failed with 'no such table: documents' once per file, counted each as a skip, and then printed '0 documents seeded' as though that were a result. That is the plausible empty outcome this codebase calls the worst available failure shape, in my own tooling, in the path the README tells Paul to use. Migrations are applied now, and a failed ingest is fatal.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SiWVaR69Vb2Lzc9wgfit1v
1 file changed,
+15
−3
tools/seed/main.go+15 −3
diff --git a/tools/seed/main.go b/tools/seed/main.go| index 9ac7dbf..974a33a 100644 |
| --- a/tools/seed/main.go |
| +++ b/tools/seed/main.go |
| @@ -20,6 +20,7 @@ import ( |
| "strings" |
| "github.com/carlosframework/rastrillo/db" |
| + "github.com/carlosframework/rastrillo/migrate" |
| memoria "amadan.net/oficina/memoria/internal/memoria" |
| "amadan.net/oficina/memoria/internal/memoria/index" |
| @@ -60,6 +61,16 @@ func main() { |
| } |
| defer d.Close() |
| + // Apply migrations. Without this, seeding a database the app has |
| + // never opened fails with "no such table: documents" once per file |
| + // and then reports success with nothing seeded — which is a |
| + // plausible empty result, and exactly the shape this codebase treats |
| + // as the worst available failure. |
| + if _, err := migrate.Apply(context.Background(), d, memoria.BootSchema); err != nil { |
| + fmt.Fprintf(os.Stderr, "migrate: %v\n", err) |
| + os.Exit(1) |
| + } |
| + |
| ix, err := index.Open() |
| if err != nil { |
| fmt.Fprintf(os.Stderr, "open index: %v\n", err) |
| @@ -100,9 +111,10 @@ func main() { |
| rel, _ := filepath.Rel(*root, p) |
| title := rel |
| if _, err := store.Ingest(ctx, *source, title, string(raw)); err != nil { |
| - fmt.Fprintf(os.Stderr, "skip %s: %v\n", rel, err) |
| - skipped++ |
| - return nil |
| + // Fatal, not a skip. An earlier version counted these and |
| + // carried on, so a missing table produced 59 skips and a |
| + // cheerful "0 documents seeded" summary. |
| + return fmt.Errorf("ingest %s: %w", rel, err) |
| } |
| n++ |
| fmt.Printf("seeded %s\n", rel) |