Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add confirmations

Roman Pominovff7a028bd9e3
diff --git a/packages/prisma-client/migrations-cli/commands.ts b/packages/prisma-client/migrations-cli/commands.ts
index c4aae803da..e24afbefdd 100644
--- a/packages/prisma-client/migrations-cli/commands.ts
+++ b/packages/prisma-client/migrations-cli/commands.ts
@@ -1,6 +1,7 @@
import { FileLocker, MigrationMeta } from "umzug";
import fs from "node:fs";
import path from "node:path";
+import * as readline from "node:readline";
import * as prismaMigrations from "./prisma-migrations";
import { umzug } from "./umzug";
import * as logger from "./logger";
@@ -12,6 +13,31 @@ const templateFilePath = path.join(
);
const lockfilePath = path.join(prismaMigrations.migrationsDir, "lockfile");
+const confirm = async (
+ message: string,
+ defaultResult = false
+): Promise<boolean> => {
+ // Not using `node:readline/promises` because it's experimental.
+ return new Promise((resolve) => {
+ const rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ });
+ rl.question(
+ `${message} ${defaultResult === true ? "(Y/n)" : "(y/N)"} `,
+ (answer) => {
+ rl.close();
+ const normalised = answer.toLowerCase().trim();
+ if (normalised === "") {
+ resolve(defaultResult);
+ return;
+ }
+ resolve(normalised === "y" || normalised === "yes");
+ }
+ );
+ });
+};
+
const failWith = (message: string) => {
logger.error(message);
logger.error("");
@@ -170,7 +196,7 @@ export const createData = async ({ name }: { name: string }) => {
let schemaContent = fs.readFileSync(prismaMigrations.schemaFilePath, "utf8");
schemaContent = `// DO NOT EDIT THIS FILE!
-// This a copy of your schema.prisma that corresponds to the state of the database
+// This is a copy of your schema.prisma that corresponds to the state of the database
// when all migrations up until this one are applied.
// It's used to generate a Prisma Client for the migration.
@@ -218,6 +244,19 @@ export const migrate = async () => {
process.exit(0);
}
+ logger.info("You're about to apply the following migration(s):");
+ logger.info("");
+
+ for (const migration of status.pending) {
+ logger.info(` - ${migration.name}`);
+ }
+
+ logger.info("");
+
+ if ((await confirm("Continue?", true)) === false) {
+ process.exit(0);
+ }
+
let locker: FileLocker | undefined;
if (args.dev) {
locker = new FileLocker({ path: lockfilePath });
@@ -307,6 +346,18 @@ export const resolve = async ({
);
}
+ logger.info(`You're about to mark ${migrationName} as ${resolveAs}.`);
+ logger.info("This will NOT automatically resolve any issues");
+ logger.info("that may have been caused by the failed run.");
+ logger.info(
+ "You should continue only if you're sure the issues have been resolved."
+ );
+ logger.info("");
+
+ if ((await confirm(`Continue?`)) === false) {
+ process.exit(0);
+ }
+
if (resolveAs === "applied") {
await prismaMigrations.setApplied(migrationName);
logger.info(`Resolved ${migrationName} as applied`);