Skip to content

Commit 2b1892c

Browse files
fix filterBySchema with defaultSchema
1 parent 3196428 commit 2b1892c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/generator.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ generatorHandler({
4848
options.dmmf.datamodel.models
4949
);
5050

51+
const hasMultiSchema = options.datasources.some(
52+
(d) => d.schemas.length > 0
53+
);
54+
5155
const multiSchemaMap =
52-
config.groupBySchema ||
53-
options.generator.previewFeatures?.includes("multiSchema")
56+
config.groupBySchema || hasMultiSchema
5457
? parseMultiSchemaMap(options.datamodel)
5558
: undefined;
5659

@@ -69,10 +72,7 @@ generatorHandler({
6972
);
7073

7174
// Extend model table names with schema names if using multi-schemas
72-
if (
73-
options.generator.previewFeatures?.includes("multiSchema") ||
74-
options.datasources.some((d) => d.schemas.length > 0)
75-
) {
75+
if (hasMultiSchema) {
7676
const filterBySchema = config.filterBySchema
7777
? new Set(config.filterBySchema)
7878
: null;

src/helpers/multiSchemaHelpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const convertToMultiSchemaModels = <const T extends ModelLike>(
2828
return models.flatMap((model) => {
2929
const schemaName = multiSchemaMap?.get(model.typeName);
3030

31-
if (!schemaName || schemaName === defaultSchema) {
31+
if (!schemaName) {
3232
return model;
3333
}
3434

@@ -37,6 +37,11 @@ export const convertToMultiSchemaModels = <const T extends ModelLike>(
3737
return [];
3838
}
3939

40+
// If the schema is the default schema, we don't need to modify the model
41+
if (schemaName === defaultSchema) {
42+
return model;
43+
}
44+
4045
return [
4146
{
4247
...model,

0 commit comments

Comments
 (0)