Skip to content

Commit

Permalink
fix: seedDatabase method in DatabaseManager.ts condition only trigger…
Browse files Browse the repository at this point in the history
…s if needs collection is empty
  • Loading branch information
maxitect committed Dec 17, 2024
1 parent 5627786 commit d957a75
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/lib/db/DatabaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DatabaseManager {
"needs",
"next_actions",
];

const existingCollections = Object.keys(dbInstance.collections);

for (const collection of requiredCollections) {
Expand Down Expand Up @@ -76,15 +76,20 @@ class DatabaseManager {
}

private async seedDatabase() {
try {
await this.seed("mood_records", generateMoodRecords("dev"));
await this.seed("categories", categories);
await this.seed("toolkit_items", toolkit);
await this.seed("needs_categories", needsCategories);
await this.seed("needs", needs);
await this.seed("next_actions", nextActions);
} catch (error) {
console.error("Error during database seeding:", error);
if (
dbInstance &&
(await dbInstance.collections["needs"].find().exec()).length === 0
) {
try {
await this.seed("mood_records", generateMoodRecords("dev"));
await this.seed("categories", categories);
await this.seed("toolkit_items", toolkit);
await this.seed("needs_categories", needsCategories);
await this.seed("needs", needs);
await this.seed("next_actions", nextActions);
} catch (error) {
console.error("Error during database seeding:", error);
}
}
}

Expand Down

0 comments on commit d957a75

Please sign in to comment.