refactor: 降级 Drizzle ORM 至 0.45.x 稳定版,对齐 Better Auth 兼容性
- drizzle-orm 1.0.0-beta.15 → 0.45.2, drizzle-kit → 0.31.10 - RQBv2 defineRelations() → 旧版 relations() 回调语法 - drizzle-orm/zod → drizzle-zod 独立包 - auth/schema.ts 改由 Better Auth CLI 生成(bun run db:auth) - db/schema/index.ts 选择性导出表(不导出生成文件中的旧版 relations) - 删除 db:push script,强制 db:generate → db:migrate 工作流 - 重建迁移基线(删除旧迁移目录,全新生成初始迁移)
This commit is contained in:
@@ -42,6 +42,7 @@ bun run fix # Lint + format (Biome auto-fix)
|
||||
bun run typecheck # TypeScript check across monorepo
|
||||
|
||||
# Database (in apps/server) — ALWAYS use migration workflow, never db:push
|
||||
bun run db:auth # Regenerate Better Auth schema (after upgrading better-auth)
|
||||
bun run db:generate # Generate migrations from schema changes
|
||||
bun run db:migrate # Run pending migrations
|
||||
bun run db:studio # Open Drizzle Studio
|
||||
@@ -88,13 +89,15 @@ Biome auto-organizes. Order: 1) External packages → 2) Internal `@/*` aliases
|
||||
- ORPC: Use `ORPCError` with proper codes (`NOT_FOUND`, `UNAUTHORIZED`, `INTERNAL_SERVER_ERROR`)
|
||||
- Never use empty catch blocks
|
||||
|
||||
## Database (Drizzle ORM v1 beta + postgres-js)
|
||||
## Database (Drizzle ORM + postgres-js)
|
||||
|
||||
- **ORM**: Drizzle ORM `1.0.0-beta` (RQBv2)
|
||||
- **ORM**: Drizzle ORM `0.45.x` (stable)
|
||||
- **Driver**: `drizzle-orm/postgres-js` (NOT `bun-sql`)
|
||||
- **Validation**: `drizzle-orm/zod` (built-in, NOT separate `drizzle-zod` package)
|
||||
- **Relations**: Defined via `defineRelations()` — RQBv2 object syntax
|
||||
- **Query style**: `db.query.tableName.findMany({ orderBy: { createdAt: 'desc' }, where: { id: 1 } })`
|
||||
- **Validation**: `drizzle-zod` (separate package, NOT `drizzle-orm/zod`)
|
||||
- **Relations**: Defined via `relations()` from `drizzle-orm` — callback syntax
|
||||
- **Query style**: `db.query.tableName.findMany({ where: (t, { eq }) => eq(t.col, val), orderBy: (t, { asc }) => asc(t.col) })`
|
||||
- **Auth schema**: Generated by Better Auth CLI (`bun run db:auth`), **never hand-edit**
|
||||
- **Schema re-export**: `db/schema/index.ts` selectively exports tables only (not relations) from auth schema
|
||||
- **Migration workflow**: Always `db:generate` → `db:migrate`. **Never** use `db:push`.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Reference in New Issue
Block a user