feat: add MaintenanceRecord Prisma model + migration
New entity tracking repair/warranty/preventive maintenance jobs for an AssetItem. Reuses Vendor (nullable) for the repair location, no cost field (mirrors PurchaseOrder). "At most 1 open record per AssetItem" invariant left to the application layer, mirroring Assignment.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "MaintenanceType" AS ENUM ('repair', 'warranty', 'preventive');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "maintenance_records" (
|
||||
"id" UUID NOT NULL,
|
||||
"asset_item_id" UUID NOT NULL,
|
||||
"type" "MaintenanceType" NOT NULL,
|
||||
"vendor_id" UUID,
|
||||
"issue_description" TEXT NOT NULL,
|
||||
"resolution_notes" TEXT,
|
||||
"start_date" DATE NOT NULL,
|
||||
"end_date" DATE,
|
||||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "maintenance_records_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "maintenance_records" ADD CONSTRAINT "maintenance_records_asset_item_id_fkey" FOREIGN KEY ("asset_item_id") REFERENCES "asset_items"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "maintenance_records" ADD CONSTRAINT "maintenance_records_vendor_id_fkey" FOREIGN KEY ("vendor_id") REFERENCES "vendors"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
Reference in New Issue
Block a user