Overview
The PC Fix database is built on PostgreSQL and managed through Prisma 6, providing type-safe database access and automatic migrations. The schema supports a full e-commerce system with users, products, shopping carts, orders, and administrative features.The database is hosted on Railway and includes 328 lines of carefully designed schema covering all business logic.
Database Technology
PostgreSQL
Production-grade relational database with ACID compliance
Prisma 6.18
Next-generation ORM with automatic client generation
Railway Hosting
Managed PostgreSQL with automatic backups
Prisma Studio
Visual database browser on port 5555
Schema Configuration
prisma/schema.prisma
Schema Overview
The database schema is organized into five main domains:1
Users & Authentication
User accounts, roles, authentication tokens, and client profiles
2
Products & Catalog
Products, categories, brands, banners, and favorites
3
Shopping & Cart
Shopping cart, cart items, and stock alerts
4
Sales & Payments
Orders, order lines, payments, and payment methods
5
Technical Support
Support tickets, service items, and ticket responses
User Management
User Model
Users can authenticate via password or Google OAuth (
googleId field). The role field enables role-based access control.Client Profile
Location Data
Refresh Tokens
Product Catalog
Product Model
Key Features
Key Features
- Soft Delete:
deletedAtfield allows marking products as deleted without removing data - Pricing: Support for original and discounted prices
- Shipping: Physical dimensions and weight for shipping calculations
- Featured Products:
isFeaturedflag for homepage highlights
Stock Alerts
Stock Alerts
Categories
Categories support hierarchical relationships (parent/child) for organizing products into nested groups.
Brands
Favorites
Shopping Cart
The
abandonedEmailSent flag tracks whether the user has received an abandoned cart email reminder.Sales & Orders
Sales Model
Order Status Workflow
Order Status Workflow
- PENDIENTE_PAGO - Order created, awaiting payment
- PENDIENTE_APROBACION - Payment submitted, awaiting admin approval
- APROBADO - Payment approved, ready to ship
- ENVIADO - Order shipped to customer
- ENTREGADO - Order delivered successfully
- RECHAZADO - Payment rejected
- CANCELADO - Order cancelled
Delivery Options
Delivery Options
- ENVIO: Home delivery via shipping provider
- RETIRO: In-store pickup
Payment Methods
Payment Methods
- TRANSFERENCIA: Bank transfer
- BINANCE: Cryptocurrency (USDT)
- EFECTIVO: Cash (for in-store pickup)
Order Lines
Order lines support custom pricing and descriptions for special scenarios (bulk discounts, promotions, etc.).
Payments
System Configuration
Technical Support
Database Indexes
The schema includes strategic indexes for performance:Prisma Migrations
Creating Migrations
Database Seeding
prisma/seed.ts
Prisma Studio
Access the visual database browser:- Browse all tables
- Create, edit, delete records
- View relationships
- Run queries
Database Relationships
Best Practices
Use Transactions
For operations affecting multiple tables (orders, payments)
Soft Deletes
Use
deletedAt timestamps instead of hard deletes for productsIndexes
Add indexes on foreign keys and frequently queried fields
Timestamps
Always use
@db.Timestamptz(3) for timezone-aware timestampsNext Steps
Backend API
Learn how to query this schema
Migrations
Manage schema changes
Deployment
Deploy to production