feat: add settings table and backup notification functionality
This commit is contained in:
@@ -19,6 +19,27 @@ fs.copyFileSync(dbPath, backupPath);
|
||||
|
||||
console.log(`✅ Backup created: ${backupPath}`);
|
||||
|
||||
// Send notification if configured
|
||||
try {
|
||||
const { createNotification, NOTIFICATION_TYPES } = await import("./src/lib/notifications.js");
|
||||
const db = (await import("./src/lib/db.js")).default;
|
||||
|
||||
const setting = db.prepare("SELECT value FROM settings WHERE key = 'backup_notification_user_id'").get();
|
||||
if (setting && setting.value) {
|
||||
const userId = setting.value;
|
||||
await createNotification({
|
||||
userId,
|
||||
type: NOTIFICATION_TYPES.SYSTEM_ANNOUNCEMENT,
|
||||
title: "Database Backup Completed",
|
||||
message: `Daily database backup completed successfully. Backup file: ${backupPath}`,
|
||||
priority: "normal"
|
||||
});
|
||||
console.log(`📢 Notification sent to user ${userId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to send backup notification:", error);
|
||||
}
|
||||
|
||||
// Cleanup: keep only last 30 backups
|
||||
const files = fs.readdirSync(backupDir)
|
||||
.filter(f => f.startsWith('backup-'))
|
||||
|
||||
Reference in New Issue
Block a user