thejessewinton
thejessewinton
Explore posts from servers
DTDrizzle Team
Created by thejessewinton on 2/2/2024 in #help
Not enough information to infer relation
I’m having an issue with my schema that is a migration from Prisma. For this particular issue, I have a job table, and a candidates table, each of them has a many relation to the other, so a job can have many candidates, and a candidate can have many jobs. When I try and run my project, I’m getting “There is not enough information to infer relation “job.candidates”.” Here’s my schema, can’t figure out what I’m doing wrong:
export const candidates = mysqlTable(
'candidates',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
user_id: varchar('user_id', { length: 255 }).notNull(),
job_id: bigint('job_id', { mode: 'number' }).notNull()
},
(table) => ({
jobIdIdx: index('candidates_jobId_idx').on(table.job_id),
userIdIdx: index('candidates_userId_idx').on(table.user_id)
})
)

export const candidatesRelations = relations(candidates, ({ one, many }) => ({
user: one(users, { fields: [candidates.user_id], references: [users.id], relationName: 'candidateToUser' }),
jobs: many(job, { relationName: 'candidatesToJob' })
}))

export const job = mysqlTable(
'job',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
title: text('title').notNull(),
user_id: varchar('user_id', { length: 255 }).notNull(),
team_id: bigint('team_id', { mode: 'number' }).notNull()
},
(table) => ({
userIdIdx: index('jobs_userId_idx').on(table.user_id),
teamIdIdx: index('jobs_teamId_idx').on(table.team_id)
})
)

export const jobRelations = relations(job, ({ one, many }) => ({
user: one(users, { fields: [job.user_id], references: [users.id], relationName: 'user' }),
candidates: many(candidates, { relationName: 'candidatesToJob' }),
tags: many(tags, { relationName: 'tags' }),
job_activity: many(jobActivity, { relationName: 'job_activity' }),
comments: many(jobComments, { relationName: 'job_comments' })
}))
export const candidates = mysqlTable(
'candidates',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
user_id: varchar('user_id', { length: 255 }).notNull(),
job_id: bigint('job_id', { mode: 'number' }).notNull()
},
(table) => ({
jobIdIdx: index('candidates_jobId_idx').on(table.job_id),
userIdIdx: index('candidates_userId_idx').on(table.user_id)
})
)

export const candidatesRelations = relations(candidates, ({ one, many }) => ({
user: one(users, { fields: [candidates.user_id], references: [users.id], relationName: 'candidateToUser' }),
jobs: many(job, { relationName: 'candidatesToJob' })
}))

export const job = mysqlTable(
'job',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
title: text('title').notNull(),
user_id: varchar('user_id', { length: 255 }).notNull(),
team_id: bigint('team_id', { mode: 'number' }).notNull()
},
(table) => ({
userIdIdx: index('jobs_userId_idx').on(table.user_id),
teamIdIdx: index('jobs_teamId_idx').on(table.team_id)
})
)

export const jobRelations = relations(job, ({ one, many }) => ({
user: one(users, { fields: [job.user_id], references: [users.id], relationName: 'user' }),
candidates: many(candidates, { relationName: 'candidatesToJob' }),
tags: many(tags, { relationName: 'tags' }),
job_activity: many(jobActivity, { relationName: 'job_activity' }),
comments: many(jobComments, { relationName: 'job_comments' })
}))
11 replies
TTCTheo's Typesafe Cult
Created by thejessewinton on 6/26/2023 in #questions
Passing function error on Contentful live preview client component
I'm trying to build a custom component for Contentful's live preview feature in Next 13 with the app directory. My idea is to create a client component which accepts a data prop from the parent, as well as a generic type to make the updatedData prop that's passed back down type-safe:
'use client'

import { useContentfulLiveUpdates } from '@contentful/live-preview/react'

const isFunction = <T extends CallableFunction = CallableFunction>(value: unknown): value is T =>
typeof value === 'function'

export const runIfFunction = <T, U>(valueOrFn: T | ((...fnArgs: U[]) => T), ...args: U[]) => {
return isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn
}

