top-tran/backend/prisma/schema.prisma
Rayan Konecny 3601b7fc0a Adds companies and rides models with sync endpoints
Introduces database schema, Prisma models, and API support for companies and rides, enabling CRUD operations and synchronization. Updates the sync flow to handle companies and rides, removes redundant user sync, and aligns naming conventions and indexing for better consistency and maintainability.

Co-authored-by: Copilot <copilot@github.com>
2026-05-03 03:51:16 -03:00

61 lines
1.5 KiB
Text

generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
model tokens {
id String @id
token String @unique
type TokenType
userId String
expiresAt DateTime
createdAt DateTime @default(now())
users users @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model users {
id String @id
name String
email String @unique
password String
createdAt DateTime @default(now())
updatedAt DateTime
rides rides[]
tokens tokens[]
}
model companies {
id String @id
name String
cost_per_km Decimal @db.Decimal(10, 2)
notes String? @default("")
createdAt DateTime? @default(now()) @db.Timestamptz(6)
updatedAt DateTime? @default(now()) @db.Timestamptz(6)
@@index([name], map: "idx_companies_name")
}
model rides {
id String @id
user_id String
company String
km Decimal @db.Decimal(10, 2)
cost_per_km Decimal @db.Decimal(10, 2)
total Decimal @db.Decimal(10, 2)
ride_date String
synced Int? @default(0) @db.SmallInt
createdAt DateTime? @default(now()) @db.Timestamptz(6)
updatedAt DateTime? @default(now()) @db.Timestamptz(6)
users users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
@@index([synced], map: "idx_rides_synced")
@@index([user_id], map: "idx_rides_user_id")
}
enum TokenType {
REFRESH
}