Skip to content

Commit

Permalink
Fix migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed May 6, 2024
1 parent 0232fe3 commit 30b3f9e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/prisma-client/migrations-cli/prisma-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,31 @@ export const generateMigrationName = (baseName: string) => {
};

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

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

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

// https://www.prisma.io/docs/reference/api-reference/command-reference#generate
await $`prisma generate --schema ${schemaPath}`;
await $({
cwd: prismaDir,
})`prisma generate --schema ${schemaPath}`;
};

0 comments on commit 30b3f9e

Please sign in to comment.