New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introspection can't get composite primary key for partitioned table #10870
Comments
Here is a related feature request: #1708
Can you explain what this means please? |
@janpio take a look at the generated schema.prisma: |
I saw #1708 but it's mostly about how to describe partitions in schema.prisma. I was curious to see if Prisma is can be used with partitioned tables at least in introspection mode |
No, not out of the box - that is exactly what issue #1708 is about. The problem for what you are observing is probably that the database does not actually return a representation of the primary key on the You can possibly modify the |
It could be a workaround but since I'd have to modify Thank you |
Sooner or later, yes - see #1708. But currently it is not very high on the list at the moment. (Doesn't mean it could not just happen in the next few months) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
We have adopted prisma in a very large postgres database that syncs integration data and want to partition some tables. I'd be very excited to have a way (even if suboptimal) to achieve partitioning. We already write many manual migrations that cannot be expressed in prisma as it is. I don't mind doing that for partitions, but the composite key issue is a blocker. |
@MikeYermolayev It has been some while, but maybe you are still around and working with the same database: generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model blocks_p2_0 {
id String @db.Uuid
account String
block_source_id String? @db.Uuid
@@id([account, id])
}
model blocks_p2_1 {
id String @db.Uuid
account String
block_source_id String? @db.Uuid
@@id([account, id])
} CREATE TABLE IF NOT EXISTS public.blocks
(
id uuid NOT NULL,
account text COLLATE pg_catalog."default" NOT NULL,
block_source_id uuid,
CONSTRAINT blocks_pkey PRIMARY KEY (account, id)
) PARTITION BY HASH (account);
CREATE TABLE public.blocks_p2_0 PARTITION OF public.blocks
FOR VALUES WITH (modulus 2, remainder 0);
CREATE TABLE public.blocks_p2_1 PARTITION OF public.blocks
FOR VALUES WITH (modulus 2, remainder 1);
ALTER TABLE public.blocks
ADD CONSTRAINT block_source_block_fk FOREIGN KEY (block_source_id, account)
REFERENCES public.blocks (id, account) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE So Prisma does not pick up the main table, but picks up only the 2 partitions. Is it possible that Prisma changed in this regard? |
Ok, I went back and tried again (as I should have initially) with the Prisma version 3.7.0 that @MikeYermolayev mentioned above, and I can now indeed reproduce the problem you are describing: Prisma is picking up the main table, but not its composite primary key. Today in Prisam 4.8.1 it looks to me now after trying these both reproductions that Prisma in general can not pick up the main table when it is partitioned at all, but only picks up the partitions itself (and then sometimes does a bad job working with that, see #17348). So technically this issue is not valid any more, and got worse in that Prisma does not pick up the main table any more at all. |
This issue took what Prisma brokenly introspected (with missing composite primary key) for the table, and tried to fix it. But is this even how a partitioned table should be represented in Prisma schema? I asked in our feature request issue and would welcome your responses: #1708 (comment) |
oh, I'm sorry but I don't longer have this database around and I haven't touched prisma for a while (( |
Release 4.10.0 later today will improve Introspection of partitioned tables for PostgreSQL and MySQL. Only the main table will be represented in the Prisma Schema, but cleanly and in a way that Prisma can handle and that should not break any other CLI commands. We explicitly tested this with the SQL @MikeYermolayev provided - so this should be good now. For full support of partitioned tables, please follow and subscribe to #1708 |
Bug description
Hello 馃憢馃徎
I'm trying to add Prisma to existing project and it fails on introspection step.
We have partitioned table with composite keys and prisma can't understand what primary key is in the original table. The fun fact is that it successfully introspected the same primary key for partitions themselves.
Blocks, comments and reactions are tables with partitions
How to reproduce
blocks
table:npx prisma db pull
Expected behavior
Primary key should be introspected correctly for partitioned table. Now it prevents me from using Prisma completely since I can't generate a client
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: