backups: use a real targetId
This commit is contained in:
+2
-4
@@ -57,6 +57,7 @@ async function add(data) {
|
||||
assert.strictEqual(typeof data.manifest, 'object');
|
||||
assert.strictEqual(typeof data.preserveSecs, 'number');
|
||||
assert.strictEqual(typeof data.appConfig, 'object');
|
||||
assert.strictEqual(typeof data.targetId, 'string');
|
||||
|
||||
const creationTime = data.creationTime || new Date(); // allow tests to set the time
|
||||
const manifestJson = JSON.stringify(data.manifest);
|
||||
@@ -64,11 +65,8 @@ async function add(data) {
|
||||
const id = `${prefixId}_v${data.packageVersion}_${hat(32)}`; // id is used by the UI to derive dependent packages. making this a UUID will require a lot of db querying
|
||||
const appConfigJson = data.appConfig ? JSON.stringify(data.appConfig) : null;
|
||||
|
||||
const targets = await database.query(`SELECT id FROM backupTargets WHERE priority=?`, [ true ]);
|
||||
const targetId = targets[0].id;
|
||||
|
||||
const [error] = await safe(database.query('INSERT INTO backups (id, remotePath, identifier, encryptionVersion, packageVersion, type, creationTime, state, dependsOnJson, manifestJson, preserveSecs, appConfigJson, targetId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[ id, data.remotePath, data.identifier, data.encryptionVersion, data.packageVersion, data.type, creationTime, data.state, JSON.stringify(data.dependsOn), manifestJson, data.preserveSecs, appConfigJson, targetId ]));
|
||||
[ id, data.remotePath, data.identifier, data.encryptionVersion, data.packageVersion, data.type, creationTime, data.state, JSON.stringify(data.dependsOn), manifestJson, data.preserveSecs, appConfigJson, data.targetId ]));
|
||||
|
||||
if (error && error.code === 'ER_DUP_ENTRY') throw new BoxError(BoxError.ALREADY_EXISTS, 'Backup already exists');
|
||||
if (error) throw error;
|
||||
|
||||
Reference in New Issue
Block a user