mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
feat(cli): Upgrade to Prisma 6.13.0 (#431)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import path from "node:path";
|
||||
import { cancel, isCancel, log, select, spinner, text } from "@clack/prompts";
|
||||
import { cancel, isCancel, log, select, text } from "@clack/prompts";
|
||||
import { consola } from "consola";
|
||||
import { execa } from "execa";
|
||||
import fs from "fs-extra";
|
||||
@@ -23,7 +23,7 @@ async function setupWithCreateDb(
|
||||
) {
|
||||
try {
|
||||
log.info(
|
||||
"Starting Prisma PostgreSQL setup. Please follow the instructions below:",
|
||||
"Starting Prisma Postgres setup. Please follow the instructions below:",
|
||||
);
|
||||
|
||||
const createDbCommand = getPackageExecutionCommand(
|
||||
@@ -149,6 +149,20 @@ async function writeEnvFile(projectDir: string, config?: PrismaConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
async function addDotenvImportToPrismaConfig(projectDir: string) {
|
||||
try {
|
||||
const prismaConfigPath = path.join(
|
||||
projectDir,
|
||||
"apps/server/prisma.config.ts",
|
||||
);
|
||||
let content = await fs.readFile(prismaConfigPath, "utf8");
|
||||
content = `import "dotenv/config";\n${content}`;
|
||||
await fs.writeFile(prismaConfigPath, content);
|
||||
} catch (_error) {
|
||||
consola.error("Failed to update prisma.config.ts");
|
||||
}
|
||||
}
|
||||
|
||||
function displayManualSetupInstructions() {
|
||||
log.info(`Manual Prisma PostgreSQL Setup Instructions:
|
||||
|
||||
@@ -226,7 +240,7 @@ export async function setupPrismaPostgres(config: ProjectConfig) {
|
||||
}
|
||||
|
||||
const setupMethod = await select({
|
||||
message: "Choose your Prisma setup method:",
|
||||
message: "Choose your Prisma Postgres setup method:",
|
||||
options: setupOptions,
|
||||
initialValue: "create-db",
|
||||
});
|
||||
@@ -246,28 +260,23 @@ export async function setupPrismaPostgres(config: ProjectConfig) {
|
||||
|
||||
if (prismaConfig) {
|
||||
await writeEnvFile(projectDir, prismaConfig);
|
||||
|
||||
await addDotenvImportToPrismaConfig(projectDir);
|
||||
|
||||
if (orm === "prisma") {
|
||||
await addPrismaAccelerateExtension(serverDir);
|
||||
log.info(
|
||||
pc.cyan(
|
||||
'NOTE: Make sure to uncomment `import "dotenv/config";` in `apps/server/src/prisma.config.ts` to load environment variables.',
|
||||
),
|
||||
);
|
||||
}
|
||||
log.success(
|
||||
pc.green("Prisma PostgreSQL database configured successfully!"),
|
||||
pc.green("Prisma Postgres database configured successfully!"),
|
||||
);
|
||||
} else {
|
||||
const fallbackSpinner = spinner();
|
||||
fallbackSpinner.start("Setting up fallback configuration...");
|
||||
await writeEnvFile(projectDir);
|
||||
fallbackSpinner.stop("Fallback configuration ready");
|
||||
displayManualSetupInstructions();
|
||||
}
|
||||
} catch (error) {
|
||||
consola.error(
|
||||
pc.red(
|
||||
`Error during Prisma PostgreSQL setup: ${
|
||||
`Error during Prisma Postgres setup: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
),
|
||||
|
||||
@@ -253,7 +253,7 @@ async function getDatabaseInstructions(
|
||||
}
|
||||
|
||||
if (orm === "prisma") {
|
||||
if (database === "sqlite") {
|
||||
if (dbSetup === "turso") {
|
||||
instructions.push(
|
||||
`${pc.yellow(
|
||||
"NOTE:",
|
||||
@@ -262,13 +262,6 @@ async function getDatabaseInstructions(
|
||||
);
|
||||
}
|
||||
|
||||
if (runtime === "bun") {
|
||||
instructions.push(
|
||||
`${pc.yellow(
|
||||
"NOTE:",
|
||||
)} Prisma with Bun may require additional configuration. If you encounter errors,\nfollow the guidance provided in the error messages`,
|
||||
);
|
||||
}
|
||||
if (database === "mongodb" && dbSetup === "docker") {
|
||||
instructions.push(
|
||||
`${pc.yellow(
|
||||
|
||||
@@ -248,9 +248,9 @@ async function updateServerPackageJson(
|
||||
}
|
||||
|
||||
if (options.orm === "prisma") {
|
||||
scripts["db:push"] = "prisma db push --schema ./prisma/schema";
|
||||
scripts["db:push"] = "prisma db push";
|
||||
scripts["db:studio"] = "prisma studio";
|
||||
scripts["db:generate"] = "prisma generate --schema ./prisma/schema";
|
||||
scripts["db:generate"] = "prisma generate";
|
||||
scripts["db:migrate"] = "prisma migrate dev";
|
||||
} else if (options.orm === "drizzle") {
|
||||
scripts["db:push"] = "drizzle-kit push";
|
||||
|
||||
Reference in New Issue
Block a user