0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-15 03:01:37 -05:00

Fixed Action event resource_type from page to post

refs https://github.com/TryGhost/Toolbox/issues/356
refs 3a9016639c

- I misunderstood the purpose of a column, and changed the values that
  are inserted into it, which broke relation includes in Bookshelf
- I've since reverted that in the commit above but this migration is to
  fixup the data that got stored in the DB
- we want to replace `resource_type` = `page` back to `post`, but then
  use the `context` column as described in the referenced commit to
  store that the type is actually a `page`, so we can link to it
  from the audit log accordingly
- I'm overwriting the `context` column without taking into account the
  current contents but that's ok because this bug existed before we
  started using `context`
This commit is contained in:
Daniel Lockyer 2022-08-23 18:15:53 +02:00 committed by Daniel Lockyer
parent 04161d2f7d
commit 5e38a23976

View file

@ -0,0 +1,22 @@
const logging = require('@tryghost/logging');
const {createTransactionalMigration} = require('../../utils');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info(`Changing Action event 'page' resource_type to 'post'`);
const affectedRows = await knex('actions')
.update({
resource_type: 'post',
context: JSON.stringify({
type: 'page'
})
})
.where('resource_type', 'page');
logging.info(`Updated ${affectedRows} Action events from 'page' to 'post'`);
},
async function down() {
// no-op: we don't want to put `pages` back as a resource type
}
);