Skip to content

Commit

Permalink
fix: make show video and review score optional
Browse files Browse the repository at this point in the history
This patch updates the show and review models to make their video and
score fields optional, respectively. This change is required to ensure
that I do not add nonsensical defaults when importing data from e.g.
Vogue. Instead, these fields will simply be NULL by default and render
differently in the UI until I manually go in and augment the imported
data with those missing fields.
  • Loading branch information
nicholaschiang committed Jul 25, 2023
1 parent a21fdd4 commit 852c587
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
26 changes: 14 additions & 12 deletions app/routes/shows.$showId/scores-header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Sex } from '@prisma/client'
import { useLoaderData } from '@remix-run/react'
import { useMemo } from 'react'
import { Sex } from '@prisma/client'

import { prisma } from 'db.server'
import { cn } from 'utils/cn'
Expand Down Expand Up @@ -29,7 +29,7 @@ function sanityCheck(score: Score, name: string): void {
export async function getScores(showId: number): Promise<Scores> {
const [total, positive, neutral, negative] = await Promise.all([
prisma.review.count({
where: { showId },
where: { showId, score: { not: null } },
select: { _all: true, publicationId: true },
}),
prisma.review.count({
Expand Down Expand Up @@ -75,16 +75,18 @@ export function ScoresHeader() {
: ''
return (
<div className='grid gap-2'>
<video
className='aspect-video w-full bg-gray-100 dark:bg-gray-900'
controls
autoPlay
playsInline
muted
>
<source src={show.video.url} type={show.video.mimeType} />
Download the <a href={show.video.url}>MP4</a> video.
</video>
{show.video != null && (
<video
className='aspect-video w-full bg-gray-100 dark:bg-gray-900'
controls
autoPlay
playsInline
muted
>
<source src={show.video.url} type={show.video.mimeType} />
Download the <a href={show.video.url}>MP4</a> video.
</video>
)}
<div className='flex gap-2'>
<div className='flex-none w-40 bg-gray-100 dark:bg-gray-900 h-0 min-h-full'>
<img
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Review" ALTER COLUMN "score" DROP NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Show" ALTER COLUMN "videoId" DROP NOT NULL;
9 changes: 6 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,10 @@ model Review {
// Critical reviews will use whatever scale the critic uses (e.g. 0-10) or
// will revert back to using a five-star scale if the critic does not assign
// a score in their review (it will then be assigned via OpenAI).
score Decimal
//
// This field should only ever be NULL if a critic review has been imported
// but no score has been assigned to it yet (e.g. when scraping Vogue).
score Decimal?
// The review summary (generated via OpenAI).
summary String?
Expand Down Expand Up @@ -843,8 +846,8 @@ model Show {
reviews Review[]
// Video of the show (typically just a single shot of runway models walking).
video Video @relation(fields: [videoId], references: [id], onDelete: Cascade, onUpdate: Cascade)
videoId Int @unique
video Video? @relation(fields: [videoId], references: [id], onDelete: Cascade, onUpdate: Cascade)
videoId Int? @unique
// The fashion season in which the show was presented. e.g. Spring 2021
// @todo collections are already associated with seasons; do we need this?
Expand Down

0 comments on commit 852c587

Please sign in to comment.