( factory: FumaDBFactory<Schemas>, version: Version, provider: Exclude<Provider, "mongodb">, )
| 217 | |
| 218 | const prismaDir = path.join(import.meta.dirname, "../node_modules/_prisma"); |
| 219 | export async function initPrismaClient< |
| 220 | Schemas extends AnySchema[], |
| 221 | Version extends Schemas[number]["version"], |
| 222 | >( |
| 223 | factory: FumaDBFactory<Schemas>, |
| 224 | version: Version, |
| 225 | provider: Exclude<Provider, "mongodb">, |
| 226 | ): Promise<FumaDB<Schemas>> { |
| 227 | fs.mkdirSync(prismaDir, { recursive: true }); |
| 228 | const hash = Date.now(); |
| 229 | const schemaPath = path.join( |
| 230 | prismaDir, |
| 231 | `schema-${hash}.${version}.${provider}.prisma`, |
| 232 | ); |
| 233 | const db = databases.find((str) => str.provider === provider)!; |
| 234 | const clientPath = path.join( |
| 235 | prismaDir, |
| 236 | `client-${hash}-${version}-${provider}`, |
| 237 | ); |
| 238 | |
| 239 | const schema = factory |
| 240 | .client( |
| 241 | prismaAdapter({ |
| 242 | prisma: {}, |
| 243 | provider, |
| 244 | }), |
| 245 | ) |
| 246 | .generateSchema(version); |
| 247 | |
| 248 | schema.path = schemaPath; |
| 249 | schema.code += `\ndatasource db { |
| 250 | provider = "${provider}" |
| 251 | } |
| 252 | |
| 253 | generator client { |
| 254 | provider = "prisma-client" |
| 255 | output = "${clientPath}" |
| 256 | }`; |
| 257 | |
| 258 | fs.writeFileSync(schema.path, schema.code); |
| 259 | const env = { |
| 260 | ...process.env, |
| 261 | DATABASE_URL: db.url, |
| 262 | PRISMA_SCHEMA: schemaPath, |
| 263 | }; |
| 264 | |
| 265 | // Push schema to database |
| 266 | await x( |
| 267 | "node", |
| 268 | [ |
| 269 | "node_modules/prisma/build/index.js", |
| 270 | "db", |
| 271 | "push", |
| 272 | "--force-reset", |
| 273 | "--accept-data-loss", |
| 274 | ], |
| 275 | { |
| 276 | nodeOptions: { |
no test coverage detected