Alexandre Bodin 0f3f984ea7 Init migration v4
- Hooks registry
- D&P CT migrations
- i18N CT migrations
- Umzug with js / sql migrations
- Eslint updates
2021-09-13 12:03:12 +02:00

39 lines
1.1 KiB
JavaScript

'use strict';
const { difference, keys, intersection, isEmpty } = require('lodash/fp');
const { getService } = require('../../utils');
const migrateForBookshelf = require('./migrate-for-bookshelf');
/*
->
->
*/
// Migration when i18n is disabled on a field of a content-type that have i18n enabled
const after = async ({ model, definition, previousDefinition, ORM }) => {
const { isLocalizedContentType, getLocalizedAttributes } = getService('content-types');
if (!isLocalizedContentType(model) || !isLocalizedContentType(previousDefinition)) {
return;
}
const localizedAttributes = getLocalizedAttributes(definition);
const prevLocalizedAttributes = getLocalizedAttributes(previousDefinition);
const attributesDisabled = difference(prevLocalizedAttributes, localizedAttributes);
const attributesToMigrate = intersection(keys(definition.attributes), attributesDisabled);
if (isEmpty(attributesToMigrate)) {
return;
}
await migrateForBookshelf({ ORM, model, attributesToMigrate });
};
const before = () => {};
module.exports = {
before,
after,
};