fix: fix db restore not applying and auto-create USB backup folder

- Reset public schema before psql restore so existing tables don't
  block CREATE TABLE statements (pg_dump without --clean has no DROPs)
- Disconnect Prisma connection pool after restore so next request
  gets fresh connections against the restored data
- Auto-create the USB backup subfolder if it doesn't exist instead
  of failing; only fail if the destination drive itself is missing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-04-13 23:12:41 -04:00
parent 90302a76b7
commit f415100cdb
2 changed files with 30 additions and 6 deletions

View File

@@ -111,19 +111,23 @@ export const startBackupCron = () => {
return;
}
const usbBackupPath = path.join(destination.path, USB_BACKUP_FOLDER_NAME);
if (!fs.existsSync(usbBackupPath)) {
const errorMessage = `Folder "${USB_BACKUP_FOLDER_NAME}" not found on the drive.`;
if (!fs.existsSync(destination.path)) {
const errorMessage = "Backup destination drive not found or disconnected.";
await cronJobLogStorage.completeJobLog(log.id, "failed", new Date(), errorMessage);
await storage.createNotification(
admin.id,
"BACKUP",
`❌ USB backup failed: folder "${USB_BACKUP_FOLDER_NAME}" not found on the drive. Make sure the USB drive is connected and the folder exists.`
"❌ USB backup failed: backup drive not found. Make sure the USB drive is connected."
);
return;
}
const usbBackupPath = path.join(destination.path, USB_BACKUP_FOLDER_NAME);
if (!fs.existsSync(usbBackupPath)) {
fs.mkdirSync(usbBackupPath, { recursive: true });
}
try {
const filename = `dental_backup_usb_${Date.now()}.sql`;
await backupDatabaseToPath({ destinationPath: usbBackupPath, filename });