drizzle-database
Drizzle Database Patterns
Use this skill to implement and review Drizzle ORM schema and query code with project-consistent typing, relation modeling, and migration/test verification.
When to Use This Skill
Use this skill when work explicitly involves Drizzle ORM primitives, for example:
pgTable(...)schema definitions- relation declarations with
relations(...) - Drizzle select/query builder composition (
db.select,db.query.*) - Drizzle migrations and schema evolution
- typed test DB seeding for Drizzle-backed tests
Avoid triggering this skill for generic SQL/database discussions that are not tied to Drizzle implementation.
Canonical Workflow
Apply this sequence for every schema/query change:
- Inspect nearby schema helpers and existing Drizzle patterns in the target repository.
- Copy an established local pattern (types, naming, indexes, relation style) instead of inventing a new style.
- Implement the minimal schema/query change required.
- Verify generated/applied migration output is coherent with the change.
- Run related tests that exercise the changed table/query path.
Read full examples in:
references/schema-patterns.mdreferences/query-patterns.mdreferences/migrations-and-testing.md
Conventions and Rules
Always-rules
- Keep relation cardinality explicit (
onevsmany) and match FK fields to referenced IDs. - Keep optional vs required joins explicit (
leftJoinfor optional,innerJoinfor required). - Verify migrations and tests after schema changes before considering the task complete.
Project conventions (apply unless local codebase uses another established pattern)
- Prefer branded/typed IDs on columns when the project uses them.
id: text("id").primaryKey().$type<UserId>();
- Prefer
.$defaultFn(...)for generated IDs/timestamps when existing tables follow that style.
createdAt: timestamp("created_at")
.$defaultFn(() => new Date())
.notNull();
- Place indexes/compound constraints in the third
pgTableargument when local schema files do so.
(table) => [
index("sessions_user_id_idx").on(table.userId),
unique().on(table.userId, table.organizationId),
];
- Pass full schema to
drizzle(...)when the codebase relies on relational query helpers.
Query Strategy Guidance
Prefer a single composed query (joins/select projection) when it reduces round trips and keeps logic readable.
Use relation query helpers (db.query.<table>.findMany/findFirst with with) when they express the read clearly, keep types clean, and avoid unnecessary query complexity.
Escalate to custom join/aggregation queries when relation helpers cannot represent required filtering, projection, or aggregation efficiently.
Scope Boundaries
Focus this skill on Drizzle schema/query/migration implementation patterns.
Delegate broader database performance triage and production indexing strategy to process-db-report or performance-optimization when the task is primarily performance investigation.
Resources
Load detailed examples only when needed:
references/schema-patterns.md- Full table, relation, typing, and index examplesreferences/query-patterns.md- Full query, join, aggregation, and mutation examplesreferences/migrations-and-testing.md- Migration workflow and test/seed examples
More from blogic-cz/blogic-marketplace
frontend-design
This skill should be used when a task requires designing or implementing frontend UI (components, pages, layouts, styling) and no more specialized frontend skill is a better fit. It guides production-grade, brand-consistent visual implementation with distinctive but controlled aesthetics.
77testing-patterns
This skill should be used when implementing or reviewing testing workflows in template-ts projects, especially for testing, Vitest, Playwright, integration test, and mocking scenarios.
76update-packages
This skill should be used when upgrading dependencies, bumping packages, resolving outdated dependencies, or performing dependency updates. It guides safe Bun-based package upgrades with breaking-change handling, runtime pin alignment, and grouped version coordination.
75code-review
This skill should be used when running a code review or pre-PR review in template-ts repositories. It provides a severity-based checklist for architecture, security, performance, and testing quality gates.
73tdd
This skill should be used when a task explicitly asks for TDD, test-first development, or the Red-Green-Refactor cycle. It guides incremental implementation with concrete Red-Green-Refactor examples, including Effect service patterns with mock layers.
71sentry-integration
This skill should be used when implementing or debugging Sentry error tracking, instrumentation, distributed tracing, performance issues, or capture-errors flows. It provides a portable workflow for SDK setup, middleware wiring, expected-error classification, and verification.
71