Database Provider
Models Overview
The database consists of 7 models:- NextAuth.js Models: User, Account, Session, VerificationToken
- Application Models: Points, Request, Notification
User
Stores user account information and serves as the central model connecting all other entities.Fields
Unique identifier (CUID format)
User’s display name
User’s email address (unique)
Timestamp when email was verified
User’s phone number
Profile image URL
Account creation timestamp (auto-generated)
Last update timestamp (auto-updated)
Relations
- accounts: OAuth accounts linked to this user
- sessions: Active sessions for this user
- points: One-to-one relationship with Points model
- requests: Requests created by this user (as requester)
- donations: Requests where this user is the donor
- notifications: Notifications for this user
Account
Stores OAuth provider account information for NextAuth.js authentication.Fields
Unique identifier
Foreign key to User model
OAuth provider name (e.g., “google”)
User’s ID from the OAuth provider
Constraints
- Cascade Delete: When a user is deleted, all their accounts are deleted
- Unique: Combination of
providerandproviderAccountIdmust be unique
Session
Stores active user sessions for NextAuth.js.Fields
Unique identifier
Unique session token (used in cookies)
Foreign key to User model
Session expiration timestamp
VerificationToken
Stores email verification tokens for NextAuth.js.Fields
Email address or user identifier
Unique verification token
Token expiration timestamp
Points
Tracks dining hall points balance for each user. One-to-one relationship with User.Fields
Unique identifier
Foreign key to User model (unique)
Current points balance (default: 0)
Last update timestamp (auto-updated)
Important Notes
Points records don’t exist by default. Always use
upsert to handle first access:Request
Tracks point-sharing requests between users.Fields
Unique identifier
Foreign key to User model (user requesting points)
Foreign key to User model (user donating points, null until accepted/declined)
UCSC dining hall location (e.g., “Cowell/Stevenson”, “Crown/Merrill”)
Number of points requested
Request status:
pending, accepted, or declined (default: pending)Optional message from requester
Request creation timestamp (auto-generated)
Last update timestamp (auto-updated)
Relations
- requester: User who created the request
- donor: User who accepted/declined the request (nullable)
Status Values
Notification
Stores notifications for users about request actions.Fields
Unique identifier
Foreign key to User model
Notification type (e.g.,
request_accepted, request_declined, request_accepted_by_you)Human-readable notification message
Whether notification has been read (default:
false)Notification creation timestamp (auto-generated)
Last update timestamp (auto-updated)