Skip to content

Commit 054df8b

Browse files
authored
Merge pull request #654 from matthew-lim-matthew-lim/matthewlim/fix-table-creation
(Feat) Initialise table properly even if db file is corrupted.
2 parents eab34b1 + 75e090d commit 054df8b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

helpers/dbHelper.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ module.exports = {
1313
* already exist
1414
*/
1515
ensureDatabase: () => {
16-
const dbExists = fs.existsSync(dbFile);
1716
const db = new sqlite3.Database(dbFile);
1817
const createSubscriptionStatement =
19-
'CREATE TABLE Subscription (' +
18+
'CREATE TABLE IF NOT EXISTS Subscription (' +
2019
'SubscriptionId TEXT NOT NULL, ' +
2120
'UserAccountId TEXT NOT NULL' +
2221
')';
2322

2423
db.serialize(() => {
25-
if (!dbExists) {
26-
db.run(createSubscriptionStatement, (error) => {
27-
if (error) throw error;
28-
});
29-
}
24+
db.run(createSubscriptionStatement, (error) => {
25+
if (error) throw error;
26+
});
3027
});
3128

3229
db.close();

0 commit comments

Comments
 (0)