Files
FEDEO/backend/db/schema/vehicles.ts
2026-01-06 12:07:43 +01:00

58 lines
1.4 KiB
TypeScript

import {
pgTable,
bigint,
text,
timestamp,
boolean,
jsonb,
uuid,
doublePrecision,
} from "drizzle-orm/pg-core"
import { tenants } from "./tenants"
import { authUsers } from "./auth_users"
export const vehicles = pgTable("vehicles", {
id: bigint("id", { mode: "number" })
.primaryKey()
.generatedByDefaultAsIdentity(),
created_at: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
tenant: bigint("tenant", { mode: "number" })
.notNull()
.references(() => tenants.id),
license_plate: text("licensePlate"),
name: text("name"),
type: text("type"),
active: boolean("active").default(true),
// FIXED: driver references auth_users.id
driver: uuid("driver").references(() => authUsers.id),
vin: text("vin"),
tank_size: doublePrecision("tankSize").notNull().default(0),
archived: boolean("archived").notNull().default(false),
build_year: text("buildYear"),
towing_capacity: bigint("towingCapacity", { mode: "number" }),
power_in_kw: bigint("powerInKW", { mode: "number" }),
color: text("color"),
profiles: jsonb("profiles").notNull().default([]),
updated_at: timestamp("updated_at", { withTimezone: true }),
updated_by: uuid("updated_by").references(() => authUsers.id),
})
export type Vehicle = typeof vehicles.$inferSelect
export type NewVehicle = typeof vehicles.$inferInsert