From cc6a805a17bed95c0d87b3c4496d07e852b6d62a Mon Sep 17 00:00:00 2001 From: Andrew Ho Date: Sat, 3 Feb 2024 11:01:22 -0800 Subject: [PATCH 1/2] schema tweaks --- .../migrations/20240203184145_/migration.sql | 88 +++++++++ packages/db/prisma/schema.prisma | 172 +++++------------- 2 files changed, 135 insertions(+), 125 deletions(-) create mode 100644 packages/db/prisma/migrations/20240203184145_/migration.sql diff --git a/packages/db/prisma/migrations/20240203184145_/migration.sql b/packages/db/prisma/migrations/20240203184145_/migration.sql new file mode 100644 index 00000000..94cd44ed --- /dev/null +++ b/packages/db/prisma/migrations/20240203184145_/migration.sql @@ -0,0 +1,88 @@ +/* + Warnings: + + - You are about to drop the column `menuId` on the `Restaurant` table. All the data in the column will be lost. + - You are about to drop the column `stationId` on the `Restaurant` table. All the data in the column will be lost. + - You are about to drop the `DietaryRestrictionInfo` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `MenuPeriod` table. If the table is not empty, all the data it contains will be lost. + - Added the required column `end` to the `Menu` table without a default value. This is not possible if the table is not empty. + - Added the required column `period` to the `Menu` table without a default value. This is not possible if the table is not empty. + - Added the required column `restaurantId` to the `Menu` table without a default value. This is not possible if the table is not empty. + - Added the required column `start` to the `Menu` table without a default value. This is not possible if the table is not empty. + - Added the required column `restaurantId` to the `Station` table without a default value. This is not possible if the table is not empty. + +*/ +-- CreateEnum +CREATE TYPE "MenuPeriod" AS ENUM ('BREAKFAST', 'BRUNCH', 'LUNCH', 'DINNER', 'LATENIGHT'); + +-- DropForeignKey +ALTER TABLE "DietaryRestrictionInfo" DROP CONSTRAINT "DietaryRestrictionInfo_dishId_fkey"; + +-- DropForeignKey +ALTER TABLE "MenuPeriod" DROP CONSTRAINT "MenuPeriod_menuId_fkey"; + +-- DropForeignKey +ALTER TABLE "Restaurant" DROP CONSTRAINT "Restaurant_menuId_fkey"; + +-- DropForeignKey +ALTER TABLE "Restaurant" DROP CONSTRAINT "Restaurant_stationId_fkey"; + +-- DropIndex +DROP INDEX "Restaurant_menuId_key"; + +-- DropIndex +DROP INDEX "Restaurant_stationId_key"; + +-- AlterTable +ALTER TABLE "Menu" ADD COLUMN "end" TIMESTAMP(3) NOT NULL, +ADD COLUMN "period" "MenuPeriod" NOT NULL, +ADD COLUMN "restaurantId" TEXT NOT NULL, +ADD COLUMN "start" TIMESTAMP(3) NOT NULL; + +-- AlterTable +ALTER TABLE "Restaurant" DROP COLUMN "menuId", +DROP COLUMN "stationId"; + +-- AlterTable +ALTER TABLE "Station" ADD COLUMN "restaurantId" TEXT NOT NULL; + +-- DropTable +DROP TABLE "DietaryRestrictionInfo"; + +-- DropTable +DROP TABLE "MenuPeriod"; + +-- CreateTable +CREATE TABLE "DietRestriction" ( + "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 "DietRestriction_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "DietRestriction_dishId_key" ON "DietRestriction"("dishId"); + +-- AddForeignKey +ALTER TABLE "Station" ADD CONSTRAINT "Station_restaurantId_fkey" FOREIGN KEY ("restaurantId") REFERENCES "Restaurant"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Menu" ADD CONSTRAINT "Menu_restaurantId_fkey" FOREIGN KEY ("restaurantId") REFERENCES "Restaurant"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "DietRestriction" ADD CONSTRAINT "DietRestriction_dishId_fkey" FOREIGN KEY ("dishId") REFERENCES "Dish"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index bcff32f7..a7ef75d5 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -10,7 +10,52 @@ datasource db { url = env("DATABASE_URL") } -model DietaryRestrictionInfo { +model Dish { + id String @id + description String + dietRestriction DietRestriction? + nutritionInfo NutritionInfo? + station Station @relation(fields: [stationId], references: [id]) + stationId String +} + +model Restaurant { + id String @id + name String + stations Station[] + Menu Menu[] +} + + +model Station { + id String @id + name String + restaurant Restaurant @relation(fields: [restaurantId], references: [id]) + restaurantId String + dishes Dish[] + menu Menu @relation(fields: [menuId], references: [id]) + menuId String +} + +enum MenuPeriod { + BREAKFAST + BRUNCH + LUNCH + DINNER + LATENIGHT +} + +model Menu { + id String @id + period MenuPeriod + date DateTime + start DateTime + end DateTime + restaurant Restaurant @relation(fields: [restaurantId], references: [id]) + restaurantId String + stations Station[] +} +model DietRestriction { id String @id containsFish Boolean? containsMilk Boolean? @@ -52,127 +97,4 @@ model NutritionInfo { 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, -// } - -// model NutritionInfo { -// // ServingSize: "1", -// // ServingUnit: "each", -// // Calories: "150", -// // CaloriesFromFat: "5", -// // TotalFat: "6", -// // TransFat: "0", -// // Cholesterol: "0", -// // Sodium: "290", -// // TotalCarbohydrates: "23", -// // DietaryFiber: "less than 1", -// // Sugars: "6", -// // Protein: "2", -// // VitaminA: null, -// // VitaminC: "0.14", -// // Calcium: "41.84", -// // Iron: "1.12", -// // SaturatedFat: "3.5" -// } - -// model Menu { -// // id -// // date -// // restaurant id -// // menuperiod id -// } - -// model Dish { -// // dietary info -// // nutrition info -// // id -// // name -// // description -// // - -// } - -// model Station { -// // restaurantId unique (not autogen) -// // name unique -// } - -// // breakfast, brunch, lunch, dinner, latenight -// model MenuPeriod { -// // id String @id -// // restaurant Restaurant @relation() -// // restaurantId String @id -// // date -// // start -// // end -// } - -// model Restaurant { -// // id -// // name -// } +} \ No newline at end of file From 6926e0beed5abd8b4330c80997f43bd31f487375 Mon Sep 17 00:00:00 2001 From: Andrew Ho Date: Sat, 3 Feb 2024 11:02:10 -0800 Subject: [PATCH 2/2] updated schema --- .env.example | 22 +--------------------- packages/api/src/router/menu.ts | 7 +++++++ packages/validators/src/index.ts | 1 - packages/validators/src/menu.ts | 3 +++ 4 files changed, 11 insertions(+), 22 deletions(-) create mode 100644 packages/validators/src/menu.ts diff --git a/.env.example b/.env.example index de17325b..4bb42e0f 100644 --- a/.env.example +++ b/.env.example @@ -1,21 +1 @@ -# Since .env is gitignored, you can use .env.example to build a new `.env` file when you clone the repo. -# Keep this file up-to-date when you add new variables to \`.env\`. - -# This file will be committed to version control, so make sure not to have any secrets in it. -# If you are cloning this repo, create a copy of this file named `.env` and populate it with your secrets. - -# The database URL is used to connect to your PlanetScale database. -DATABASE_URL='' - -# @see https://next-auth.js.org/configuration/options#nextauth_url -AUTH_URL='http://localhost:3000' -AUTH_REDIRECT_PROXY_URL="http://localhost:3001/api" - -# You can generate the secret via 'openssl rand -base64 32' on Unix -# @see https://next-auth.js.org/configuration/options#secret -AUTH_SECRET='supersecret' - -# Preconfigured Discord OAuth provider, works out-of-the-box -# @see https://next-auth.js.org/providers/discord -AUTH_DISCORD_ID='' -AUTH_DISCORD_SECRET='' \ No newline at end of file +DATABASE_URL="" \ No newline at end of file diff --git a/packages/api/src/router/menu.ts b/packages/api/src/router/menu.ts index fd396f9c..4e15bb61 100644 --- a/packages/api/src/router/menu.ts +++ b/packages/api/src/router/menu.ts @@ -3,6 +3,13 @@ import axios from "axios"; import { createTRPCRouter, publicProcedure } from "../trpc"; export const menuRouter = createTRPCRouter({ + get: publicProcedure.query(({ ctx }) => { + const _ = ctx; + // get a menu + + // get it from prisma + // if not there, call parse procedure + }), hello: publicProcedure.query(async ({ ctx }) => { const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1"); console.log(res.data); diff --git a/packages/validators/src/index.ts b/packages/validators/src/index.ts index e864f183..2e10a973 100644 --- a/packages/validators/src/index.ts +++ b/packages/validators/src/index.ts @@ -5,4 +5,3 @@ export const CreatePostSchema = z.object({ content: z.string().min(1), }); -export const GetMenuSchema = z.object({}); diff --git a/packages/validators/src/menu.ts b/packages/validators/src/menu.ts new file mode 100644 index 00000000..bee9088c --- /dev/null +++ b/packages/validators/src/menu.ts @@ -0,0 +1,3 @@ +import { z } from "zod"; + +export const GetMenuSchema = z.object({});