Skip to content

Commit

Permalink
feat(prisma): add createdAt and updatedAt fields
Browse files Browse the repository at this point in the history
This patch adds `createdAt` and `updatedAt` timestamp fields to
everything. The `updatedAt` field will be automatically set by Prisma
whenever we make an update due to the `@updatedAt` attribute [[1]].

[1]: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#updatedat
  • Loading branch information
nicholaschiang committed Jul 23, 2023
1 parent df8fdfb commit 00dda3f
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 29 deletions.
11 changes: 5 additions & 6 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ import {
} from '@remix-run/react'
import { Analytics } from '@vercel/analytics/react'
import {
type SerializeFrom,
type LinksFunction,
type LoaderArgs,
type V2_MetaFunction,
json,
} from '@vercel/remix'
import { json } from '@vercel/remix'
import cn from 'classnames'
import { LogIn, LogOut } from 'lucide-react'
import { Fragment, type ReactNode } from 'react'

import { ThemeSwitcher } from 'components/theme-switcher'
import { buttonVariants } from 'components/ui/button'

import { type User } from 'models/user.server'

import tailwindStylesheetUrl from 'styles/tailwind.css'

import { getSession, getUser, sessionStorage } from 'session.server'
Expand Down Expand Up @@ -173,13 +172,11 @@ declare global {
}
}

export type LoaderData = { user: User | null; theme: Theme | null; env: Env }

export async function loader({ request }: LoaderArgs) {
const session = await getSession(request)
const theme = session.get('theme') as Theme | null
const headers = { 'Set-Cookie': await sessionStorage.commitSession(session) }
return json<LoaderData>(
return json(
{
user: await getUser(request),
theme: isTheme(theme) ? theme : null,
Expand All @@ -189,6 +186,8 @@ export async function loader({ request }: LoaderArgs) {
)
}

export type LoaderData = SerializeFrom<typeof loader>

function App({ data, children }: { data?: LoaderData; children: ReactNode }) {
const [theme] = useTheme()
return (
Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/aritzia.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// - materials
// - reviews

import type { Product, Style, StyleGroup } from '@prisma/client'
import { type Style } from '@prisma/client'
import invariant from 'tiny-invariant'

type DataMaster = {
Expand Down Expand Up @@ -191,6 +191,8 @@ describe('aritzia', () => {
}).forEach(([category, { ignore }]) => {
const style: DataStyle = {
id: styleId,
createdAt: new Date(),
updatedAt: new Date(),
name: category.charAt(0).toUpperCase() + category.slice(1),
styleGroupId: null,
parentId: null,
Expand All @@ -209,6 +211,8 @@ describe('aritzia', () => {
} else {
const child: DataStyle = {
id: styleId,
createdAt: new Date(),
updatedAt: new Date(),
name: el.text().trim(),
catid: el.attr('data-cat-id') as string,
styleGroupId: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
-- AlterTable
ALTER TABLE "Brand" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Collection" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Color" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Company" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Country" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Image" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Link" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Look" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Material" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Password" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Price" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Product" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Publication" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Retailer" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Review" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Season" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Show" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Size" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Style" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "StyleGroup" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "User" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Variant" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Video" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
Loading

0 comments on commit 00dda3f

Please sign in to comment.