Cursor rule
.cursor/rules/database.mdc[object Object]
Cursor rules
Quality
61/100
Scores the file, not the repository.Length
560 words
5 headings · 6 code blocksRepository
0
— · pushed 396 days agoLast changed
3 days ago
First indexed 3 days ago.123456## Database78Find the schema here: [schema.sql](mdc:packages/db/schema.sql)910### Commands1112Run from the root directory:1314- `DATABASE_URL=postgres://localhost:5432/monorepo-scaffold pnpm --filter @app/db db:migrate:create <name>` - Create a new database migration template15- `DATABASE_URL=postgres://localhost:5432/monorepo-scaffold pnpm --filter @app/db db:migrate` - Run database migrations16- `DATABASE_URL=postgres://localhost:5432/monorepo-scaffold pnpm --filter @app/db db:migrate:down` - Rollback database migrations17- `DATABASE_URL=postgres://localhost:5432/monorepo-scaffold pnpm --filter @app/db db:reset` - Reset database18- `DATABASE_URL=postgres://localhost:5432/monorepo-scaffold pnpm --filter @app/db db:seed` - Seed database with initial data (default tenant and permissions)1920### Create a new migration21221. Run `db:migrate:create <myname>`232. Edit the file it creates243. Run `db:migrate`2526Do not generate types.gen.ts files yourself - they'll be auto generated.2728### Using Kysely Type Helpers2930When working with database types in TypeScript, always use Kysely's type helper utilities for proper type safety:31321. **Selectable<T>** - Use when selecting/reading data from the database:33```typescript34 import type { Selectable } from 'kysely'35 import type { User } from '@app/db/types'3637 // Function that returns user data from DB38 async function getUser(id: string): Promise<Selectable<User> | null> {39 return await db.selectFrom('users').where('id', '=', id).selectAll().executeTakeFirst()40 }4142 // Component props43 interface UserProfileProps {44 user: Selectable<User>45 }46```47482. **Insertable<T>** - Use when inserting data into the database:49```typescript50 import type { Insertable } from 'kysely'51 import type { Project } from '@app/db/types'5253 // Function parameters for creating records54 async function createProject(data: Insertable<Project>): Promise<Selectable<Project>> {55 return await db.insertInto('projects').values(data).returningAll().executeTakeFirstOrThrow()56 }5758 // Partial inserts with required fields59 async function createUser(data: Partial<Insertable<User>> & { email: string; tenantId: string }) {60 return await db.insertInto('users').values({61 emailVerified: false,62 status: 'active',63 ...data,64 }).returningAll().executeTakeFirstOrThrow()65 }66```67683. **Updateable<T>** - Use when updating records in the database:69```typescript70 import type { Updateable } from 'kysely'71 import type { Task } from '@app/db/types'7273 async function updateTask(id: string, data: Updateable<Task>): Promise<Selectable<Task>> {74 return await db.updateTable('tasks')75 .set(data)76 .where('id', '=', id)77 .returningAll()78 .executeTakeFirstOrThrow()79 }80```81824. **General Guidelines**:83 - Never use raw table types directly (e.g., `User`, `Project`) for function parameters or return types84 - Always wrap with appropriate helper based on the operation85 - For partial updates/inserts, combine `Partial<Insertable<T>>` or `Partial<Updateable<T>>` with required fields86 - When passing database records between functions/components, use `Selectable<T>`87 - We use underscore naming for table columns in the database, but Kysely always maps these to camelCase names. So from within TypeScript, you will need to use camelCase when interacting with a column, say, using it in a `where` condition.88 - **Timestamp columns are typed as `Date`**: Columns like `TIMESTAMP` or `TIMESTAMPTZ` are automatically returned as JavaScript `Date` objects (not strings). You can safely call `getTime()` etc. without parsing.8990### Handling JSONB Types9192When working with JSONB columns in the database, you need to specify proper TypeScript types to ensure type safety. Follow these steps:93941. **Create column type definitions** in `packages/db/src/column-types.ts`:9596```typescript97export type ProjectStage = {98 name: string99 description: string100}101102// Includes RawBuilder to allow for JSONB103export type ProjectStageColumnType = ColumnType<104 ProjectStage[] | null,105 ProjectStage[] | null | RawBuilder<ProjectStage[]>,106 ProjectStage[] | null | RawBuilder<ProjectStage[]>107>108```1091102. **Reference the type in Kysely codegen configuration** in `packages/db/.kysely-codegenrc.yaml`:111112```yaml113serializer-properties:114 'public.projects.stages': 'import("./src/column-types").ProjectStageColumnType | null'115```1161173. **Use the type in your migrations**:118119```sql120ALTER TABLE projects ADD COLUMN tools_config JSONB;121```122123The types will be automatically generated and available through `@app/db/types` after running the migration and type generation.124125**Important**: Always define explicit TypeScript interfaces for JSONB columns rather than using generic types like `any` or `unknown`. This ensures type safety throughout the application.
Also in poglesbyg/htsf-consultant
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| poglesbyg/htsf-consultant.cursor/rules/always.mdc · 0 | Cursor rules | test | 35/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/code-conventions.mdc · 0 | Cursor rules | setuplint-formatstyledo-not+1 | 80/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/crispr-algorithms.mdc · 0 | Cursor rules | deployment | 44/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/data-models.mdc · 0 | Cursor rules | typessecuritydatabase | 44/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/env-vars.mdc · 0 | Cursor rules | securitydo-not | 63/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/react.mdc · 0 | Cursor rules | style | 34/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/shadcn-components.mdc · 0 | Cursor rules | ui | 63/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/smart-polling.mdc · 0 | Cursor rules | no sections | 44/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/trpc-architecture.mdc · 0 | Cursor rules | archtypes | 56/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/trpc.mdc · 0 | Cursor rules | no sections | 40/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/typescript.mdc · 0 | Cursor rules | styletypesdo-not | 55/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursorrules · 0 | .cursorrules | archdeploymentagent-behaviour | 48/100 | 3 days ago |
Diff against .cursor/rules/always.mdc Diff against .cursor/rules/code-conventions.mdc Diff against .cursor/rules/crispr-algorithms.mdc Diff against .cursor/rules/data-models.mdc Diff against .cursor/rules/env-vars.mdc Diff against .cursor/rules/react.mdc Diff against .cursor/rules/shadcn-components.mdc Diff against .cursor/rules/smart-polling.mdc Diff against .cursor/rules/trpc-architecture.mdc Diff against .cursor/rules/trpc.mdc Diff against .cursor/rules/typescript.mdc Diff against .cursorrules
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
