Skip to content

Commit

Permalink
add truncate tables
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjam committed Dec 7, 2023
1 parent 33a89cd commit cb4b8d2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions prisma/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ class SeedSingleton {

async handledDeleteAllTables() {
try {
await this.deleteAllTables();
// await this.deleteAllTables();
await this.truncateAllTables();
} catch (error) {
console.error('Handled delete tables error:', error);
}
Expand All @@ -189,6 +190,18 @@ class SeedSingleton {
console.log('Tables deleted.');
}

async truncateAllTables() {
console.log('Truncating tables ...');
await this.prisma.$transaction([
this.prisma.$executeRaw('TRUNCATE TABLE posts RESTART IDENTITY CASCADE;'),
this.prisma.$executeRaw('TRUNCATE TABLE accounts RESTART IDENTITY CASCADE;'),
this.prisma.$executeRaw('TRUNCATE TABLE sessions RESTART IDENTITY CASCADE;'),
this.prisma.$executeRaw('TRUNCATE TABLE verificationtokens RESTART IDENTITY CASCADE;'),
this.prisma.$executeRaw('TRUNCATE TABLE users RESTART IDENTITY CASCADE;'),
]);
console.log('Tables Truncated.');
}

// just require file, or fn will be called 2 times
// without exception handling here
async seed() {
Expand All @@ -199,7 +212,8 @@ class SeedSingleton {

await deleteAllAvatars();
await deleteAllHeaderImages();
await this.deleteAllTables();
// await this.deleteAllTables();
await this.truncateAllTables();

const users = createUsers(numberOfUsers);

Expand Down

0 comments on commit cb4b8d2

Please sign in to comment.