-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
name: Bug Report
about: Database Schema Circular Reference Issue
title: "[BUG] Database Schema Uses Unsafe Type Workaround for Circular References"
labels: bug, database, typescript, medium-priority
assignees: ''
🐛 Bug Description
The database schema in packages/database/drizzle/schema.ts
contains a circular reference issue where usersTable.workspaceId
references workspacesTable.id
using an unsafe TypeScript workaround (): any => workspacesTable.id
. This breaks type safety and indicates improper schema design that could lead to runtime errors and degraded developer experience.
🔄 Steps to Reproduce
- Navigate to
packages/database/drizzle/schema.ts
- Examine line 16-18 in the
usersTable
definition - Observe the
workspaceId
field using(): any => workspacesTable.id
- Run TypeScript compilation or IDE type checking
- Notice type safety warnings and potential runtime issues
📱 Expected Behavior
The database schema should:
- Use proper forward references without
any
types - Maintain full TypeScript type safety
- Follow Drizzle ORM best practices for circular references
- Generate clean, type-safe database operations
- Provide proper IntelliSense and autocompletion
🔍 Possible Solution
Option 1: Restructure Schema (Recommended)
Option 2: Use Drizzle Forward References
Option 3: Use String References
Implementation Steps
- Analyze current usage of
usersTable.workspaceId
- Choose appropriate solution based on actual requirements
- Update schema definition with type-safe approach
- Generate new migration to reflect changes
- Update all affected queries and API endpoints
- Test database operations thoroughly
- Update type exports and ensure consistency
Testing Checklist
- Schema compiles without TypeScript errors
- Database migrations generate correctly
- All existing queries still work
- Type inference works properly in IDE
- No runtime errors in database operations
- Performance impact is minimal
Files to modify:
packages/database/drizzle/schema.ts
- Potentially affected query files in
apps/app/src
- Migration files (auto-generated)