Commit 66fd713d authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

rename version to packageVersion

parent 2e7630f9
'use strict';
exports.up = function(db, callback) {
db.runSql('ALTER TABLE backups CHANGE version packageVersion VARCHAR(128) NOT NULL', [], function (error) {
if (error) console.error(error);
callback(error);
});
};
exports.down = function(db, callback) {
db.runSql('ALTER TABLE backups CHANGE packageVersion version VARCHAR(128) NOT NULL', [], function (error) {
if (error) console.error(error);
callback(error);
});
};
......@@ -6,7 +6,7 @@ var assert = require('assert'),
safe = require('safetydance'),
util = require('util');
var BACKUPS_FIELDS = [ 'id', 'creationTime', 'version', 'type', 'dependsOn', 'state', 'manifestJson', 'format', 'preserveSecs' ];
var BACKUPS_FIELDS = [ 'id', 'creationTime', 'packageVersion', 'type', 'dependsOn', 'state', 'manifestJson', 'format', 'preserveSecs' ];
exports = module.exports = {
add: add,
......@@ -106,7 +106,7 @@ function get(id, callback) {
function add(id, data, callback) {
assert(data && typeof data === 'object');
assert.strictEqual(typeof id, 'string');
assert.strictEqual(typeof data.version, 'string');
assert.strictEqual(typeof data.packageVersion, 'string');
assert(data.type === exports.BACKUP_TYPE_APP || data.type === exports.BACKUP_TYPE_BOX);
assert(util.isArray(data.dependsOn));
assert.strictEqual(typeof data.manifest, 'object');
......@@ -116,8 +116,8 @@ function add(id, data, callback) {
var creationTime = data.creationTime || new Date(); // allow tests to set the time
var manifestJson = JSON.stringify(data.manifest);
database.query('INSERT INTO backups (id, version, type, creationTime, state, dependsOn, manifestJson, format) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
[ id, data.version, data.type, creationTime, exports.BACKUP_STATE_NORMAL, data.dependsOn.join(','), manifestJson, data.format ],
database.query('INSERT INTO backups (id, packageVersion, type, creationTime, state, dependsOn, manifestJson, format) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
[ id, data.packageVersion, data.type, creationTime, exports.BACKUP_STATE_NORMAL, data.dependsOn.join(','), manifestJson, data.format ],
function (error) {
if (error && error.code === 'ER_DUP_ENTRY') return callback(new BoxError(BoxError.ALREADY_EXISTS));
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
......
......@@ -941,7 +941,7 @@ function rotateBoxBackup(backupConfig, tag, appBackupIds, progressCallback, call
debug(`Rotating box backup to id ${backupId}`);
backupdb.add(backupId, { version: constants.VERSION, type: backupdb.BACKUP_TYPE_BOX, dependsOn: appBackupIds, manifest: null, format: format }, function (error) {
backupdb.add(backupId, { packageVersion: constants.VERSION, type: backupdb.BACKUP_TYPE_BOX, dependsOn: appBackupIds, manifest: null, format: format }, function (error) {
if (error) return callback(error);
var copy = api(backupConfig.provider).copy(backupConfig, getBackupFilePath(backupConfig, 'snapshot/box', format), getBackupFilePath(backupConfig, backupId, format));
......@@ -1023,7 +1023,7 @@ function rotateAppBackup(backupConfig, app, tag, options, progressCallback, call
debug(`Rotating app backup of ${app.id} to id ${backupId}`);
backupdb.add(backupId, { version: manifest.version, type: backupdb.BACKUP_TYPE_APP, dependsOn: [ ], manifest: manifest, format: format }, function (error) {
backupdb.add(backupId, { packageVersion: manifest.version, type: backupdb.BACKUP_TYPE_APP, dependsOn: [ ], manifest: manifest, format: format }, function (error) {
if (error) return callback(error);
var copy = api(backupConfig.provider).copy(backupConfig, getBackupFilePath(backupConfig, `snapshot/app_${app.id}`, format), getBackupFilePath(backupConfig, backupId, format));
......
......@@ -95,7 +95,7 @@ describe('backups', function () {
describe('cleanup', function () {
var BACKUP_0 = {
id: 'backup-box-0',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_BOX,
dependsOn: [ 'backup-app-00', 'backup-app-01' ],
manifest: null,
......@@ -104,7 +104,7 @@ describe('backups', function () {
var BACKUP_0_APP_0 = {
id: 'backup-app-00',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_APP,
dependsOn: [],
manifest: null,
......@@ -113,7 +113,7 @@ describe('backups', function () {
var BACKUP_0_APP_1 = {
id: 'backup-app-01',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_APP,
dependsOn: [],
manifest: null,
......@@ -122,7 +122,7 @@ describe('backups', function () {
var BACKUP_1 = {
id: 'backup-box-1',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_BOX,
dependsOn: [ 'backup-app-10', 'backup-app-11' ],
manifest: null,
......@@ -131,7 +131,7 @@ describe('backups', function () {
var BACKUP_1_APP_0 = {
id: 'backup-app-10',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_APP,
dependsOn: [],
manifest: null,
......@@ -140,7 +140,7 @@ describe('backups', function () {
var BACKUP_1_APP_1 = {
id: 'backup-app-11',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_APP,
dependsOn: [],
manifest: null,
......@@ -312,6 +312,7 @@ describe('backups', function () {
if (require('child_process').execSync('/usr/bin/mysqldump --version').toString().indexOf('MariaDB') !== -1) return done();
createBackup(function (error, result) {
console.dir(error);
expect(error).to.be(null);
expect(fs.statSync(path.join(gBackupConfig.backupFolder, 'snapshot/box.tar.gz')).nlink).to.be(2); // hard linked to a rotated backup
expect(fs.statSync(path.join(gBackupConfig.backupFolder, `${result.id}.tar.gz`)).nlink).to.be(2);
......
......@@ -1324,7 +1324,7 @@ describe('database', function () {
it('add succeeds', function (done) {
var backup = {
id: 'backup-box',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_BOX,
dependsOn: [ 'dep1' ],
manifest: null,
......@@ -1340,7 +1340,7 @@ describe('database', function () {
it('get succeeds', function (done) {
backupdb.get('backup-box', function (error, result) {
expect(error).to.be(null);
expect(result.version).to.be('1.0.0');
expect(result.packageVersion).to.be('1.0.0');
expect(result.type).to.be(backupdb.BACKUP_TYPE_BOX);
expect(result.creationTime).to.be.a(Date);
expect(result.dependsOn).to.eql(['dep1']);
......@@ -1365,7 +1365,7 @@ describe('database', function () {
expect(results.length).to.be(1);
expect(results[0].id).to.be('backup-box');
expect(results[0].version).to.be('1.0.0');
expect(results[0].packageVersion).to.be('1.0.0');
expect(results[0].dependsOn).to.eql(['dep1']);
expect(results[0].manifest).to.eql(null);
......@@ -1390,7 +1390,7 @@ describe('database', function () {
it('add app succeeds', function (done) {
var backup = {
id: 'app_appid_123',
version: '1.0.0',
packageVersion: '1.0.0',
type: backupdb.BACKUP_TYPE_APP,
dependsOn: [ ],
manifest: { foo: 'bar' },
......@@ -1406,7 +1406,7 @@ describe('database', function () {
it('get succeeds', function (done) {
backupdb.get('app_appid_123', function (error, result) {
expect(error).to.be(null);
expect(result.version).to.be('1.0.0');
expect(result.packageVersion).to.be('1.0.0');
expect(result.type).to.be(backupdb.BACKUP_TYPE_APP);
expect(result.creationTime).to.be.a(Date);
expect(result.dependsOn).to.eql([]);
......@@ -1422,7 +1422,7 @@ describe('database', function () {
expect(results.length).to.be(1);
expect(results[0].id).to.be('app_appid_123');
expect(results[0].version).to.be('1.0.0');
expect(results[0].packageVersion).to.be('1.0.0');
expect(results[0].dependsOn).to.eql([]);
expect(results[0].manifest).to.eql({ foo: 'bar' });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment