Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"change-case": "^5.4.4",
"deepmerge": "^4.3.1",
"env-paths": "^3.0.0",
"execa": "^7.2.0",
"p-limit": "^4.0.0",
"parse5": "7.1.2",
"picocolors": "^1.1.0",
"strip-indent": "^4.0.0",
"tinyexec": "^0.3.1",
"yargs": "^17.7.2",
"zod": "^3.22.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init-flow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { chdir, cwd } from "node:process";
import { join } from "node:path";
import pc from "picocolors";
import { x } from "tinyexec";
import {
cancel,
confirm,
Expand All @@ -10,7 +11,6 @@ import {
spinner,
text,
} from "@clack/prompts";
import { $ } from "execa";
import { createFolderIfNotExists, isFileExists } from "../fs-utils";
import { PROJECT_TEMPLATES } from "../config";
import { link, validateShareLink } from "./link";
Expand Down Expand Up @@ -112,7 +112,7 @@ export const initFlow = async (
if (shouldInstallDeps === true) {
const install = spinner();
install.start("Installing dependencies");
await $`npm install`;
await x("npm", ["install"]);
install.stop("Installed dependencies");
}

Expand Down
6 changes: 0 additions & 6 deletions packages/prisma-client/migrations-cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Commands:
create-schema <name> — Create a migration based on the changes in schema.prisma
create-data <name> — Create a migration that will change data rather than schema
migrate — Apply all pending migrations
reset — Clear the database and apply all migrations
status — Information about the state of the migrations
pending-count — Get the number of pending migrations
resolve <applied|rolled-back> <name> — Mark a failed migration as applied or rolled-back
Expand Down Expand Up @@ -102,11 +101,6 @@ const main = async () => {
return;
}

if (command === "reset") {
await commands.reset();
return;
}

throw new UserError(`Unknown command: ${command}`);
};

Expand Down
13 changes: 0 additions & 13 deletions packages/prisma-client/migrations-cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,3 @@ export const resolve = async ({
logger.info(`Resolved ${migrationName} as rolled back`);
logger.info("");
};

export const reset = async () => {
// Just to make it read the migrations folder
// and fail early if something is wrong with it.
await getStatus();

logger.info("You're about to DELETE ALL INFORMATION from the database,");
logger.info("and run all migrations from scratch!");
logger.info("");

await prismaMigrations.resetDatabase();
await up();
};
47 changes: 24 additions & 23 deletions packages/prisma-client/migrations-cli/prisma-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// We want to preserve semantics of the migrations folder and the _prisma_migrations table.
// https://github.com/prisma/prisma-engines/blob/4.3.0/migration-engine/ARCHITECTURE.md

import { $ } from "execa";
import path from "node:path";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import { createHash } from "node:crypto";
import { x } from "tinyexec";
import { createPrisma } from "../src/prisma";
import { UserError } from "./errors";
import { PrismaClient } from "../src/__generated__";
Expand Down Expand Up @@ -248,32 +248,33 @@ export const generateMigrationName = (baseName: string) => {
return `${prefix}_${baseName}`.slice(0, 254);
};

export const resetDatabase = async () => {
const { stdout: sqlToDeleteEverything } = await $({
cwd: prismaDir,
})`"prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-empty --script`;

await $({
input: sqlToDeleteEverything,
cwd: prismaDir,
})`prisma db execute --stdin --schema ${schemaFilePath}`;

await context.prisma.$executeRaw`DROP TABLE IF EXISTS _prisma_migrations`;
};

// https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff
export const cliDiff = async () => {
const { stdout } = await $({
cwd: prismaDir,
})`prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-schema-datamodel ${schemaFilePath} --script`;
const { stdout } = await x(
"prisma",
[
"migrate",
"diff",
`--from-schema-datasource=${schemaFilePath}`,
`--to-schema-datamodel=${schemaFilePath}`,
"--script",
],
{
nodeOptions: { cwd: prismaDir },
}
);
return stdout;
};

// https://www.prisma.io/docs/reference/api-reference/command-reference#db-execute
export const cliExecute = async (filePath: string) => {
await $({
cwd: prismaDir,
})`prisma db execute --file ${filePath} --schema ${schemaFilePath}`;
await x(
"prisma",
["db", "execute", `--file=${filePath}`, `--schema=${schemaFilePath}`],
{
nodeOptions: { cwd: prismaDir },
}
);
};

export const generateMigrationClient = async (migrationName: string) => {
Expand All @@ -297,7 +298,7 @@ export const generateMigrationClient = async (migrationName: string) => {
}

// https://www.prisma.io/docs/reference/api-reference/command-reference#generate
await $({
cwd: prismaDir,
})`prisma generate --schema ${schemaPath}`;
await x("prisma", ["generate", `--schema=${schemaPath}`], {
nodeOptions: { cwd: prismaDir },
});
};
3 changes: 1 addition & 2 deletions packages/prisma-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"license": "AGPL-3.0-or-later",
"private": true,
"dependencies": {
"execa": "^7.2.0",
"nanoid": "^5.0.1",
"tinyexec": "^0.3.1",
"umzug": "^3.2.1"
},
"peerDependencies": {
Expand Down
82 changes: 11 additions & 71 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.