Skip to content

Commit

Permalink
Merge pull request #93 from icssc/data-model-andy
Browse files Browse the repository at this point in the history
Schema tweaks
  • Loading branch information
KatyH820 authored Feb 3, 2024
2 parents 7eec868 + 6926e0b commit 65abd01
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 147 deletions.
22 changes: 1 addition & 21 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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=''
DATABASE_URL=""
7 changes: 7 additions & 0 deletions packages/api/src/router/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
88 changes: 88 additions & 0 deletions packages/db/prisma/migrations/20240203184145_/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
172 changes: 47 additions & 125 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
// }
}
1 change: 0 additions & 1 deletion packages/validators/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export const CreatePostSchema = z.object({
content: z.string().min(1),
});

export const GetMenuSchema = z.object({});
3 changes: 3 additions & 0 deletions packages/validators/src/menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { z } from "zod";

export const GetMenuSchema = z.object({});

0 comments on commit 65abd01

Please sign in to comment.