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 resolve

Roman Pominove88c9b10350c
diff --git a/packages/prisma-client/migrations-cli/cli.ts b/packages/prisma-client/migrations-cli/cli.ts
index 571b3d43f2..7a3014286e 100755
--- a/packages/prisma-client/migrations-cli/cli.ts
+++ b/packages/prisma-client/migrations-cli/cli.ts
@@ -19,7 +19,7 @@ Commands:
migrate — Apply all pending migrations
reset — Clear the database and apply all migrations
status — Information about the state of the migrations
- resolve — Mark a failed migration as applied or rolled-back
+ resolve <applied|rolled-back> <name> — Mark a failed migration as applied or rolled-back
Arguments
--dev — Lets the CLI know that it's running in a development environment
@@ -71,6 +71,38 @@ const main = async () => {
return;
}
+ if (command === "resolve") {
+ // @todo: confirmation prompt
+
+ const type = args._[1];
+
+ if (type === undefined || (type !== "applied" && type !== "rolled-back")) {
+ failWith(
+ "Missing type of resolve.\nUsage: migrations resolve <applied|rolled-back> <migration-name>"
+ );
+ return;
+ }
+
+ const name = args._[2];
+ if (name === undefined) {
+ failWith(
+ "Missing name of migration.\nUsage: migrations resolve <applied|rolled-back> <migration-name>"
+ );
+ return;
+ }
+
+ await commands.resolve({ migrationName: name, resolveAs: type });
+ return;
+ }
+
+ if (command === "reset") {
+ // @todo: confirmation prompt
+ // @todo: allow only in dev mode
+
+ // @todo
+ throw new Error("Not implemented");
+ }
+
failWith(`Unknown command: ${command}`);
};
diff --git a/packages/prisma-client/migrations-cli/commands.ts b/packages/prisma-client/migrations-cli/commands.ts
index e16b3ed983..c4aae803da 100644
--- a/packages/prisma-client/migrations-cli/commands.ts
+++ b/packages/prisma-client/migrations-cli/commands.ts
@@ -284,3 +284,37 @@ export const status = async () => {
logger.info("");
};
+
+// Silimar to https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-resolve
+export const resolve = async ({
+ migrationName,
+ resolveAs,
+}: {
+ migrationName: string;
+ resolveAs: "applied" | "rolled-back";
+}) => {
+ const status = await getStatus();
+
+ const failed = status.started.filter((m) => m.state === "failed");
+
+ if (
+ failed.some(
+ ({ migration }) => migration.migration_name === migrationName
+ ) === false
+ ) {
+ failWith(
+ `Migration ${migrationName} is not failed. You can resolve only a failed migration.`
+ );
+ }
+
+ if (resolveAs === "applied") {
+ await prismaMigrations.setApplied(migrationName);
+ logger.info(`Resolved ${migrationName} as applied`);
+ logger.info("");
+ return;
+ }
+
+ await prismaMigrations.setRolledBack(migrationName);
+ logger.info(`Resolved ${migrationName} as rolled back`);
+ logger.info("");
+};
diff --git a/packages/prisma-client/migrations-cli/prisma-migrations.ts b/packages/prisma-client/migrations-cli/prisma-migrations.ts
index 5fd88acb75..74b1945267 100644
--- a/packages/prisma-client/migrations-cli/prisma-migrations.ts
+++ b/packages/prisma-client/migrations-cli/prisma-migrations.ts
@@ -190,7 +190,8 @@ export const setRolledBack = async (migrationName: string) => {
);
}
- await prisma.$executeRaw`update _prisma_migrations set rolled_back_at = now()`;
+ await prisma.$executeRaw`update _prisma_migrations set rolled_back_at = now()
+ where migration_name = ${migrationName}`;
};
// https://github.com/prisma/prisma-engines/blob/88f6ab88e559ef52ab26bc98f1da15200e0c25b4/migration-engine/core/src/commands/diagnose_migration_history.rs#L109-L111