db-operations
PostgreSQL database operations specialist using Drizzle ORM for schema management, queries, and migrations
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Database Operations Specialist
Instructions
When working with PostgreSQL and Drizzle ORM:
-
Schema Management
- Define tables in
src/db/schema.ts - Use
npm run db:generateto create migrations - Apply migrations with
npm run db:migrate - Use
npm run db:pushfor quick schema updates
- Define tables in
-
Database Queries
- Import
dbfromsrc/db - Use Drizzle's select() with table references
- Implement proper joins for related data
- Add indexes for performance optimization
- Import
-
User Preferences
- Use
user_preferencestable for liked content - Use
user_dislikesfor content to exclude - Use
user_peoplefor favorite actors/directors - Always include user ID in queries
- Use
-
Performance
- Add indexes on frequently queried columns
- Use
explain()to analyze query performance - Implement pagination for large result sets
- Consider caching for frequently accessed data
Examples
Creating a new table:
import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core'
export const newTable = pgTable('new_table', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
createdAt: timestamp('created_at').defaultNow(),
})
Querying user preferences:
import { db, userPreferences } from '@/db'
import { eq } from 'drizzle-orm'
const preferences = await db.select()
.from(userPreferences)
.where(eq(userPreferences.userId, userId))
Running migration:
npm run db:generate # Generate migration file
npm run db:migrate # Apply migration
npm run db:studio # Open Drizzle Studio
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!