Database

April 8, 2026 · View on GitHub

Technology

Track Your Time uses Prisma 7 as the ORM and PostgreSQL 17 as the database engine.

For local development a Dockerised PostgreSQL instance is provided via docker-compose.yml.

Running locally

# Start the database
docker compose up -d

# Apply migrations
npx prisma migrate dev --name init

# (Optional) Open Prisma Studio
npx prisma studio

Schema overview

The schema lives in prisma/schema.prisma.

Better Auth tables

ModelDescription
UserRegistered users
SessionActive authentication sessions
AccountLinked OAuth provider accounts
VerificationEmail verification tokens

Application tables

ModelDescription
ProjectUser-defined projects (name, colour)
ProjectMemberJoin table linking users to projects with a role (ADMIN, TRACKER, READER)
TimeEntryIndividual time records with optional project link

TimeEntry fields

FieldTypeDescription
idString (cuid)Primary key
descriptionString?Optional description
startTimeDateTimeWhen the entry started
endTimeDateTime?When the entry stopped (null if still running)
durationInt?Duration in seconds (null if still running)
userIdStringOwner (FK → User)
projectIdString?Associated project (FK → Project, nullable)

Creating a migration

After editing prisma/schema.prisma run:

npx prisma migrate dev --name <description>

This will:

  1. Generate a SQL migration file in prisma/migrations/.
  2. Apply it to the local database.
  3. Re-generate the Prisma client.

Resetting the database

npx prisma migrate reset

⚠️ This deletes all data. Use only in development.