type MaybeRenderProp<P> = React.ReactNode | ((props: P) => React.ReactNode)

type LivePreviewWrapperProps<T> = {
children: MaybeRenderProp<{
updatedData: T
}>
data: T
}

export const LivePreviewWrapper = <T extends Record<string, unknown>>({
children,
data
}: LivePreviewWrapperProps<T>) => {
const updatedData = useContentfulLiveUpdates<T>(data, { locale: 'en-US' })

return runIfFunction(children, { updatedData })
}
'use client'

import { useContentfulLiveUpdates } from '@contentful/live-preview/react'

const isFunction = <T extends CallableFunction = CallableFunction>(value: unknown): value is T =>
typeof value === 'function'

export const runIfFunction = <T, U>(valueOrFn: T | ((...fnArgs: U[]) => T), ...args: U[]) => {
return isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn
}

type MaybeRenderProp<P> = React.ReactNode | ((props: P) => React.ReactNode)

type LivePreviewWrapperProps<T> = {
children: MaybeRenderProp<{
updatedData: T
}>
data: T
}

export const LivePreviewWrapper = <T extends Record<string, unknown>>({
children,
data
}: LivePreviewWrapperProps<T>) => {
const updatedData = useContentfulLiveUpdates<T>(data, { locale: 'en-US' })

return runIfFunction(children, { updatedData })
}
But, when I'm trying to use it in the app, this is the error that I'm getting:
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
<... data={{...}} children={function}>
^^^^^^^^^^
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
<... data={{...}} children={function}>
^^^^^^^^^^
Anyone have any ideas of how to get around this? I can include my implementation inside a page, but this message is too long atm.
1 replies
TTCTheo's Typesafe Cult
Created by thejessewinton on 4/11/2023 in #questions
@next/mdx with slug in app dir
Doing some experimentation with the app directory, and I’m curious if anyone has seen or can find documentation for how to do dynamic slugs for posts within the app directory using @next/mdx to fetch content? So that /blog/dynamic-slug would fetch the right MDX doc. Should I just opt for contentlayer instead?
1 replies
TTCTheo's Typesafe Cult
Created by thejessewinton on 12/6/2022 in #questions
Multiple DB Connections and Prisma clients
I have 2 databases that are handling different elements of my platform; because of the limitations of Prisma for multi-tenant connection, I need to have multiple clients. At the same time, using the output property does't resolve correctly in my Turborepo setup, so it makes it difficult to do so. I'm getting some conflicts between the clients, and had to ultimately take one of my clients out of the packages, and move it side-by-side with the app that uses it most. It's just inefficient; anyone have any ways to get around this and be able to have multiple clients in a Turborepo setup?
4 replies
TTCTheo's Typesafe Cult
Created by thejessewinton on 9/28/2022 in #questions
Trouble with NEXTAUTH_URL
I've been getting the missing next auth url error in my console, even though my NEXTAUTH_URL is defined in my .env:
dev: [next-auth][warn][NEXTAUTH_URL]
dev: https://next-auth.js.org/warnings#nextauth_url
dev: [next-auth][warn][NEXTAUTH_URL]
dev: https://next-auth.js.org/warnings#nextauth_url
I'm using a turborepo monorepo, and I have .env files in each of my applications, as well as .env.local to override the .env. If I console.log my env the correct variable shows up there, but for some reason it's not loading and it's getting in the way of my ability to develop what I'm needing to dev. Anyone have any insight into what could be going on? Or experiencing the same thing?
1 replies
TTCTheo's Typesafe Cult
Created by thejessewinton on 9/18/2022 in #questions
GitHub Action for Linting with Vercel
I’m trying to setup GitHub Actions to lint and prettify the code in my turborepo monorepo; it’s great and works really well to get everything set, but it’s throwing an error from Vercel; the lint-action user doesn’t have access to my Vercel account to create a preview deployment, and at the same time I don’t want linting to create a separate deployment. Given these things, is there a reason to use actions for this instead of something like lint-staged as a pre-commit hook?
67 replies