Skip to content

Commit 3cbd6cc

Browse files
committed
Added functionality to run a reset.sql that resets the database
1 parent c47a8df commit 3cbd6cc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/commands/seed.command.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,25 @@ export default async function (seedName?: string, resetOption?: boolean) {
1515
console.error(`${seedName}.sql does not exist!`);
1616
process.exit(1);
1717
}
18-
await confirmation(`${seedName}.sql`);
18+
const resetFilePath = `${rootDirectory}/${seedDirectory}/reset.sql`;
19+
if (!fsSync.existsSync(resetFilePath) && resetOption) {
20+
console.error(`reset.sql does not exist!`);
21+
process.exit(1);
22+
}
23+
if (resetOption) {
24+
await confirmation([`${seedName}.sql`, 'reset.sql']);
25+
} else {
26+
await confirmation(`${seedName}.sql`);
27+
}
28+
if(resetOption) {
29+
const seed = await fs.readFile(resetFilePath, 'utf-8');
30+
await pool.query(seed);
31+
}
1932
const seed = await fs.readFile(seedFilePath, 'utf-8');
2033
await pool.query(seed);
34+
if(resetOption) {
35+
console.log(`\nDatabase truncated\n`);
36+
}
2137
console.log(`\nDatabase seeded\n`);
2238
pool.end();
2339
} else {

0 commit comments

Comments
 (0)