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

57 lines
1.3 KiB
TypeScript

import {
pgTable,
bigint,
timestamp,
text,
jsonb,
boolean,
uuid,
date,
} from "drizzle-orm/pg-core"
import { tenants } from "./tenants"
import { customers } from "./customers"
import { contracts } from "./contracts"
import { authUsers } from "./auth_users"
export const plants = pgTable("plants", {
id: bigint("id", { mode: "number" })
.primaryKey()
.generatedByDefaultAsIdentity(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
tenant: bigint("tenant", { mode: "number" })
.notNull()
.references(() => tenants.id),
name: text("name").notNull(),
customer: bigint("customer", { mode: "number" }).references(
() => customers.id
),
infoData: jsonb("infoData"),
contract: bigint("contract", { mode: "number" }).references(
() => contracts.id
),
description: jsonb("description").default({
html: "",
json: [],
text: "",
}),
archived: boolean("archived").notNull().default(false),
profiles: jsonb("profiles").notNull().default([]),
updatedAt: timestamp("updated_at", { withTimezone: true }),
updatedBy: uuid("updated_by").references(() => authUsers.id),
})
export type Plant = typeof plants.$inferSelect
export type NewPlant = typeof plants.$inferInsert