inventory1
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
CREATE TABLE "InventoryItem" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"sku" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"unitOfMeasure" TEXT NOT NULL,
|
||||
"isSellable" BOOLEAN NOT NULL DEFAULT true,
|
||||
"isPurchasable" BOOLEAN NOT NULL DEFAULT true,
|
||||
"defaultCost" REAL,
|
||||
"notes" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE "InventoryBomLine" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"parentItemId" TEXT NOT NULL,
|
||||
"componentItemId" TEXT NOT NULL,
|
||||
"quantity" REAL NOT NULL,
|
||||
"unitOfMeasure" TEXT NOT NULL,
|
||||
"notes" TEXT NOT NULL,
|
||||
"position" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "InventoryBomLine_parentItemId_fkey" FOREIGN KEY ("parentItemId") REFERENCES "InventoryItem" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "InventoryBomLine_componentItemId_fkey" FOREIGN KEY ("componentItemId") REFERENCES "InventoryItem" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "InventoryItem_sku_key" ON "InventoryItem"("sku");
|
||||
CREATE INDEX "InventoryBomLine_parentItemId_position_idx" ON "InventoryBomLine"("parentItemId", "position");
|
||||
CREATE INDEX "InventoryBomLine_componentItemId_idx" ON "InventoryBomLine"("componentItemId");
|
||||
@@ -101,6 +101,24 @@ model FileAttachment {
|
||||
companyLogoFor CompanyProfile? @relation("CompanyLogo")
|
||||
}
|
||||
|
||||
model InventoryItem {
|
||||
id String @id @default(cuid())
|
||||
sku String @unique
|
||||
name String
|
||||
description String
|
||||
type String
|
||||
status String
|
||||
unitOfMeasure String
|
||||
isSellable Boolean @default(true)
|
||||
isPurchasable Boolean @default(true)
|
||||
defaultCost Float?
|
||||
notes String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
bomLines InventoryBomLine[] @relation("InventoryBomParent")
|
||||
usedInBomLines InventoryBomLine[] @relation("InventoryBomComponent")
|
||||
}
|
||||
|
||||
model Customer {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
@@ -134,6 +152,23 @@ model Customer {
|
||||
childCustomers Customer[] @relation("CustomerHierarchy")
|
||||
}
|
||||
|
||||
model InventoryBomLine {
|
||||
id String @id @default(cuid())
|
||||
parentItemId String
|
||||
componentItemId String
|
||||
quantity Float
|
||||
unitOfMeasure String
|
||||
notes String
|
||||
position Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
parentItem InventoryItem @relation("InventoryBomParent", fields: [parentItemId], references: [id], onDelete: Cascade)
|
||||
componentItem InventoryItem @relation("InventoryBomComponent", fields: [componentItemId], references: [id], onDelete: Restrict)
|
||||
|
||||
@@index([parentItemId, position])
|
||||
@@index([componentItemId])
|
||||
}
|
||||
|
||||
model Vendor {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
|
||||
Reference in New Issue
Block a user