Hybrid cars implementation 1.0(Without stats)

This commit is contained in:
EdiFarcas
2025-07-10 00:09:58 +03:00
parent b3b916f52b
commit cf1f78280c
14 changed files with 247 additions and 50 deletions
@@ -0,0 +1,18 @@
/*
Warnings:
- You are about to drop the column `fuelType` on the `Car` table. All the data in the column will be lost.
- Added the required column `fuelType` to the `FillUp` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Car" DROP COLUMN "fuelType",
ADD COLUMN "fuelTypes" "FuelType"[];
-- AlterTable: add as nullable first
ALTER TABLE "FillUp" ADD COLUMN "fuelType" "FuelType";
-- Set default for existing rows (choose the most common, e.g. GASOLINE)
UPDATE "FillUp" SET "fuelType" = 'GASOLINE' WHERE "fuelType" IS NULL;
-- Make the column required
ALTER TABLE "FillUp" ALTER COLUMN "fuelType" SET NOT NULL;
@@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "FillUp" DROP CONSTRAINT "FillUp_carId_fkey";
-- DropForeignKey
ALTER TABLE "MileageEntry" DROP CONSTRAINT "MileageEntry_carId_fkey";
-- AddForeignKey
ALTER TABLE "FillUp" ADD CONSTRAINT "FillUp_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MileageEntry" ADD CONSTRAINT "MileageEntry_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+4 -4
View File
@@ -23,27 +23,27 @@ model Car {
make String // Manufacturer (e.g. "BMW")
model String // Model (e.g. "320i")
year Int // Year (e.g. 2019)
fuelType FuelType
fuelTypes FuelType[] // Changed from single fuelType to array for hybrid support
fillUps FillUp[]
mileage MileageEntry[]
}
model FillUp {
id String @id @default(cuid())
car Car @relation(fields: [carId], references: [id])
car Car @relation(fields: [carId], references: [id], onDelete: Cascade)
carId String
mileage Int
liters Float
cost Float
currency Currency
date DateTime @default(now())
fuelType FuelType // Add fuelType to each fill-up
}
model MileageEntry {
id String @id @default(cuid())
car Car @relation(fields: [carId], references: [id])
car Car @relation(fields: [carId], references: [id], onDelete: Cascade)
carId String
mileage Int
date DateTime @default(now())