Skip to content
Merged
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
3 changes: 0 additions & 3 deletions .github/workflows/deploy-to-vm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ jobs:
printf 'DATABASE_URL="%s"\n' "$DATABASE_URL" > apps/backend/.env
cp apps/backend/.env packages/db/.env
- name: Apply database migrations
run: pnpm --filter @t09-project-2/db run db:push

- name: Generate Prisma client
run: pnpm --filter @t09-project-2/db run db:generate

Expand Down
1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@apollo/server": "^5.5.1",
"@pothos/core": "^4.0.0",
"@pothos/plugin-prisma": "^4.0.0",
"@pothos/plugin-with-input": "^4.1.5",
"@t09-project-2/db": "workspace:*",
"graphql": "^16.9.0"
},
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDatamodel, prisma } from '@t09-project-2/db'
import type { PrismaTypes } from '@t09-project-2/db'

import type { Context } from './context.js'
import WithInputPlugin from '@pothos/plugin-with-input'

export const builder = new SchemaBuilder<{
Context: Context
Expand All @@ -16,7 +17,7 @@ export const builder = new SchemaBuilder<{
}
}
}>({
plugins: [PrismaPlugin],
plugins: [PrismaPlugin, WithInputPlugin],
prisma: {
client: prisma,
dmmf: getDatamodel(),
Expand Down
33 changes: 33 additions & 0 deletions apps/backend/src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ builder.prismaObject('Venue', {
openingHours: t.relation('openingHours'),
city: t.relation('city'),
pricesSighted: t.relation('pricesSighted'),
reviews: t.relation('reviews'),
}),
})

Expand All @@ -38,6 +39,17 @@ builder.prismaObject('City', {
}),
})

builder.prismaObject('Review', {
fields: (t) => ({
id: t.exposeString('id'),
username: t.exposeString('username'),
body: t.exposeString('body'),
rating: t.exposeInt('rating'),
timeCreated: t.expose('timeCreated', { type: 'DateTime' }),
venueId: t.exposeString('venueId'),
}),
})

const priceSightingRef = builder.prismaObject('PriceSighting', {
select: {
size: true,
Expand Down Expand Up @@ -204,3 +216,24 @@ builder.queryType({
}),
}),
})

builder.mutationType({
fields: (t) => ({
createReview: t.prismaFieldWithInput({
type: 'Review',
input: {
venueId: t.input.string({ required: true }),
username: t.input.string({ required: true }),
body: t.input.string({ required: true }),
rating: t.input.int({ required: true }),
},
resolve: (query, _parent, args) =>
prisma.review.create({
...query,
data: {
...args.input,
},
}),
}),
}),
})
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"db:migrate": "dotenv -e .env -- prisma migrate dev",
"db:seed": "dotenv -e .env -- prisma db seed",
"db:studio": "dotenv -e .env -- prisma studio",
"db:reset": "dotenv -e .env -- prisma migrate reset",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "review" (
"id" UUID NOT NULL DEFAULT uuidv7(),
"username" TEXT NOT NULL,
"body" TEXT NOT NULL,
"rating" INTEGER NOT NULL,
"time_created" TIMESTAMPTZ NOT NULL DEFAULT now(),
"venue_id" UUID NOT NULL,

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

-- AddForeignKey
ALTER TABLE "review" ADD CONSTRAINT "review_venue_id_fkey" FOREIGN KEY ("venue_id") REFERENCES "venue"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
14 changes: 14 additions & 0 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ model Venue {
city City @relation(fields: [cityId], references: [id])
pricesSighted PriceSighting[]
reviews Review[]
@@map("venue")
}
Expand Down Expand Up @@ -97,3 +98,16 @@ model PriceSighting {
@@map("price_sighting")
}

model Review {
id String @id @default(dbgenerated("uuidv7()")) @db.Uuid
username String
body String
rating Int
timeCreated DateTime @map("time_created") @db.Timestamptz() @default(dbgenerated("now()"))
venueId String @map("venue_id") @db.Uuid
venue Venue @relation(fields: [venueId], references: [id])
@@map("review")
}
86 changes: 79 additions & 7 deletions packages/db/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function at(time: string) {
async function main() {
console.log('Seeding database...')

await prisma.review.deleteMany()
await prisma.priceSighting.deleteMany()
await prisma.openingHours.deleteMany()
await prisma.venue.deleteMany()
Expand Down Expand Up @@ -65,6 +66,20 @@ async function main() {
},
],
},
reviews: {
create: [
{
username: 'bakklandet_wanderer',
body: 'Classic Trondheim pub by the river. Great atmosphere and friendly staff!',
rating: 5,
},
{
username: 'beer_enthusiast',
body: 'Good selection, but it gets crowded on sunny days.',
rating: 4,
},
],
},
},
{
name: 'Skjenkestua',
Expand Down Expand Up @@ -101,6 +116,15 @@ async function main() {
},
],
},
reviews: {
create: [
{
username: 'cozy_seeker',
body: 'Intimate little spot with a fireplace. Perfect for a quiet pint.',
rating: 4,
},
],
},
},
{
name: 'Baklandet Skydsstation',
Expand Down Expand Up @@ -132,6 +156,20 @@ async function main() {
},
],
},
reviews: {
create: [
{
username: 'sunday_sipper',
body: 'Charming venue, but the prices are on the higher side.',
rating: 3,
},
{
username: 'historic_pub_fan',
body: 'Oldest pub on Bakklandet! A must-visit for the vibes alone.',
rating: 5,
},
],
},
},
{
name: 'Trondheim Torg Pub',
Expand Down Expand Up @@ -171,6 +209,15 @@ async function main() {
},
],
},
reviews: {
create: [
{
username: 'city_center_local',
body: 'Convenient location, but nothing special. Fine for a quick one.',
rating: 3,
},
],
},
},
],
},
Expand Down Expand Up @@ -216,6 +263,20 @@ async function main() {
},
],
},
reviews: {
create: [
{
username: 'dubliner_regular',
body: 'Live music every weekend! Feels like a little slice of Ireland.',
rating: 5,
},
{
username: 'oslo_nightowl',
body: 'Great selection of stouts, though a bit pricey even for Oslo.',
rating: 4,
},
],
},
},
{
name: 'Tilt',
Expand Down Expand Up @@ -256,21 +317,32 @@ async function main() {
},
],
},
reviews: {
create: [
{
username: 'arcade_addict',
body: 'Retro games and craft beer, what more could you want?',
rating: 5,
},
],
},
},
],
},
},
})

const [cities, venues, openingHours, priceSightings] = await Promise.all([
prisma.city.count(),
prisma.venue.count(),
prisma.openingHours.count(),
prisma.priceSighting.count(),
])
const [cities, venues, openingHours, priceSightings, reviews] =
await Promise.all([
prisma.city.count(),
prisma.venue.count(),
prisma.openingHours.count(),
prisma.priceSighting.count(),
prisma.review.count(),
])

console.log(
`Created ${cities} cities, ${venues} venues, ${openingHours} opening hours entries, and ${priceSightings} price sightings`,
`Created ${cities} cities, ${venues} venues, ${openingHours} opening hours entries, ${priceSightings} price sightings, and ${reviews} reviews`,
)
}

Expand Down
Loading