inventory
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "InventoryTransaction" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"itemId" TEXT NOT NULL,
|
||||
"warehouseId" TEXT NOT NULL,
|
||||
"locationId" TEXT NOT NULL,
|
||||
"transactionType" TEXT NOT NULL,
|
||||
"quantity" INTEGER NOT NULL,
|
||||
"reference" TEXT NOT NULL,
|
||||
"notes" TEXT NOT NULL,
|
||||
"createdById" TEXT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "InventoryTransaction_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "InventoryItem" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "InventoryTransaction_warehouseId_fkey" FOREIGN KEY ("warehouseId") REFERENCES "Warehouse" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "InventoryTransaction_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "WarehouseLocation" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "InventoryTransaction_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "InventoryTransaction_itemId_createdAt_idx" ON "InventoryTransaction"("itemId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "InventoryTransaction_warehouseId_createdAt_idx" ON "InventoryTransaction"("warehouseId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "InventoryTransaction_locationId_createdAt_idx" ON "InventoryTransaction"("locationId", "createdAt");
|
||||
@@ -19,6 +19,7 @@ model User {
|
||||
updatedAt DateTime @updatedAt
|
||||
userRoles UserRole[]
|
||||
contactEntries CrmContactEntry[]
|
||||
inventoryTransactions InventoryTransaction[]
|
||||
}
|
||||
|
||||
model Role {
|
||||
@@ -117,6 +118,7 @@ model InventoryItem {
|
||||
updatedAt DateTime @updatedAt
|
||||
bomLines InventoryBomLine[] @relation("InventoryBomParent")
|
||||
usedInBomLines InventoryBomLine[] @relation("InventoryBomComponent")
|
||||
inventoryTransactions InventoryTransaction[]
|
||||
}
|
||||
|
||||
model Warehouse {
|
||||
@@ -127,6 +129,7 @@ model Warehouse {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
locations WarehouseLocation[]
|
||||
inventoryTransactions InventoryTransaction[]
|
||||
}
|
||||
|
||||
model Customer {
|
||||
@@ -188,11 +191,34 @@ model WarehouseLocation {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Cascade)
|
||||
inventoryTransactions InventoryTransaction[]
|
||||
|
||||
@@unique([warehouseId, code])
|
||||
@@index([warehouseId])
|
||||
}
|
||||
|
||||
model InventoryTransaction {
|
||||
id String @id @default(cuid())
|
||||
itemId String
|
||||
warehouseId String
|
||||
locationId String
|
||||
transactionType String
|
||||
quantity Int
|
||||
reference String
|
||||
notes String
|
||||
createdById String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
||||
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Restrict)
|
||||
location WarehouseLocation @relation(fields: [locationId], references: [id], onDelete: Restrict)
|
||||
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([itemId, createdAt])
|
||||
@@index([warehouseId, createdAt])
|
||||
@@index([locationId, createdAt])
|
||||
}
|
||||
|
||||
model Vendor {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
|
||||
Reference in New Issue
Block a user