Refactor database schema for roles and visibility management
- Updated the roles table to use `code` as the primary key, enhancing readability and simplifying junction tables. - Modified `user_roles` and `product_role_visibility` tables to reference `role_code` instead of `role_id`, maintaining many-to-many relationships. - Added foreign key constraints and created new indexes to optimize queries. - Removed the previous migration file that was no longer needed, ensuring a cleaner migration history. - Updated related documentation to reflect the new schema changes and their benefits.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
## my.experimenta.science
|
||||
|
||||
**Last Updated:** 2025-11-01
|
||||
**Last Updated:** 2025-11-03
|
||||
**Overall Progress:** 39/137 tasks (28.5%)
|
||||
**Current Phase:** ✅ Phase 3 - Authentication (Validated & Completed)
|
||||
**Current Phase:** ✅ Phase 3 - Authentication (Completed) | Database Schema Refinement Completed
|
||||
|
||||
---
|
||||
|
||||
@@ -30,6 +30,29 @@
|
||||
|
||||
## 🚀 Current Work
|
||||
|
||||
**Phase:** Database Schema Refinement ✅ **COMPLETED** (2025-11-03)
|
||||
|
||||
**Recent Work: Roles Table Refactoring**
|
||||
|
||||
Completed a major database schema refinement to improve code readability and performance:
|
||||
|
||||
- ✅ **Refactored `roles` table**: Changed Primary Key from `id` (UUID) to `code` (enum: 'private' | 'educator' | 'company')
|
||||
- ✅ **Updated junction tables**: `user_roles.roleCode` and `product_role_visibility.roleCode` now reference `roles.code` directly
|
||||
- ✅ **Simplified code**: Removed all UUID lookup queries for roles - direct enum usage throughout
|
||||
- ✅ **Maintained functionality**: Many-to-Many relationships fully preserved
|
||||
- ✅ **Migration**: Successfully applied, database reseeded with 3 roles, 3 products, 7 role assignments
|
||||
- ✅ **Auto-assignment**: Confirmed that new users automatically receive `'private'` role on first login
|
||||
- ✅ **Product visibility**: Verified role-based product filtering works correctly
|
||||
- ✅ **Documentation**: Updated CLAUDE.md and ARCHITECTURE.md to reflect new schema
|
||||
|
||||
**Benefits:**
|
||||
- Better readability: `roleCode: 'private'` instead of `roleId: 'uuid...'`
|
||||
- Simpler code: No role lookups needed
|
||||
- Better performance: Fewer joins in queries
|
||||
- Type safety: Direct enum type usage
|
||||
|
||||
---
|
||||
|
||||
**Phase:** Phase 3 - Authentication ✅ **VALIDATED & COMPLETED** (2025-11-01)
|
||||
|
||||
**Validation Summary:**
|
||||
@@ -431,6 +454,7 @@ Tasks:
|
||||
| 2025-10-30 | 15.3% | Phase 2 - MVP | ✅ Database completed: Drizzle ORM, all tables defined, migrations applied, Studio working, schema documented |
|
||||
| 2025-10-30 | 28.5% | Phase 3 - MVP | ✅ Authentication completed: Password Grant Flow, JWT validation, auth endpoints, UI components, middleware |
|
||||
| 2025-11-01 | 28.5% | Phase 3 - Validation | ✅ Authentication validated: Login tested with Playwright, DB user creation verified, docs updated |
|
||||
| 2025-11-03 | 28.5% | DB Refinement | ✅ Roles table refactored: `code` as PK, simplified junction tables, maintained Many-to-Many functionality |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user