Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit c5ed543

Browse files
committed
test(cli): support datasource extras in test utils
Enhances the test utility helpers to allow passing extra datasource properties, such as multi-schema configurations for PostgreSQL. Refactors existing database pull tests to use these extra properties, ensuring the generated ZModel schema correctly reflects multi-schema environments while simplifying assertions.
1 parent 9dcf2ab commit c5ed543

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

packages/cli/test/db/pull.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ model Post {
353353
354354
@@schema("content")
355355
}`,
356-
{ provider: 'postgresql' },
356+
{ provider: 'postgresql', extra:{ schemas: ["public", "content", "auth"] } },
357357
);
358358
runCli('db push', workDir);
359359

@@ -366,8 +366,6 @@ model Post {
366366

367367
const restoredSchema = getSchema(workDir);
368368
expect(restoredSchema).toEqual(expectedSchema);
369-
expect(restoredSchema).toContain('@@schema("auth")');
370-
expect(restoredSchema).toContain('@@schema("content")');
371369
});
372370

373371
it('should preserve native PostgreSQL enums when schema exists', async ({ skip }) => {
@@ -404,8 +402,6 @@ enum UserRole {
404402
const pulledSchema = getSchema(workDir);
405403

406404
expect(pulledSchema).toEqual(originalSchema);
407-
expect(pulledSchema).toContain('enum UserStatus');
408-
expect(pulledSchema).toContain('enum UserRole');
409405
});
410406

411407
it('should not modify schema with PostgreSQL-specific features', async ({ skip }) => {
@@ -442,7 +438,7 @@ enum UserStatus {
442438
INACTIVE
443439
SUSPENDED
444440
}`,
445-
{ provider: 'postgresql' },
441+
{ provider: 'postgresql', extra:{ schemas: ["public", "content", "auth"] } },
446442
);
447443
runCli('db push', workDir);
448444

packages/cli/test/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getTestDbName(provider: string) {
4242
);
4343
}
4444

45-
export function getDefaultPrelude(options?: { provider?: 'sqlite' | 'postgresql' | 'mysql' }) {
45+
export function getDefaultPrelude(options?: { provider?: 'sqlite' | 'postgresql' | 'mysql', extra?: Record<string, string | string[]> }) {
4646
const provider = (options?.provider || getTestDbProvider()) ?? 'sqlite';
4747
const dbName = getTestDbName(provider);
4848
let dbUrl: string;
@@ -60,10 +60,10 @@ export function getDefaultPrelude(options?: { provider?: 'sqlite' | 'postgresql'
6060
default:
6161
throw new Error(`Unsupported provider: ${provider}`);
6262
}
63-
63+
const DATASOURCE_EXTRAS = Object.entries(options?.extra || {}).map(([k, v]) => ` ${k} = ${JSON.stringify(v)}`).join('\n');
6464
const ZMODEL_PRELUDE = `datasource db {
6565
provider = "${provider}"
66-
url = "${dbUrl}"
66+
url = "${dbUrl}"${DATASOURCE_EXTRAS.length > 0 ? '\n' + DATASOURCE_EXTRAS : ''}
6767
}`;
6868
return ZMODEL_PRELUDE;
6969
}
@@ -81,9 +81,9 @@ export function createProject(
8181

8282
export async function createFormattedProject(
8383
zmodel: string,
84-
options?: { provider?: 'sqlite' | 'postgresql' | 'mysql' },
84+
options?: { provider?: 'sqlite' | 'postgresql' | 'mysql', extra?: Record<string, string | string[]> },
8585
) {
86-
const fullContent = `${getDefaultPrelude({ provider: options?.provider })}\n\n${zmodel}`;
86+
const fullContent = `${getDefaultPrelude({ provider: options?.provider, extra: options?.extra })}\n\n${zmodel}`;
8787
const formatted = await formatDocument(fullContent);
8888
return createProject(formatted, { customPrelude: true, provider: options?.provider });
8989
}

0 commit comments

Comments
 (0)