Aura Farm uses PostgreSQL as its database, accessed through Prisma ORM (v6). The schema is defined in backend/prisma/schema.prisma and versioned via Prisma migrations.
Stores registered users. The email field is the join key between Supabase Auth and the PostgreSQL record.
model User { id Int @id @default(autoincrement()) email String @unique name String role UserRole @default(user) auraPoints Int @default(0) streak Int @default(0) lastCompletedAt DateTime? createdAt DateTime @default(now()) completions ChallengeCompletion[] flags Flag[] @@index([auraPoints])}
Field
Type
Notes
id
Int
Auto-incrementing primary key
email
String
Unique — mirrors the Supabase Auth identity
name
String
Display name
role
UserRole
user or admin; defaults to user
auraPoints
Int
Accumulated score from completed challenges
streak
Int
Consecutive-day completion streak
lastCompletedAt
DateTime?
Nullable; used for streak tracking
createdAt
DateTime
Record creation timestamp
auraPoints is indexed to support efficient leaderboard queries.
Represents a campus activity or location-based task that users can complete.
model Challenge { id Int @id @default(autoincrement()) title String description String latitude Float longitude Float difficulty String pointsReward Int createdAt DateTime @default(now()) completions ChallengeCompletion[] @@index([createdAt]) @@index([difficulty])}
Field
Type
Notes
id
Int
Auto-incrementing primary key
title
String
Short challenge name
description
String
Full description shown to the user
latitude
Float
Geographic coordinate of the challenge location
longitude
Float
Geographic coordinate of the challenge location
difficulty
String
e.g., easy, medium, hard
pointsReward
Int
Aura points awarded on completion
createdAt
DateTime
Record creation timestamp
createdAt and difficulty are indexed to support filtered browsing.
Allows users to report a completion as suspicious or invalid. A user can only flag a given completion once.
model Flag { id Int @id @default(autoincrement()) completionId Int flaggedById Int reason String? createdAt DateTime @default(now()) completion ChallengeCompletion @relation(fields: [completionId], references: [id]) flaggedBy User @relation(fields: [flaggedById], references: [id]) @@unique([completionId, flaggedById]) @@index([completionId]) @@index([flaggedById])}
Field
Type
Notes
id
Int
Auto-incrementing primary key
completionId
Int
Foreign key → ChallengeCompletion.id
flaggedById
Int
Foreign key → User.id (the reporter)
reason
String?
Optional explanation from the reporter
createdAt
DateTime
Flag submission timestamp
Key constraint:@@unique([completionId, flaggedById]) prevents the same user from flagging the same completion multiple times.