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
4 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