#npx payload generate:db-schema

38 messages · Page 1 of 1 (latest)

stiff kayak
#

In the docs (https://payloadcms.com/docs/database/postgres#access-to-drizzle) it says to access Drizzle to run this:

npx payload generate:db-schema

but when i try that i am getting:

Unknown script: "generate:db-schema". as a response

Is there something else i need to do to add this script? I have updated tot he latest version and also tried making a brand new payload project and still dont have this script added or listed in the package.json file?

Payload

Payload is a headless CMS and application framework built with TypeScript, Node.js, React and MongoDB

neon kettleBOT
void cedar
#

@agile fern Going to include you here so we can continue in this thread instead

#

This PR was merged to main, but not yet released. This means that you do not have access to it

#

You have to wait for the next release of the packages in order to utilize this feature

agile fern
#

and you guys updated in docs early

#

literally wasted my hours to get it work

#

@void cedar

void cedar
#

Sorry to hear that

#

But this is purely type-safety

#

You can still access drizzle

agile fern
#

yessir but this would be a cherry on top if i can able to have this!

#

btw when the next release?

void cedar
#

Look for the next release, they come pretty often, keep an eye out on the #releases channel

#

Wouldn't be surprised if we got one today

#

Although I don't know for certain

agile fern
#

we got one yesterday

#

maybe today or tomorrow

obsidian glade
#

Literally joined the Discord because of that one 🙂

vernal kindle
#

yeah had a feeling something was off. seeing that generateSchemaOutputFile wasn't in the types

#

this is pretty crazy functionality though. so i already have a pretty complex RBAC multi-tenant setup using drizzle and RLS policies for my core application, so I wanted to keep all of my payload stuff separate from my core application functionality. by just setting the schema from public to payload and the default migrations folder to /payload-migrations i'm able to just keep everything separate, have both auth systems in the same DB, and still auto-manage full type-safety and zod schemas in my trpc procedures.

looks like next-step is to not use it totally headless for the landing page and marketing (blog) routes for SEO purposes, looks like there's a lot of QoL stuff for SEO with payload

void cedar
#

But keep an eye out, something tells me a release will be incoming today for db-schema type-safety

vernal kindle
#

yeah very impressed so far. feels like the core stack for everyone is starting to go in the nextjs/shadcn/tailwind/supabase(or just pg/pgvector)/drizzle (for me trpc as well) direction. just because of the QoL of vercel ai sdk and v0.dev, and with everything being typed and the tailwind inline, the cursor/v0 driven development has maybe 10x'd my productivity. it is practically not making any mistakes now because all the context is just there upfront with types and tailwind. and the tools are increasingly converging, and adding direct support.

feels like payload can get in on this wave, and fits right in. right everyones exploring this new QoL tech stack for building AI apps, and then payload is just there to also solve the QoL improvements for CMS space at the same time. i could see something like leveraging the shadcn/v0 block feature to have payload users or team create features (like a blog and it's corresponding collections/blocks/components) into a project with just a command

oak tapir
#

Right, this is very common for more complex apps that the Local API is simply not enough. For example complex aggregations or important optimized queries now you can just do them with the full Drizzle's Typescript power. That was my motivation to build this feature

#

We'll also have the Realtime API soon that will allow you to use websockets, either to subscribe to "hooks" from the frontend / across many instances or build your own logic with custom events on top of it.

void cedar
#

Unreal... can't believe the progress, every week with something absolutely killer

#

Great job here

void cedar
#

@agile fern @obsidian glade @stiff kayak @vernal kindle 3.10.0 was just released, including the aforementioned PR changes!

#

Thanks Ritsu!

stiff kayak
# void cedar <@739936813355106447> <@965514529712775189> <@1176531473071882350> <@52412414006...

Cheers for that!

it now creates the schema fine

the code ive been using though

const secContent = await payload.db.drizzle.query.pages_sections.findFirst({
    where: (pages_sections, { eq }) => eq(pages_sections.id, sectionId),
  })

while it works, still has type errors. what do i need to include from the new schema types to get rid of the type errors?

tried importing this:
import { pages_sections } from '@/payload-generated-schema'

but doesnt seem to help and im still left with type errors in vs code on the pages_sections parts?

oak tapir
#

what kind of errors do you have? have you tried to restart TS server?

#

it might be needed to do so, ctrl shift p -> Typescript: Restart

stiff kayak
oak tapir
#

shouldn't be needed in the future I think, it's because the generated file has declaration

#

glad that it works

stiff kayak
# oak tapir glad that it works

yep, thanks for your help. the whole querying and possabilities with payload have just multiplied infinately. gone from thinking i could use it for a quick admin to now i could actully use it for the whole db for the site.

void cedar
#

Everyone here owes Ritsu a Christmas present now