Commit 839f62de authored by nickstiffler's avatar nickstiffler

feat(models): migration for adding section editor teams to manuscripts

parent 86d3eb18
const { transaction } = require('objection')
const { Manuscript, Team } = require('@pubsweet/models')
const logger = require('@pubsweet/logger')
exports.up = async knex => {
try {
await transaction(Manuscript.knex(), async trx => {
const manuscripts = await Manuscript.query(trx)
await Promise.all(
manuscripts.map(async manuscript => {
await Team.query(trx).insert({
name: `section-editor-${manuscript.id}`,
objectId: manuscript.id,
objectType: 'article',
role: 'sectionEditor',
})
}),
)
})
} catch (e) {
logger.error(
'Add section editor team to manuscripts: Transaction failed! Rolling back...',
)
throw new Error(e)
}
}
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