Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix db timestamps to match db values #305

Closed
wants to merge 1 commit into from
Closed
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
69 changes: 69 additions & 0 deletions prisma/migrations/20231102094755_fix_timestamps/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- AlterTable
ALTER TABLE "Account" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "AnalyticsEvent" ALTER COLUMN "timestamp" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Attach" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "CalendarEvent" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "CalendarEventCancellation" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "CalendarEventDetails" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "CalendarEventException" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Candidate" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Interview" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "InterviewEvent" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Problem" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Reaction" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Section" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "SectionType" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Session" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Solution" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "Tag" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "User" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());

-- AlterTable
ALTER TABLE "VerificationRequest" ALTER COLUMN "createdAt" SET DEFAULT timezone('utc'::text, now()),
ALTER COLUMN "updatedAt" SET DEFAULT timezone('utc'::text, now());
64 changes: 32 additions & 32 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ model Account {
password String?
userId Int
user User @relation(fields: [userId], references: [id])
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt

@@unique([provider, providerAccountId])
}
Expand All @@ -37,8 +37,8 @@ model Session {
expires DateTime
sessionToken String @unique
accessToken String @unique
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
user User @relation(fields: [userId], references: [id])
}

Expand All @@ -47,8 +47,8 @@ model VerificationRequest {
identifier String
token String @unique
expires DateTime
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt

@@unique([identifier, token])
}
Expand All @@ -63,8 +63,8 @@ model User {
favoriteProblems Problem[] @relation("FavoriteProblems")
section Section[]
createdInterviews Interview[]
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
accounts Account[]
sessions Session[]
interviewEvents InterviewEvent[]
Expand Down Expand Up @@ -97,8 +97,8 @@ model Problem {
solutionsOk Int @default(0)
solutionsBad Int @default(0)

createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt

@@index([name])
}
Expand All @@ -108,8 +108,8 @@ model Tag {
name String
problems Problem[]
color String?
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
}

model Candidate {
Expand All @@ -121,8 +121,8 @@ model Candidate {
email String? @unique
phone String? @unique
interviews Interview[]
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt

@@index([name])
@@index([email])
Expand All @@ -144,8 +144,8 @@ model Interview {
status InterviewStatus @default(NEW)
sections Section[]
feedback String?
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
candidateSelectedSectionId Int?
candidateSelectedSection Section? @relation(name: "CandidateSelectedSection", fields: [candidateSelectedSectionId], references: [id])
interviewEvents InterviewEvent[]
Expand All @@ -169,8 +169,8 @@ model Section {
isCanceled Boolean @default(false)
canceledAt DateTime?
cancelComment String?
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
sectionType SectionType @relation(fields: [sectionTypeId], references: [id])
sectionTypeId Int
selectedInInterviews Interview[] @relation("CandidateSelectedSection")
Expand All @@ -190,8 +190,8 @@ model Solution {
answer String?
result SolutionResult @default(UNKNOWN)
position Int @default(autoincrement())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt

@@unique([problemId, sectionId])
}
Expand All @@ -205,8 +205,8 @@ model InterviewEvent {
type String
before Json?
after Json?
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
}

model HireStream {
Expand All @@ -222,8 +222,8 @@ model HireStream {
/// Section type parameters
model SectionType {
id Int @id @default(autoincrement())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt
hireStream HireStream @relation(fields: [hireStreamId], references: [id])
hireStreamId Int

Expand Down Expand Up @@ -270,15 +270,15 @@ model Reaction {
interviewId Int
interview Interview @relation(fields: [interviewId], references: [id])
text String?
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @updatedAt
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
updatedAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @updatedAt

@@unique([interviewId, userId])
}

model AnalyticsEvent {
id Int @id @default(autoincrement())
timestamp DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
timestamp DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
authUserId Int?
event String
candidateId Int?
Expand Down Expand Up @@ -322,7 +322,7 @@ enum SolutionResult {
/// Can be treated as main event/series (CalendarEvent), so to exception event (CalendarEventException)
model CalendarEventDetails {
id String @id @default(uuid())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()

title String
description String
Expand All @@ -337,7 +337,7 @@ model CalendarEventDetails {
/// Master record of a series of events, or an independent event without repetitions
model CalendarEvent {
id String @id @default(uuid())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()

/// Format rule
/// Always contains the date of the main event, for a series of events it also contains a recurrence rule
Expand All @@ -362,7 +362,7 @@ model CalendarEvent {
/// Exception events from a recurring event series
model CalendarEventException {
id String @id @default(uuid())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()

/// Date excluded from the series of events
originalDate DateTime
Expand All @@ -386,7 +386,7 @@ model CalendarEventException {
/// Canceled event series instances
model CalendarEventCancellation {
id String @id @default(uuid())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()

/// Date excluded from the series of events
originalDate DateTime
Expand All @@ -398,7 +398,7 @@ model CalendarEventCancellation {

model Attach {
id String @id @default(uuid())
createdAt DateTime @default(dbgenerated("timezone('utc', current_timestamp)")) @db.Timestamp()
createdAt DateTime @default(dbgenerated("timezone('utc'::text, now())")) @db.Timestamp()
link String
filename String
deletedAt DateTime?
Expand Down
22 changes: 14 additions & 8 deletions src/components/layout/LayoutMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const StyledContainer = styled.div`
padding-left: 40px;
`;

const StyledContent = styled.main`
/* presses the footer to the bottom*/
min-height: calc(100vh - 160px);
`;

export const LayoutMain: FC<LayoutMainProps> = ({
pageTitle,
aboveContainer,
Expand Down Expand Up @@ -54,16 +59,17 @@ export const LayoutMain: FC<LayoutMainProps> = ({
{nullable(theme, (t) => (
<Theme theme={t} />
))}
<StyledContent>
{!hidePageHeader && (
<PageTitle title={pageTitle} gutter={headerGutter} backlink={backlink}>
{titleMenuItems && titleMenuItems.length > 0 && <TitleMenu items={titleMenuItems} />}
</PageTitle>
)}

{!hidePageHeader && (
<PageTitle title={pageTitle} gutter={headerGutter} backlink={backlink}>
{titleMenuItems && titleMenuItems.length > 0 && <TitleMenu items={titleMenuItems} />}
</PageTitle>
)}

{aboveContainer}
{aboveContainer}

<StyledContainer>{children}</StyledContainer>
<StyledContainer>{children}</StyledContainer>
</StyledContent>

<PageFooter />
</>
Expand Down
16 changes: 16 additions & 0 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as Sentry from '@sentry/nextjs';

import { LayoutMain } from '../components/layout/LayoutMain';

export type ErrorProps = {
statusCode: number;
message: string;
};

export default function Custom404() {
return (
<Sentry.ErrorBoundary fallback={<p>404 on hire</p>}>
<LayoutMain pageTitle="Nothing found 😔" />
</Sentry.ErrorBoundary>
);
}
7 changes: 4 additions & 3 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { FC, useEffect } from 'react';
import * as SentryNextJs from '@sentry/nextjs';
import * as SentryBrowser from '@sentry/browser';
import { link0 } from '@taskany/colors';
import { ErrorProps } from 'next/error';

import { AppSettingsContextProvider } from '../contexts/app-settings-context';
import { ProblemFilterContextProvider } from '../contexts/problem-filter-context';
Expand All @@ -20,6 +19,8 @@ import { trpc } from '../utils/trpc-front';
import { TLocale, setSSRLocale } from '../utils/getLang';
import '../../react-big-calendar.css';

import Error, { ErrorProps } from './_error';

type TaskanyHireAppProps = {
session: Session;
browser: Browser;
Expand All @@ -28,7 +29,7 @@ type TaskanyHireAppProps = {

const TaskanyHireApp: FC<AppProps<TaskanyHireAppProps>> = ({ Component, pageProps, router }) => {
setSSRLocale(router.locale as TLocale);
const { session, browser } = pageProps;
const { session, browser, error, ...restPageProps } = pageProps;

useEffect(() => {
SentryBrowser.setUser({
Expand Down Expand Up @@ -57,8 +58,8 @@ const TaskanyHireApp: FC<AppProps<TaskanyHireAppProps>> = ({ Component, pageProp
<ThemeProvider themes={['light', 'dark']}>
<ProblemFilterContextProvider>
<CandidateFilterContextProvider>
<Component {...pageProps} />
<ReactQueryDevtools />
{error ? <Error {...error} /> : <Component {...restPageProps} />}
</CandidateFilterContextProvider>
</ProblemFilterContextProvider>
</ThemeProvider>
Expand Down
29 changes: 22 additions & 7 deletions src/pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import * as Sentry from '@sentry/nextjs';
import type { NextPage } from 'next';
import type { ErrorProps } from 'next/error';
import NextErrorComponent from 'next/error';
import type { NextPage, NextPageContext } from 'next';

const CustomErrorComponent: NextPage<ErrorProps> = (props) => <NextErrorComponent statusCode={props.statusCode} />;
import { LayoutMain } from '../components/layout/LayoutMain';

CustomErrorComponent.getInitialProps = async (contextData) => {
await Sentry.captureUnderscoreErrorException(contextData);
export type ErrorProps = {
statusCode: number;
message: string;
};

const CustomErrorComponent: NextPage<ErrorProps> = ({ message }: ErrorProps) => {
return (
<Sentry.ErrorBoundary fallback={<p>{message}</p>}>
<LayoutMain pageTitle={message} />
</Sentry.ErrorBoundary>
);
};

CustomErrorComponent.getInitialProps = ({ err, res }: NextPageContext) => {
const message = err?.message || 'Unexpected error';

let statusCode = err?.statusCode || 404;

if (!err && res) statusCode = res.statusCode;

return NextErrorComponent.getInitialProps(contextData);
return { statusCode, message };
};

export default CustomErrorComponent;
Loading
Loading