Skip to content

Commit 9922d6b

Browse files
efollinCasperJensen19davidagardh
authored
Stocklist2.0 (#1088)
* first draft * second draft * draft 2 * Big changes made * Fixa buggar kring edit och borttagning av batches * fixed errors * fixed some more errors * errors 3.0 * Squash database migrations --------- Co-authored-by: Casper Jensen <casper.v.jensen@gmail.com> Co-authored-by: CasperJensen19 <144714740+CasperJensen19@users.noreply.github.com> Co-authored-by: David Agardh <21132805+davidagardh@users.noreply.github.com> Co-authored-by: David Agardh <agardh.david@gmail.com>
1 parent b185f7c commit 9922d6b

File tree

20 files changed

+1771
-0
lines changed

20 files changed

+1771
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- CreateEnum
2+
CREATE TYPE "DrinkQuantityType" AS ENUM ('NONE', 'WEIGHT', 'COUNTS');
3+
4+
-- CreateEnum
5+
CREATE TYPE "DrinkGroup" AS ENUM ('S1', 'S2', 'S3', 'S4');
6+
7+
-- CreateTable
8+
CREATE TABLE "drinkitem" (
9+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
10+
"quantity_type" "DrinkQuantityType" NOT NULL,
11+
"name" TEXT NOT NULL,
12+
"price" INTEGER NOT NULL,
13+
"group" "DrinkGroup" NOT NULL,
14+
"systembolaget_id" INTEGER NOT NULL,
15+
"bottle_empty_weight" INTEGER,
16+
"bottle_full_weight" INTEGER,
17+
18+
CONSTRAINT "drinkitem_pkey" PRIMARY KEY ("id")
19+
);
20+
21+
-- CreateTable
22+
CREATE TABLE "drinkitembatch" (
23+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
24+
"drink_item_id" UUID NOT NULL,
25+
"quantityIn" INTEGER,
26+
"quantityOut" INTEGER,
27+
"user" TEXT NOT NULL,
28+
"date" TIMESTAMP(3) NOT NULL,
29+
"nrBottles" INTEGER,
30+
31+
CONSTRAINT "drinkitembatch_pkey" PRIMARY KEY ("id")
32+
);
33+
34+
-- CreateTable
35+
CREATE TABLE "sexetinventoryvaluelog" (
36+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
37+
"date" TIMESTAMP(3) NOT NULL,
38+
"value" INTEGER NOT NULL,
39+
40+
CONSTRAINT "sexetinventoryvaluelog_pkey" PRIMARY KEY ("id")
41+
);
42+
43+
-- AddForeignKey
44+
ALTER TABLE "drinkitembatch" ADD CONSTRAINT "drinkitembatch_drink_item_id_fkey" FOREIGN KEY ("drink_item_id") REFERENCES "drinkitem"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

src/database/prisma/schema.prisma

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ enum recurringType {
2727
YEARLY
2828
}
2929

30+
enum DrinkQuantityType {
31+
NONE
32+
WEIGHT
33+
COUNTS
34+
}
35+
36+
enum DrinkGroup {
37+
S1
38+
S2
39+
S3
40+
S4
41+
}
42+
3043
enum DocumentType {
3144
POLICY
3245
GUIDELINE
@@ -447,6 +460,41 @@ model Markdown {
447460
@@map("markdowns")
448461
}
449462

463+
model DrinkItem {
464+
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
465+
quantityType DrinkQuantityType @map("quantity_type")
466+
name String
467+
price Int
468+
group DrinkGroup
469+
systembolagetID Int @map("systembolaget_id")
470+
bottleEmptyWeight Int? @map("bottle_empty_weight")
471+
bottleFullWeight Int? @map("bottle_full_weight")
472+
stockLists DrinkItemBatch[]
473+
474+
@@map("drinkitem")
475+
}
476+
477+
model DrinkItemBatch {
478+
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
479+
drinkItemId String @map("drink_item_id") @db.Uuid()
480+
item DrinkItem @relation(fields: [drinkItemId], references: [id])
481+
quantityIn Int?
482+
quantityOut Int?
483+
user String
484+
date DateTime
485+
nrBottles Int?
486+
487+
@@map("drinkitembatch")
488+
}
489+
490+
model SexetInventoryValueLog {
491+
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
492+
date DateTime
493+
value Int
494+
495+
@@map("sexetinventoryvaluelog")
496+
}
497+
450498
model Meeting {
451499
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
452500
title String @db.VarChar(255)

src/database/schema.zmodel

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,68 @@ model Markdown {
542542
@@map("markdowns")
543543
}
544544

545+
546+
model DrinkItem {
547+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
548+
quantityType DrinkQuantityType @map("quantity_type")
549+
name String
550+
price Int
551+
group DrinkGroup
552+
systembolagetID Int @map("systembolaget_id")
553+
bottleEmptyWeight Int? @map("bottle_empty_weight")
554+
bottleFullWeight Int? @map("bottle_full_weight")
555+
556+
stockLists DrinkItemBatch[]
557+
558+
@@allow("read", true)
559+
@@allow("create", has(auth().policies, "drinkitem:create"))
560+
@@allow("update", has(auth().policies, "drinkitem:update"))
561+
@@allow("delete", has(auth().policies, "drinkitem:delete"))
562+
@@map("drinkitem")
563+
}
564+
565+
model DrinkItemBatch {
566+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
567+
drinkItemId String @map("drink_item_id") @db.Uuid
568+
item DrinkItem @relation(fields: [drinkItemId], references: [id])
569+
quantityIn Int?
570+
quantityOut Int?
571+
user String
572+
date DateTime
573+
nrBottles Int?
574+
575+
@@allow("read", true)
576+
@@allow("create", has(auth().policies, "drinkitembatch:create"))
577+
@@allow("update", has(auth().policies, "drinkitembatch:update"))
578+
@@allow("delete", has(auth().policies, "drinkitembatch:delete"))
579+
@@map("drinkitembatch")
580+
}
581+
582+
model SexetInventoryValueLog {
583+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
584+
date DateTime
585+
value Int
586+
587+
@@allow("read", true)
588+
@@allow("create", has(auth().policies, "drinkitembatch:create"))
589+
@@allow("update", has(auth().policies, "drinkitembatch:update"))
590+
@@allow("delete", has(auth().policies, "drinkitembatch:delete"))
591+
@@map("sexetinventoryvaluelog")
592+
}
593+
594+
enum DrinkQuantityType {
595+
NONE
596+
WEIGHT
597+
COUNTS
598+
}
599+
600+
enum DrinkGroup {
601+
S1
602+
S2
603+
S3
604+
S4
605+
}
606+
545607
model Meeting {
546608
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
547609
title String @db.VarChar(255)

0 commit comments

Comments
 (0)