Open jog1t opened 2 months ago
To resolve the issue of creating a module without a defined DB model, follow these steps:
schema.prisma
file to include a default model if none are defined. This can be done in the runPrismaCommand
function in /src/migrate/prisma.ts
.// Append generator config
const schemaPath = resolve(dbDir, "schema.prisma");
let schema = await Deno.readTextFile(schemaPath);
// Check if schema contains any model definitions
if (!/model\s+\w+\s+\{/.test(schema)) {
schema += dedent`
model DefaultModel {
id Int @id @default(autoincrement())
name String?
}
`;
}
schema += dedent`
// Generated by Open Game Backend
generator client {
provider = "prisma-client-js"
output = "${dbDir}/client"
previewFeatures = ["driverAdapters"]
}
`;
await Deno.writeTextFile(schemaPath, schema);
This will ensure that a default model is added to the schema.prisma
file if no models are defined, preventing Prisma from throwing an error.
/src/runtime/runtime.ts /tests/basic/modules/foo/db/schema.prisma /src/migrate/prisma.ts /src/migrate/generate.ts /src/cli/commands/db.ts
@kacper said:
Steps to reproduce:
opengb create script my_module
opengb create script my_module test
opengb dev
You should see the following error: