Describe the bug
Running pnpm db:pull (which runs drizzle-kit pull) in packages/db completely rewrites packages/db/drizzle/schema.ts and packages/db/drizzle/relations.ts, discarding hand-maintained customizations that the introspector cannot reproduce. On the current main (ad24abc0), a single db:pull produces a ~1,570-line diff across the two files (+752 / -820 in one run).
The regeneration is lossy in ways that break type safety and our lint/format conventions, so the output can't just be committed as-is — it has to be manually reconciled every time, which defeats the purpose of the pull.
What gets lost / changed
-
Typed json columns lose their $type<>() annotations. Hand-written columns like:
settings: json().$type<SlackSpacesMeta>(),
meta: json().$type<UserMeta>(),
eventMeta: json("event_meta").$type<EventMeta>(),
are regenerated as untyped json(). This drops compile-time type safety on every meta column (SlackSpacesMeta, SlackUserMeta, UserMeta, EventMeta, OrgMeta, LocationMeta, AttendanceMeta, UpdateRequestMeta).
-
Shared enum/type imports are dropped and enums are re-inlined. The maintained file imports enums and meta types from @acme/shared/app/enums and @acme/shared/app/types:
import { AchievementCadence, DayOfWeek, /* … */ } from "@acme/shared/app/enums";
import type { AttendanceMeta, EventMeta, /* … */ } from "@acme/shared/app/types";
db:pull deletes these imports and re-inlines every enum as a literal pgEnum(...) definition, so the schema no longer shares a single source of truth with the app.
-
Import ordering is scrambled in both files (imports are emitted in introspection order, not our prettier/eslint sorted order), producing large no-op churn on top of the real changes.
To reproduce
cd packages/db
pnpm db:pull
git diff drizzle/schema.ts drizzle/relations.ts
Observe a full rewrite of both files, with the losses listed above.
Expected
pnpm db:pull should be usable to sync schema changes from the database without destroying the typed-json annotations, shared @acme/shared imports, and import ordering — or the workflow should be documented so a pull can be reconciled against the maintained file instead of overwriting it.
Additional information
drizzle.config.ts points schema at ./drizzle/schema.ts and out at ../db/drizzle, so the pull writes back over the hand-maintained files.
- Affected files:
packages/db/drizzle/schema.ts, packages/db/drizzle/relations.ts.
- Observed on
main @ ad24abc0.
Possible directions
- Introspect into a separate throwaway path (the config already has a commented
out: "../db/src/schema" line) and diff/merge manually, keeping drizzle/schema.ts as the authored source.
- Or add a post-pull codemod/script that re-applies the
$type<>() annotations, shared imports, and formatting.
Describe the bug
Running
pnpm db:pull(which runsdrizzle-kit pull) inpackages/dbcompletely rewritespackages/db/drizzle/schema.tsandpackages/db/drizzle/relations.ts, discarding hand-maintained customizations that the introspector cannot reproduce. On the currentmain(ad24abc0), a singledb:pullproduces a ~1,570-line diff across the two files (+752 / -820in one run).The regeneration is lossy in ways that break type safety and our lint/format conventions, so the output can't just be committed as-is — it has to be manually reconciled every time, which defeats the purpose of the pull.
What gets lost / changed
Typed
jsoncolumns lose their$type<>()annotations. Hand-written columns like:are regenerated as untyped
json(). This drops compile-time type safety on every meta column (SlackSpacesMeta,SlackUserMeta,UserMeta,EventMeta,OrgMeta,LocationMeta,AttendanceMeta,UpdateRequestMeta).Shared enum/type imports are dropped and enums are re-inlined. The maintained file imports enums and meta types from
@acme/shared/app/enumsand@acme/shared/app/types:db:pulldeletes these imports and re-inlines every enum as a literalpgEnum(...)definition, so the schema no longer shares a single source of truth with the app.Import ordering is scrambled in both files (imports are emitted in introspection order, not our prettier/eslint sorted order), producing large no-op churn on top of the real changes.
To reproduce
cd packages/dbpnpm db:pullgit diff drizzle/schema.ts drizzle/relations.tsObserve a full rewrite of both files, with the losses listed above.
Expected
pnpm db:pullshould be usable to sync schema changes from the database without destroying the typed-json annotations, shared@acme/sharedimports, and import ordering — or the workflow should be documented so a pull can be reconciled against the maintained file instead of overwriting it.Additional information
drizzle.config.tspointsschemaat./drizzle/schema.tsandoutat../db/drizzle, so the pull writes back over the hand-maintained files.packages/db/drizzle/schema.ts,packages/db/drizzle/relations.ts.main@ad24abc0.Possible directions
out: "../db/src/schema"line) and diff/merge manually, keepingdrizzle/schema.tsas the authored source.$type<>()annotations, shared imports, and formatting.