Skip to content

Commit 0aad7ea

Browse files
committed
fix: re-create database in the test environment
1 parent 98c6b54 commit 0aad7ea

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/application.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class BookkeepingApplication {
4848
async run() {
4949
try {
5050
await this.database.connect();
51+
52+
if (this.isInTestMode()) {
53+
await this.database.dropAllTables();
54+
}
55+
5156
await this.database.migrate();
5257

5358
if (this.isInTestMode()) {

lib/database/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class SequelizeDatabase {
8282
return this.sequelize.close();
8383
}
8484

85+
/**
86+
* Drops all tables.
87+
*
88+
* @returns {Promise} Promise object represents the outcome.
89+
*/
90+
async dropAllTables() {
91+
return this.sequelize.getQueryInterface().dropAllTables();
92+
}
93+
8594
/**
8695
* Executes every *pending* migrations.
8796
*

0 commit comments

Comments
 (0)