drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Materialized views not being included in the schema file with introspect:pg

Open juanjalvarez opened this issue 2 years ago • 5 comments

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

0.20.10

Describe the Bug

  • I am running introspect:pg on my database in order to get the schema exported as usable references however I am noticing that while this works for tables, materialized views are not included.

Expected behavior

I expect my materialized view to be included in the generated schema. I assume this is a bug because there is clear support for views/mat views given that there is an export for pgMaterializedView and pgView from drizzle-orm/pg-core.

Environment & setup

I am connecting to postgres and trying to generate a schema file from an existing database which includes a materialized view.

It should be irrelevant but my database is Timescaledb (postgres under the hood) and the materialized view in question is a vanilla postgres mat view and NOT the timescale continous aggregate view feature.

Table:

create table public.stock_split (
  dt date not null,
  symbol text not null,
  "from" integer not null,
  "to" integer not null,
  primary key (dt, symbol)
);

Materialized View:

create materialized view public.stock_split_realized as
SELECT a.dt,
       a.symbol,
       exp(sum(ln(b."to"::numeric / b."from"::numeric))) AS denominator
FROM stock_split a
         JOIN stock_split b ON a.symbol = b.symbol AND a.dt <= b.dt
GROUP BY a.dt, a.symbol;

juanjalvarez avatar Jan 12 '24 05:01 juanjalvarez

hey @juanjalvarez considering using timescaledb with drizzle as well. How is your experience so far?

iamcrisb avatar Jan 20 '24 10:01 iamcrisb

In the docs they mention that it's not yet supported by drizzle-kit. If you go to the top of the views page, you will see this message: image

rami-maalouf avatar Feb 02 '24 15:02 rami-maalouf

We are working on adding it to drizzle-kit. You can track it here: https://github.com/drizzle-team/drizzle-orm/issues/1856

AndriiSherman avatar Feb 03 '24 19:02 AndriiSherman

@juanjalvarez @iamcrisb did you try using drizzle with timescaledb? I am considering drizzle myself and I am in process of choosing orm for my project. Thanks

tonven avatar Aug 12 '24 11:08 tonven

hey @tonven you won't find any orm that supports timescale, regardless of the orm you'll have to write sql, so drizzle is as good of choice as anything else.

iamcrisb avatar Aug 16 '24 15:08 iamcrisb