P
Prisma3d ago
Helix

Two Schemas but only one will stay generated at a time

Title is pretty explanatory. I have two schemas for different databases but I can run generate for one schema and then the other schema starts to have error lines in vscode, then generating the other schema swaps the errors to the first schema. Any way to fix this it’s pretty annoying.
4 Replies
Helix
HelixOP3d ago
import { PrismaClient } from "@prisma/client";

import { env } from "@/env";
const createPrismaClient = (url: string) =>
new PrismaClient({
log:
env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
datasources: {
db: {
url: url,
},
},
});

const globalForPrisma = globalThis as unknown as {
prisma: ReturnType<typeof createPrismaClient> | undefined;
};

export const aero_db =
globalForPrisma.prisma ?? createPrismaClient(env.DATABASE_URL);
export const alec_site_db = createPrismaClient(env.ALEC_SITE_DB_URL);

if (env.NODE_ENV !== "production") globalForPrisma.prisma = aero_db;
import { PrismaClient } from "@prisma/client";

import { env } from "@/env";
const createPrismaClient = (url: string) =>
new PrismaClient({
log:
env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
datasources: {
db: {
url: url,
},
},
});

const globalForPrisma = globalThis as unknown as {
prisma: ReturnType<typeof createPrismaClient> | undefined;
};

export const aero_db =
globalForPrisma.prisma ?? createPrismaClient(env.DATABASE_URL);
export const alec_site_db = createPrismaClient(env.ALEC_SITE_DB_URL);

if (env.NODE_ENV !== "production") globalForPrisma.prisma = aero_db;
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
output = "../node_modules/@internal/prisma-second/client"
}

datasource db {
provider = "mysql"
url = env("ALEC_SITE_DB_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
output = "../node_modules/@internal/prisma-second/client"
}

datasource db {
provider = "mysql"
url = env("ALEC_SITE_DB_URL")
}
Nurul
Nurul3d ago
Hello @Helix 👋 Can you try providing custom output path for both of your schemas and check if you still get the same error? Also, what error do you get? Can you also share your use case? Does having two generated Prisma Clients cause an issue? https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path
Generating Prisma Client | Prisma Documentation
This page explains how to generate Prisma Client. It also provides additional context on the generated client, typical workflows and Node.js configuration.
Helix
HelixOP2d ago
// schema1.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
output = "../node_modules/@internal/prisma-first/client"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

// schema2.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
output = "../node_modules/@internal/prisma-second/client"
}

datasource db {
provider = "mysql"
url = env("ALEC_SITE_DB_URL")
}
// schema1.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
output = "../node_modules/@internal/prisma-first/client"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

// schema2.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "prismaSchemaFolder", "multiSchema"]
output = "../node_modules/@internal/prisma-second/client"
}

datasource db {
provider = "mysql"
url = env("ALEC_SITE_DB_URL")
}
I have two different database schemas one called aero and one called alec_site that I'm trying to connect to, aero contains the user data & app specific data where alec_site contains other data that I need. I'm not getting any specific errors besides Property 'vendor_id_walmart' does not exist on type 'PrismaClient<{ datasources: { db: { url: string; }; }; }, never, DefaultArgs>'. for the alec_site db.
export const aero_db = new PrismaClient({
datasources: { db: { url: env.DATABASE_URL } },
});
export const alec_site_db = new PrismaClient({
datasources: { db: { url: env.ALEC_SITE_DB_URL } },
});
export const aero_db = new PrismaClient({
datasources: { db: { url: env.DATABASE_URL } },
});
export const alec_site_db = new PrismaClient({
datasources: { db: { url: env.ALEC_SITE_DB_URL } },
});
this is the prisma clients I figured it out!
Nurul
Nurul2d ago
I am glad to hear that you figured out the solution. What was the fix which worked for you?
Want results from more Discord servers?
Add your server