Repository navigation
Commit f638d12
authored
fix(db): treat files in db/schema/ beside db/schema.ts as schema files (#504)
Refs #472
Same cause as #472, hit by the default output of `void gen model`. The
#472 layout is not fixed here.
`void gen model` writes `db/schema/<name>.ts`, re-exports it from
`db/schema.ts`, and the generated file imports `sql` from `void/db`.
When `db/schema.ts` exists, the plugin treats only that file as a schema
file. `db/schema/<name>.ts` gets `virtual:void-db`, which imports the
schema, so the import goes around: `db/schema.ts` →
`db/schema/<name>.ts` → `virtual:void-db` → `db/schema.ts`. In dev,
`sql` is not ready yet and every page that imports `void/db` returns 500
(`TypeError: __vite_ssr_import_1__.sql is not a function`). `vp build` →
`vp preview` works.
To reproduce:
```sh
pnpm create void my-app # React / D1
cd my-app
pnpm add zod
pnpm exec void gen model todos title:string done:boolean
pnpm exec void db generate
pnpm dev # / and /api/todos return 500
```
This PR also treats files under `db/schema/` as schema files when
`db/schema.ts` exists. The folder comes from `paths.schemaDir`, the same
path `gen model` writes to.
Out of scope: the #472 layout (a file outside `db/schema/` re-exported
from `db/schema.ts`). Moving the `drizzle-orm` re-export above the
schema import in `virtual:void-db` makes `sql` ready in dev for that
case too (checked locally), but it makes the import order matter, so it
is not in this PR.
Checked:
- `plugin-drizzle.test.ts` (1 new test, fails without the fix)
- typecheck for `void`
- an app after `gen model`: dev (500 → 200) and `vp build` → `vp
preview` (200 before and after)
14 tests in `init.test.ts` and 1 in `nitro.test.ts` fail locally on main
too. This PR adds no new failures.1 parent 3b5a6fc commit f638d12
2 files changed
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
753 | 771 | | |
754 | 772 | | |
755 | 773 | | |
| |||
0 commit comments