Skip to content

Commit

Permalink
fix: correctly empty dirs before copy
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Mar 7, 2024
1 parent 2b0f9bf commit e43597e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/migrate/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Wrapper around `prisma migrate dev`

import { assert, copy, exists, resolve } from "../deps.ts";
import { assert, copy, emptyDir, exists, resolve } from "../deps.ts";
import { Module, Project } from "../project/mod.ts";
import { forEachPrismaSchema } from "./mod.ts";

Expand Down Expand Up @@ -50,8 +50,13 @@ export async function migrateDev(
// `sourcePath` (which is the original module's source)
const tempMigrationsDir = resolve(tempDir, "migrations");
if (await exists(tempMigrationsDir)) {
await copy(tempMigrationsDir, resolve(module.path, "db", "migrations"), { overwrite: true });
await copy(tempMigrationsDir, resolve(module.sourcePath, "db", "migrations"), { overwrite: true });
const migrationsDir = resolve(module.path, "db", "migrations");
await emptyDir(migrationsDir);
await copy(tempMigrationsDir, migrationsDir, { overwrite: true });

const sourceMigrationsDir = resolve(module.sourcePath, "db", "migrations");
await emptyDir(sourceMigrationsDir);
await copy(tempMigrationsDir, sourceMigrationsDir, { overwrite: true });
}
},
);
Expand Down
4 changes: 2 additions & 2 deletions src/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy, dirname, exists, resolve } from "../deps.ts";
import { copy, emptyDir, exists, resolve } from "../deps.ts";
import { bold, brightRed, glob } from "./deps.ts";
import { readConfig as readProjectConfig } from "../config/project.ts";
import { ProjectConfig } from "../config/project.ts";
Expand Down Expand Up @@ -187,7 +187,7 @@ async function fetchAndResolveModule(
"modules",
moduleName,
);
await Deno.mkdir(dirname(dstPath), { recursive: true });
await emptyDir(dstPath);
await copy(modulePath, dstPath, { overwrite: true });

return { genPath: dstPath, sourcePath: modulePath, registry };
Expand Down

0 comments on commit e43597e

Please sign in to comment.