From 21b900258a7dc6a87073984562ee3aa3a2f42a94 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 8 Apr 2022 16:23:27 -0700 Subject: [PATCH] backup: fix format of id the id is used in dependsOn by the UI to find the linked apps. if we had it as an uuid, we have to query the db a lot --- .../20220404211215-backups-rename-id-to-remotePath.js | 8 ++++++-- src/backups.js | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/migrations/20220404211215-backups-rename-id-to-remotePath.js b/migrations/20220404211215-backups-rename-id-to-remotePath.js index e909eab8d..69f2ab74a 100644 --- a/migrations/20220404211215-backups-rename-id-to-remotePath.js +++ b/migrations/20220404211215-backups-rename-id-to-remotePath.js @@ -1,7 +1,7 @@ 'use strict'; const async = require('async'), - uuid = require('uuid'); + hat = require('../src/hat.js'); exports.up = function(db, callback) { db.all('SELECT * from backups', function (error, allBackups) { @@ -9,7 +9,11 @@ exports.up = function(db, callback) { console.log(`Fixing up ${allBackups.length} backup entries`); const idMap = {}; - allBackups.forEach(b => { b.remotePath = b.id; b.id = uuid.v4(); idMap[b.remotePath] = b.id; }); + allBackups.forEach(b => { + b.remotePath = b.id; + b.id = `${b.type}_${b.identifier}_v${b.packageVersion}_${hat(256)}`; // id is used by the UI to derive dependent packages. making this a UUID will require a lot of db querying + idMap[b.remotePath] = b.id; + }); db.runSql('ALTER TABLE backups ADD COLUMN remotePath VARCHAR(256)', function (error) { if (error) return callback(error); diff --git a/src/backups.js b/src/backups.js index 4e119c601..870a1625b 100644 --- a/src/backups.js +++ b/src/backups.js @@ -53,6 +53,7 @@ const assert = require('assert'), ejs = require('ejs'), eventlog = require('./eventlog.js'), fs = require('fs'), + hat = require('./hat.js'), locker = require('./locker.js'), path = require('path'), paths = require('./paths.js'), @@ -60,8 +61,7 @@ const assert = require('assert'), settings = require('./settings.js'), storage = require('./storage.js'), tasks = require('./tasks.js'), - util = require('util'), - uuid = require('uuid'); + util = require('util'); const COLLECTD_CONFIG_EJS = fs.readFileSync(__dirname + '/collectd/cloudron-backup.ejs', { encoding: 'utf8' }); @@ -134,7 +134,7 @@ async function add(data) { const creationTime = data.creationTime || new Date(); // allow tests to set the time const manifestJson = JSON.stringify(data.manifest); - const id = 'bid-' + uuid.v4(); + const id = `${data.type}_${data.identifier}_v${data.packageVersion}_${hat(256)}`; // id is used by the UI to derive dependent packages. making this a UUID will require a lot of db querying const [error] = await safe(database.query('INSERT INTO backups (id, remotePath, identifier, encryptionVersion, packageVersion, type, creationTime, state, dependsOnJson, manifestJson, format, preserveSecs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [ id, data.remotePath, data.identifier, data.encryptionVersion, data.packageVersion, data.type, creationTime, data.state, JSON.stringify(data.dependsOn), manifestJson, data.format, data.preserveSecs ]));