Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ni borde squasha era migrations. Det kan ni göra genom att ta bort alla migrations ni har skapat och sedan köra pnpm migrate, så kommer en enda stor migration skapas

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- CreateEnum
CREATE TYPE "DrinkQuantityType" AS ENUM ('NONE', 'WEIGHT', 'COUNTS');

-- CreateEnum
CREATE TYPE "DrinkGroup" AS ENUM ('S1', 'S2', 'S3', 'S4');

-- CreateTable
CREATE TABLE "drinkitem" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"quantity_type" "DrinkQuantityType" NOT NULL,
"name" TEXT NOT NULL,
"price" INTEGER NOT NULL,
"group" "DrinkGroup" NOT NULL,
"systembolaget_id" INTEGER NOT NULL,

CONSTRAINT "drinkitem_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "drinkitembatch" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"drink_item_id" UUID NOT NULL,
"best_before_date" TIMESTAMP(3) NOT NULL,
"quantity" INTEGER NOT NULL,

CONSTRAINT "drinkitembatch_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "drinkitembatch" ADD CONSTRAINT "drinkitembatch_drink_item_id_fkey" FOREIGN KEY ("drink_item_id") REFERENCES "drinkitem"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `best_before_date` on the `drinkitembatch` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "drinkitembatch" DROP COLUMN "best_before_date";
3 changes: 3 additions & 0 deletions src/database/prisma/migrations/20251124165427_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "drinkitem" ADD COLUMN "bottle_empty_weight" INTEGER,
ADD COLUMN "bottle_full_weight" INTEGER;
8 changes: 8 additions & 0 deletions src/database/prisma/migrations/20251124193841_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- CreateTable
CREATE TABLE "sexetinventoryvaluelog" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"date" TIMESTAMP(3) NOT NULL,
"value" INTEGER NOT NULL,

CONSTRAINT "sexetinventoryvaluelog_pkey" PRIMARY KEY ("id")
);
10 changes: 10 additions & 0 deletions src/database/prisma/migrations/20251124204050_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:

- Added the required column `date` to the `drinkitembatch` table without a default value. This is not possible if the table is not empty.
- Added the required column `user` to the `drinkitembatch` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "drinkitembatch" ADD COLUMN "date" TIMESTAMP(3) NOT NULL,
ADD COLUMN "user" TEXT NOT NULL;
10 changes: 10 additions & 0 deletions src/database/prisma/migrations/20251124204155_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:

- You are about to drop the column `quantity` on the `drinkitembatch` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "drinkitembatch" DROP COLUMN "quantity",
ADD COLUMN "quantityIn" INTEGER,
ADD COLUMN "quantityOut" INTEGER;
2 changes: 2 additions & 0 deletions src/database/prisma/migrations/20251215180520_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "drinkitembatch" ADD COLUMN "nrBottles" INTEGER;
48 changes: 48 additions & 0 deletions src/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ enum recurringType {
YEARLY
}

enum DrinkQuantityType {
NONE
WEIGHT
COUNTS
}

enum DrinkGroup {
S1
S2
S3
S4
}

enum DocumentType {
POLICY
GUIDELINE
Expand Down Expand Up @@ -444,6 +457,41 @@ model Markdown {
@@map("markdowns")
}

model DrinkItem {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
quantityType DrinkQuantityType @map("quantity_type")
name String
price Int
group DrinkGroup
systembolagetID Int @map("systembolaget_id")
bottleEmptyWeight Int? @map("bottle_empty_weight")
bottleFullWeight Int? @map("bottle_full_weight")
stockLists DrinkItemBatch[]

@@map("drinkitem")
}

model DrinkItemBatch {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
drinkItemId String @map("drink_item_id") @db.Uuid()
item DrinkItem @relation(fields: [drinkItemId], references: [id])
quantityIn Int?
quantityOut Int?
user String
date DateTime
nrBottles Int?

@@map("drinkitembatch")
}

model SexetInventoryValueLog {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
date DateTime
value Int

@@map("sexetinventoryvaluelog")
}

model Meeting {
id String @id() @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
title String @db.VarChar(255)
Expand Down
62 changes: 62 additions & 0 deletions src/database/schema.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,68 @@ model Markdown {
@@map("markdowns")
}


model DrinkItem {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
quantityType DrinkQuantityType @map("quantity_type")
name String
price Int
group DrinkGroup
systembolagetID Int @map("systembolaget_id")
bottleEmptyWeight Int? @map("bottle_empty_weight")
bottleFullWeight Int? @map("bottle_full_weight")

stockLists DrinkItemBatch[]

@@allow("read", true)
@@allow("create", has(auth().policies, "drinkitem:create"))
@@allow("update", has(auth().policies, "drinkitem:update"))
@@allow("delete", has(auth().policies, "drinkitem:delete"))
@@map("drinkitem")
}

model DrinkItemBatch {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
drinkItemId String @map("drink_item_id") @db.Uuid
item DrinkItem @relation(fields: [drinkItemId], references: [id])
quantityIn Int?
quantityOut Int?
Comment on lines +566 to +567
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Är det meningen att dessa ska vara nullable? Defaulta till 0 istället?

user String
date DateTime
nrBottles Int?

@@allow("read", true)
@@allow("create", has(auth().policies, "drinkitembatch:create"))
@@allow("update", has(auth().policies, "drinkitembatch:update"))
@@allow("delete", has(auth().policies, "drinkitembatch:delete"))
@@map("drinkitembatch")
}

model SexetInventoryValueLog {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
date DateTime
value Int

@@allow("read", true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

För alla databas-models ni har skapat: är det meningen att vem som helst ska kunna se allt?

@@allow("create", has(auth().policies, "drinkitembatch:create"))
@@allow("update", has(auth().policies, "drinkitembatch:update"))
@@allow("delete", has(auth().policies, "drinkitembatch:delete"))
@@map("sexetinventoryvaluelog")
}

enum DrinkQuantityType {
NONE
WEIGHT
COUNTS
}

enum DrinkGroup {
S1
S2
S3
S4
}

model Meeting {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String @db.VarChar(255)
Expand Down
Loading