Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/e2e/orm/client-api/pg-computed-multischema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { createTestClient } from '@zenstackhq/testtools';
import { describe, expect, it } from 'vitest';

describe('Postgres multi-schema with computed fields', () => {
it('supports computed fields on models in custom schemas', async () => {
const db = await createTestClient(
`
datasource db {
provider = "postgresql"
url = '$DB_URL'
schemas = ["public", "mySchema1", "mySchema2"]
}

model Author {
id Int @id @default(autoincrement())
name String
books Book[]
@@schema("mySchema1")
}

model Book {
id Int @id @default(autoincrement())
title String
authorId Int
author Author @relation(fields: [authorId], references: [id])
authorName String @computed()
@@schema("mySchema2")
}
`,
{
provider: 'postgresql',
usePrismaPush: true,
computedFields: {
Book: {
authorName: (eb: any) => eb
.selectFrom('mySchema1.Author')
.select('Author.name')
.whereRef('Author.id', '=', 'authorId')
.limit(1)
},
},
} as any
);

// Create author and book
const author = await db.author.create({ data: { name: 'Jane Doe' } });
const book = await db.book.create({ data: { title: 'ZenStack Guide', authorId: author.id } });

// Fetch book and check computed field
const fetched = await db.book.findUnique({ where: { id: book.id } });
expect(fetched?.authorName).toBe('Jane Doe');
});
});
Loading