
Drizzle Schemas and Queries
Writes Drizzle tables, indexes, relations and typed queries.
Install
npx skills add lobehub/lobehub --skill drizzle -g -a claude-code -y- Repository
- lobehub/lobehub83.7k
- Category
- Engineering
- Updated
- 3d ago
- License
- See repository
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Use for Drizzle schemas and queries: tables, indexes, relations, joins and inferred types. Rollout belongs to db-migrations.
Drizzle ORM Schema Style Guide
Adding a Model or Repository? Ship a sibling test in the same PR, every new file under
packages/database/src/models/**orsrc/repositories/**needs a matching__tests__/<name>.test.ts. See the testing skill (.agents/skills/testing/references/db-model-test.md) for thegetTestDB()integration pattern, user-isolation tests, the BM25describe.skipIf(!isServerDB)guard, and schema gotchas. CI's coverage patch gate won't reliably catch a brand-new untested file, so this is on you.
Configuration
- Config:
drizzle.config.ts - Schemas:
packages/database/src/schemas/ - Migrations:
packages/database/migrations/ - Dialect:
postgresqlwithstrict: true
Helper Functions
Location: packages/database/src/schemas/_helpers.ts
timestamptz(name): Timestamp with timezonecreatedAt(),updatedAt(),accessedAt(): Standard timestamp columnstimestamps: Object with all three for easy spread
Naming Conventions
- Tables: Plural snake_case (
users,session_groups) - Columns: snake_case (
user_id,created_at) - New tables: Check nearby existing tables before naming a new one. Preserve
the established noun family and suffix. For example, if the user-scoped table
is
user_xxx_logs, the workspace-scoped counterpart should beworkspace_xxx_logs, notworkspace_xxx_recordsor another new synonym.
// ✅ Good: follows the existing user/workspace table family (names are
// illustrative, swap `widget` for the real noun).
export const userWidgetLogs = pgTable('user_widget_logs', { ... });
export const workspaceWidgetLogs = pgTable('workspace_widget_logs', { ... });
// ❌ Bad: introduces a new suffix for the same concept.
export const workspaceWidgetRecords = pgTable('workspace_widget_records', { ... });
