Skip to content

Commit

Permalink
feat(schema): Define initial entities and relationships in Prisma dat…
Browse files Browse the repository at this point in the history
…a model
  • Loading branch information
KatyH820 committed Feb 3, 2024
1 parent 710e03e commit 7eec868
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 39 deletions.
146 changes: 146 additions & 0 deletions packages/db/prisma/migrations/20240203074327_test1/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
Warnings:
- You are about to drop the `Post` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Post" DROP CONSTRAINT "Post_authorId_fkey";

-- DropTable
DROP TABLE "Post";

-- DropTable
DROP TABLE "User";

-- CreateTable
CREATE TABLE "DietaryRestrictionInfo" (
"id" TEXT NOT NULL,
"containsFish" BOOLEAN,
"containsMilk" BOOLEAN,
"containsPeanuts" BOOLEAN,
"containsSesame" BOOLEAN,
"containsShellfish" BOOLEAN,
"containSoy" BOOLEAN,
"containsTreeNuts" BOOLEAN,
"containsWheat" BOOLEAN,
"isGlutenFree" BOOLEAN,
"isHalal" BOOLEAN,
"isKosher" BOOLEAN,
"isLocallyGrown" BOOLEAN,
"isOrganic" BOOLEAN,
"isVegan" BOOLEAN,
"isVegetarian" BOOLEAN,
"dishId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "NutritionInfo" (
"id" TEXT NOT NULL,
"servingSize" TEXT,
"servingUnit" TEXT,
"calories" TEXT,
"caloriesFromFat" TEXT,
"totalFat" TEXT,
"transFat" TEXT,
"cholesterol" TEXT,
"sodum" TEXT,
"totalCarbohydrates" TEXT,
"dietaryFiber" TEXT,
"sugars" TEXT,
"protein" TEXT,
"vitaminA" TEXT,
"vitaminC" TEXT,
"calcium" TEXT,
"iron" TEXT,
"saturatedFat" TEXT,
"dishId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Restaurant" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"stationId" TEXT NOT NULL,
"menuId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "MenuPeriod" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"start" TIMESTAMP(3) NOT NULL,
"end" TIMESTAMP(3) NOT NULL,
"menuId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Dish" (
"id" TEXT NOT NULL,
"description" TEXT NOT NULL,
"stationId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Station" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"menuId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Menu" (
"id" TEXT NOT NULL,
"date" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "DietaryRestrictionInfo_dishId_key" ON "DietaryRestrictionInfo"("dishId");

-- CreateIndex
CREATE UNIQUE INDEX "NutritionInfo_dishId_key" ON "NutritionInfo"("dishId");

-- CreateIndex
CREATE UNIQUE INDEX "Restaurant_stationId_key" ON "Restaurant"("stationId");

-- CreateIndex
CREATE UNIQUE INDEX "Restaurant_menuId_key" ON "Restaurant"("menuId");

-- CreateIndex
CREATE UNIQUE INDEX "MenuPeriod_menuId_key" ON "MenuPeriod"("menuId");

-- AddForeignKey
ALTER TABLE "DietaryRestrictionInfo" ADD CONSTRAINT "DietaryRestrictionInfo_dishId_fkey" FOREIGN KEY ("dishId") REFERENCES "Dish"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NutritionInfo" ADD CONSTRAINT "NutritionInfo_dishId_fkey" FOREIGN KEY ("dishId") REFERENCES "Dish"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Restaurant" ADD CONSTRAINT "Restaurant_stationId_fkey" FOREIGN KEY ("stationId") REFERENCES "Station"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Restaurant" ADD CONSTRAINT "Restaurant_menuId_fkey" FOREIGN KEY ("menuId") REFERENCES "Menu"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MenuPeriod" ADD CONSTRAINT "MenuPeriod_menuId_fkey" FOREIGN KEY ("menuId") REFERENCES "Menu"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Dish" ADD CONSTRAINT "Dish_stationId_fkey" FOREIGN KEY ("stationId") REFERENCES "Station"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Station" ADD CONSTRAINT "Station_menuId_fkey" FOREIGN KEY ("menuId") REFERENCES "Menu"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
147 changes: 108 additions & 39 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,114 @@ datasource db {
url = env("DATABASE_URL")
}

model DietaryRestrictionInfo {
id String @id
containsFish Boolean?
containsMilk Boolean?
containsPeanuts Boolean?
containsSesame Boolean?
containsShellfish Boolean?
containSoy Boolean?
containsTreeNuts Boolean?
containsWheat Boolean?
isGlutenFree Boolean?
isHalal Boolean?
isKosher Boolean?
isLocallyGrown Boolean?
isOrganic Boolean?
isVegan Boolean?
isVegetarian Boolean?
dish Dish @relation(fields: [dishId], references: [id])
dishId String @unique
}

model NutritionInfo {
id String @id
servingSize String?
servingUnit String?
calories String?
caloriesFromFat String?
totalFat String?
transFat String?
cholesterol String?
sodum String?
totalCarbohydrates String?
dietaryFiber String?
sugars String?
protein String?
vitaminA String?
vitaminC String?
calcium String?
iron String?
saturatedFat String?
dish Dish @relation(fields: [dishId], references: [id])
dishId String @unique
}

model Restaurant {
id String @id
name String
station Station @relation(fields: [stationId], references: [id])
stationId String @unique
menu Menu @relation(fields: [menuId], references: [id])
menuId String @unique
}

model MenuPeriod {
id String @id
name String
start DateTime
end DateTime
menu Menu @relation(fields: [menuId], references: [id])
menuId String @unique
}

model Dish {
id String @id
description String
dietaryRestrictionInfo DietaryRestrictionInfo?
nutritionInfo NutritionInfo?
station Station @relation(fields: [stationId], references: [id])
stationId String
}

model Station {
id String @id
name String
restaurant Restaurant?
dishes Dish[]
menu Menu @relation(fields: [menuId], references: [id])
menuId String
}

model Menu {
id String @id
date DateTime
restaurant Restaurant?
menuPeriod MenuPeriod?
stations Station[]
}

// model DietaryRestrictionInfo {
// does not have its own id, just the dish id is the primarykey for this table
// id primary key referenecs Dish(id)
// ContainsEggs: null,
// ContainsFish: null,
// ContainsMilk: null,
// ContainsPeanuts: null,
// ContainsShellfish: null,
// ContainsSoy: null,
// ContainsTreeNuts: null,
// ContainsWheat: null,
// ContainsSesame: null,
// IsGlutenFree: false,
// IsHalal: false,
// IsKosher: true,
// IsLocallyGrown: false,
// IsOrganic: false,
// IsVegan: false,
// IsVegetarian: false,
// does not have its own id, just the dish id is the primarykey for this table
// id primary key referenecs Dish(id)
// ContainsEggs: null,
// ContainsFish: null,
// ContainsMilk: null,
// ContainsPeanuts: null,
// ContainsShellfish: null,
// ContainsSoy: null,
// ContainsTreeNuts: null,
// ContainsWheat: null,
// ContainsSesame: null,
// IsGlutenFree: false,
// IsHalal: false,
// IsKosher: true,
// IsLocallyGrown: false,
// IsOrganic: false,
// IsVegan: false,
// IsVegetarian: false,
// }

// model NutritionInfo {
Expand Down Expand Up @@ -59,15 +147,13 @@ datasource db {
// // menuperiod id
// }



// model Dish {
// // dietary info
// // nutrition info
// // id
// // name
// // description
// //
// //

// }

Expand All @@ -78,7 +164,7 @@ datasource db {

// // breakfast, brunch, lunch, dinner, latenight
// model MenuPeriod {
// // id String @id
// // id String @id
// // restaurant Restaurant @relation()
// // restaurantId String @id
// // date
Expand All @@ -90,20 +176,3 @@ datasource db {
// // id
// // name
// }


model User {
id Int @id @default(autoincrement())
email String @unique
name String?
// posts Post[]
}

model Post {
id Int @id @default(autoincrement())
title String
content String?
// published Boolean @default(false)
// author User @relation(fields: [authorId], references: [id])
// authorId Int
}

0 comments on commit 7eec868

Please sign in to comment.