Skip to content

Commit

Permalink
Added migrations for backupContent permission
Browse files Browse the repository at this point in the history
no-issue
  • Loading branch information
allouis committed Aug 7, 2019
1 parent f31e535 commit 42c9904
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const logging = require('../../../../lib/common/logging');
const models = require('../../../../models');
const utils = require('../../../schema/fixtures/utils');

const fixtureBackupContentPerm = utils.findModelFixtureEntry('Permission', {
object_type: 'db',
action_type: 'backupContent'
});

module.exports = {
config: {
transaction: true
},

async up(options) {
try {
const existingBackupContentPerm = await models.Permission.findOne(
fixtureBackupContentPerm,
options
);

if (existingBackupContentPerm) {
return logging.warn('Issue adding db.backupContent (already exists)');
}

const result = await utils.addFixturesForModel({
name: 'Permission',
entries: [fixtureBackupContentPerm]
}, options);

const success = result.done === result.expected;

if (!success) {
return logging.warn('Issue adding db.backupContent permission (did not insert)');
}

return logging.info('Completed adding db.backupContent permission');
} catch (err) {
return logging.error('Errored when adding db.backupContent permission');
}
},

async down(options) {
try {
const existingBackupContentPerm = await models.Permission.findOne(
fixtureBackupContentPerm,
options
);

if (!existingBackupContentPerm) {
return logging.warn('Issue removing db.backupContent (already removed)');
}

await existingBackupContentPerm.destroy(options);

return logging.info('Completed removing db.backupContent permission');
} catch (err) {
return logging.error('Errored when removing db.backupContent permission');
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const logging = require('../../../../lib/common/logging');
const utils = require('../../../schema/fixtures/utils');

const relationFixtures = {
from: {
model: 'Role',
match: 'name',
relation: 'permissions'
},
to: {
model: 'Permission',
match: ['object_type', 'action_type']
},
entries: {
Administrator: {
db: 'backupContent'
},
'DB Backup Integration': {
db: 'backupContent'
}
}
};

module.exports = {
config: {
transaction: true
},

async up(options) {
try {
await utils.addFixturesForRelation(relationFixtures, options);
return logging.info('Completed adding db.backupContent permission to roles');
} catch (err) {
return logging.warn('Issue adding db.backupContent permission to roles');
}
},

async down(options) {
try {
await utils.removeFixturesForRelation(relationFixtures, options);
return logging.info('Completed removing db.backupContent permission from roles');
} catch (err) {
return logging.warn('Issue removing db.backupContent permission from roles');
}
}
};

0 comments on commit 42c9904

Please sign in to comment.