ReviewOS

stacks/bun-query-builder

Live-DB schema introspection → defineModel codegen (the 'pull' workflow)

#1047
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

The introspect action is currently a stub that only re-reads local model files. But the live-schema reads already exist: db-info.ts queries information_schema.columns/statistics and SQLite PRAGMA table_info/index_list; inspect.ts reads constraints. Reuse those to emit defineModel stubs from an existing database (the Knex/Drizzle "pull" workflow).

Effort: M (SQL already written; net-new is the model-codegen step). Location: src/actions/introspect.ts, db-info.ts, inspect.ts. Found via internal code audit.

9 days ago

Done in 70ea4ff. Added introspectDatabase() + the introspect:db CLI command — reads the live database (sqlite PRAGMA / postgres+mysql information_schema), maps column types to attribute types, and emits defineModel(...) source per table (PascalCase-singular model name, detected primary key, required: true for NOT NULL non-PK columns). Usage: query-builder introspect:db > app/Models/generated.ts. Pure codegen/type-mapping unit tests + a live-sqlite round-trip added; full suite green.

Sign in to comment on this issue.