drizzle-studio doesn't see pgView materialized views
I have existing materialized views and marked as such in my schema, but drizzle studio doesn't see them. the drizzle studio schema seems to have left them out when being generated
here is the relevant part of my schema that drizzle studio leaves out
export const claimsView = pgView("claims_view", {
customerCode: varchar("customer_code", { length: 8 }).notNull(),
totalPetitionValue: numeric("total_petition_value"),
totalPetitionValueCurrency: text("total_petition_value").notNull(),
totalLatestValue: numeric("total_latest_value"),
totalLatestValueCurrency: text("total_latest_value").notNull(),
}).existing(); // existing() tells drizzle that this view already exists in the db
export const claimAssetsView = pgView("claim_assets_view", {
customerCode: varchar("customer_code", { length: 8 }).notNull(),
name: text("name").notNull(),
type: text("type").notNull(),
balance: numeric("balance").notNull(),
usdPetition: numeric("usd_petition"),
usdPetitionCurrency: text("usd_petition").notNull(),
usdLatest: numeric("usd_latest"),
usdLatestCurrency: text("usd_latest").notNull(),
}).existing(); // existing() tells drizzle that this view already exists in the db
6 Replies
Refer to this thread: https://discord.com/channels/1043890932593987624/1184451142718062592
@Rami that thread isn't helping. pls take a look at my code above
Drizzle doesn't yet support views. You will have to manually write an SQL script that would create that view. Then create a custom migration by running:
drizzle-kit generate:pg --custom
. Insert that SQL script into that generated migration file. Then run your migrations to update your database to have that view. This is my migration.ts file if you haven't made one:
Check this page for more info: https://orm.drizzle.team/docs/migrationsDrizzle ORM - Migrations
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Also for the SQL query that creates the materialized views, this is an example:
P.S I'm just someone who started working with drizzle like 2 month back and this is my workflow with creating materialized views
I recommend building and testing out the SQL query for whatever you want the view to be inside drizzle studio, so for example if I want to test out the previous materialized view, I would run:
In there to see if it gives me what I want
Hi, is still the case? I can see that support for pgView was added in https://github.com/drizzle-team/drizzle-orm/blob/866c257b2d5e7e98415b77f726e72862360d5502/changelogs/drizzle-kit/0.26.0.md 2 months ago. I am trying to add a pgView in my schema but it wont add them on generate. I checked adding test table so I know for a fact that it can identify changes, but not picking up pgView and pgMateralizedView.
Thanks for your attention
GitHub
drizzle-orm/changelogs/drizzle-kit/0.26.0.md at 866c257b2d5e7e98415...
Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅 - drizzle-team/drizzle-orm
Got no error messages or so, and checked the validity of the view creation with pure SQL script