feat: allow a honey batch to be split across multiple storage containers
Backend Image / build-and-push (push) Successful in 3m9s
Frontend Image / build-and-push (push) Successful in 2m45s

A batch that doesn't fit in one container (e.g. 125 kg across 5 x 25 kg
buckets) had no way to be represented - HoneyBatch.storageContainerId
is a single nullable FK. Adds HoneyBatchContainerAllocation as an
additive join table (container + amount per batch), independent of the
existing single-container/relocate() flow which still covers the
simple one-container case unchanged.

- GET/PUT/DELETE /honey-batches/:id/containers[/:containerId], reusing
  the existing honey-batches:relocate permission.
- Assigning a container is an upsert (@@unique on batch+container), and
  the total assigned is validated against the batch's own amount when
  known.
- New "Aufteilung auf mehrere Behälter" card on the honey batch detail
  page, alongside (not replacing) the existing storage card.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Sonnet 5 committed 2026-09-04 19:44:33 +02:00
1 parent c91dc9ebf1
commit 1054a845ef
10 files changed
+579 -7

No files matched your search

@@ -0,0 +1,23 @@
-- CreateTable
CREATE TABLE "HoneyBatchContainerAllocation" (
"id" TEXT NOT NULL,
"honeyBatchId" TEXT NOT NULL,
"storageContainerId" TEXT NOT NULL,
"amount" DOUBLE PRECISION NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "HoneyBatchContainerAllocation_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "HoneyBatchContainerAllocation_storageContainerId_idx" ON "HoneyBatchContainerAllocation"("storageContainerId");
-- CreateIndex
CREATE UNIQUE INDEX "HoneyBatchContainerAllocation_honeyBatchId_storageContaine_key" ON "HoneyBatchContainerAllocation"("honeyBatchId", "storageContainerId");
-- AddForeignKey
ALTER TABLE "HoneyBatchContainerAllocation" ADD CONSTRAINT "HoneyBatchContainerAllocation_honeyBatchId_fkey" FOREIGN KEY ("honeyBatchId") REFERENCES "HoneyBatch"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "HoneyBatchContainerAllocation" ADD CONSTRAINT "HoneyBatchContainerAllocation_storageContainerId_fkey" FOREIGN KEY ("storageContainerId") REFERENCES "StorageContainer"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+29 -6
View File
@@ -708,9 +708,10 @@ model HoneyBatch {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
measurements HoneyMeasurement[]
bottlingBatches BottlingBatch[]
relocations HoneyBatchRelocation[]
measurements HoneyMeasurement[]
bottlingBatches BottlingBatch[]
relocations HoneyBatchRelocation[]
containerAllocations HoneyBatchContainerAllocation[]
@@index([status])
@@index([extractionId])
@@ -756,9 +757,10 @@ model StorageContainer {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
honeyBatches HoneyBatch[]
relocationsFrom HoneyBatchRelocation[] @relation("RelocationFrom")
relocationsTo HoneyBatchRelocation[] @relation("RelocationTo")
honeyBatches HoneyBatch[]
relocationsFrom HoneyBatchRelocation[] @relation("RelocationFrom")
relocationsTo HoneyBatchRelocation[] @relation("RelocationTo")
batchAllocations HoneyBatchContainerAllocation[]
@@index([status])
}
@@ -781,6 +783,27 @@ model HoneyBatchRelocation {
@@index([honeyBatchId, relocatedAt])
}
// Aufteilung einer Honigcharge auf mehrere Lagerbehälter (z.B. 125 kg auf 5
// Eimer à 25 kg) - additiv zum obigen "primären" storageContainerId/
// Umlagern-Fluss auf HoneyBatch, der weiterhin den einfachen Ein-Behälter-
// Fall abdeckt; diese Tabelle bildet zusätzlich den Fall ab, dass eine
// Charge zu groß für einen einzelnen Behälter ist. @@unique macht das
// Zuweisen einer Menge zu einem Behälter ein Upsert (erneutes Zuweisen
// überschreibt die Menge, statt einen Duplikat-Eintrag anzulegen).
model HoneyBatchContainerAllocation {
id String @id @default(cuid())
honeyBatchId String
honeyBatch HoneyBatch @relation(fields: [honeyBatchId], references: [id])
storageContainerId String
storageContainer StorageContainer @relation(fields: [storageContainerId], references: [id])
amount Float
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([honeyBatchId, storageContainerId])
@@index([storageContainerId])
}
enum StockCategory {
HONEY
CONSUMABLE